goldman.collection.spatial
Class DefaultXYComparator<E extends XYPoint>

java.lang.Object
  extended by goldman.collection.spatial.DefaultXYComparator<E>
All Implemented Interfaces:
XYComparator<E>, Comparator<E>

public class DefaultXYComparator<E extends XYPoint>
extends Object
implements XYComparator<E>

The DefaultXYComparator class provides an implementation of the XYComparator interface that simply uses the x and y coordinates.


Constructor Summary
DefaultXYComparator()
           
 
Method Summary
 int compare(E a, E b)
           
 double compareX(E a, E b)
          Compares a and b according to their x-coordinates.
 double compareY(E a, E b)
          Compares a and b according to their y-coordinates.
 double getX(E item)
          Returns the x-coordinate of the given item.
 double getY(E item)
          Returns the y-coordinate of the given item.
 int quadrant(E origin, E target)
          Returns the quadrant for the given item with respect to the given origin where 0 indicates lower left, 1 indicates lower right, 2 indicates upper right, 3 indicates upper left, and 4 indicates the item is at the origin.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.Comparator
equals
 

Constructor Detail

DefaultXYComparator

public DefaultXYComparator()
Method Detail

compareX

public double compareX(E a,
                       E b)
Description copied from interface: XYComparator
Compares a and b according to their x-coordinates.

Specified by:
compareX in interface XYComparator<E extends XYPoint>

compareY

public double compareY(E a,
                       E b)
Description copied from interface: XYComparator
Compares a and b according to their y-coordinates.

Specified by:
compareY in interface XYComparator<E extends XYPoint>

getX

public double getX(E item)
Description copied from interface: XYComparator
Returns the x-coordinate of the given item.

Specified by:
getX in interface XYComparator<E extends XYPoint>

getY

public double getY(E item)
Description copied from interface: XYComparator
Returns the y-coordinate of the given item.

Specified by:
getY in interface XYComparator<E extends XYPoint>

compare

public int compare(E a,
                   E b)
Specified by:
compare in interface Comparator<E extends XYPoint>

quadrant

public int quadrant(E origin,
                    E target)
Description copied from interface: XYComparator
Returns the quadrant for the given item with respect to the given origin where 0 indicates lower left, 1 indicates lower right, 2 indicates upper right, 3 indicates upper left, and 4 indicates the item is at the origin.

Specified by:
quadrant in interface XYComparator<E extends XYPoint>
Parameters:
origin - the element that defines the origin
target - the target element
Returns:
the quadrant (with respect to origin) that contains the target.