1 /* 2 * This file is part of ELKI: 3 * Environment for Developing KDD-Applications Supported by Index-Structures 4 * 5 * Copyright (C) 2018 6 * ELKI Development Team 7 * 8 * This program is free software: you can redistribute it and/or modify 9 * it under the terms of the GNU Affero General Public License as published by 10 * the Free Software Foundation, either version 3 of the License, or 11 * (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU Affero General Public License for more details. 17 * 18 * You should have received a copy of the GNU Affero General Public License 19 * along with this program. If not, see <http://www.gnu.org/licenses/>. 20 */ 21 package de.lmu.ifi.dbs.elki.data.spatial; 22 23 import java.util.Comparator; 24 25 /** 26 * Comparator for sorting spatial objects by the minimum value in a single 27 * dimension. 28 * 29 * @author Erich Schubert 30 * @since 0.6.0 31 * 32 * @assoc - - - SpatialComparable 33 */ 34 public class SpatialSingleMinComparator implements Comparator<SpatialComparable> { 35 /** 36 * Current dimension. 37 */ 38 int dim; 39 40 /** 41 * Constructor. 42 * 43 * @param dim Dimension to sort by. 44 */ SpatialSingleMinComparator(int dim)45 public SpatialSingleMinComparator(int dim) { 46 super(); 47 this.dim = dim; 48 } 49 50 /** 51 * Set the dimension to sort by. 52 * 53 * @param dim Dimension 54 */ setDimension(int dim)55 public void setDimension(int dim) { 56 this.dim = dim; 57 } 58 59 @Override compare(SpatialComparable o1, SpatialComparable o2)60 public int compare(SpatialComparable o1, SpatialComparable o2) { 61 return Double.compare(o1.getMin(dim), o2.getMin(dim)); 62 } 63 } 64