org.geotools.util
Class Comparators

java.lang.Object
  extended by org.geotools.util.Comparators

public final class Comparators
extends java.lang.Object

General purpose comparators.

Since:
2.5
Version:
$Id: Comparators.java 30792 2008-06-23 19:19:58Z desruisseaux $
Author:
Martin Desruisseaux

Method Summary
static
<T extends java.lang.Comparable<T>>
java.util.Comparator<java.util.Collection<T>>
forCollections()
          Returns a comparator for arbitrary collections of comparable elements.
static
<T extends java.lang.Comparable<T>>
java.util.Comparator<java.util.List<T>>
forLists()
          Returns a comparator for lists of comparable elements.
static
<T extends java.lang.Comparable<T>>
java.util.Comparator<java.util.SortedSet<T>>
forSortedSets()
          Returns a comparator for sorted sets of comparable elements.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

forLists

public static <T extends java.lang.Comparable<T>> java.util.Comparator<java.util.List<T>> forLists()
Returns a comparator for lists of comparable elements. The first element of each list are compared. If one is greater than or less than the other, the result of that comparaison is returned. Otherwise the second element are compared, and so on until either non-equal elements are found, or end-of-list are reached. In the later case, the shortest list is considered less than the longuest one.

If both lists have the same length and equal elements in the sense of Comparable.compareTo(T), then the comparator returns 0.

Type Parameters:
T - The type of elements in both lists.
Returns:
The ordering between two lists.

forSortedSets

public static <T extends java.lang.Comparable<T>> java.util.Comparator<java.util.SortedSet<T>> forSortedSets()
Returns a comparator for sorted sets of comparable elements. The elements are compared in iteration order as for lists.

Type Parameters:
T - The type of elements in both sets.
Returns:
The ordering between two sets.

forCollections

public static <T extends java.lang.Comparable<T>> java.util.Comparator<java.util.Collection<T>> forCollections()
Returns a comparator for arbitrary collections of comparable elements. The elements are compared in iteration order as for lists. This comparator make sense only for collections having determinist order like TreeSet, LinkedHashSet or queues. Do not use it with HashSet.

Type Parameters:
T - The type of elements in both collections.
Returns:
The ordering between two collections.


Copyright © 1996-2010 Geotools. All Rights Reserved.