| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
package org.locationtech.jts.index.strtree; |
| 14 |
|
| 15 |
import java.io.Serializable; |
| 16 |
import java.util.Comparator; |
| 17 |
|
| 18 |
|
| 19 |
/** |
| 20 |
* The Class BoundablePairDistanceComparator. It implements Java comparator and is used |
| 21 |
* as a parameter to sort the BoundablePair list. |
| 22 |
*/ |
| 23 |
public class BoundablePairDistanceComparator implements Comparator<BoundablePair>, Serializable{ |
| 24 |
|
| 25 |
/** The normal order. */ |
| 26 |
boolean normalOrder; |
| 27 |
|
| 28 |
/** |
| 29 |
* Instantiates a new boundable pair distance comparator. |
| 30 |
* |
| 31 |
* @param normalOrder true puts the lowest record at the head of this queue. |
| 32 |
* This is the natural order. PriorityQueue peek() will get the least element. |
| 33 |
*/ |
| 34 |
public BoundablePairDistanceComparator(boolean normalOrder) |
| 35 |
{ |
| 36 |
this.normalOrder = normalOrder; |
| 37 |
} |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
public int compare(BoundablePair p1, BoundablePair p2) { |
| 43 |
double distance1 = p1.getDistance(); |
| 44 |
double distance2 = p2.getDistance(); |
| 45 |
if(this.normalOrder) |
| 46 |
{ |
| 47 |
if (distance1 > distance2) { |
| 48 |
return 1; |
| 49 |
} else if (distance1 == distance2) { |
| 50 |
return 0; |
| 51 |
} |
| 52 |
return -1; |
| 53 |
} |
| 54 |
else |
| 55 |
{ |
| 56 |
if (distance1 > distance2) { |
| 57 |
return -1; |
| 58 |
} else if (distance1 == distance2) { |
| 59 |
return 0; |
| 60 |
} |
| 61 |
return 1; |
| 62 |
} |
| 63 |
|
| 64 |
} |
| 65 |
} |
| 66 |
|