org.geotools.util
Class Comparators

Object
  extended by Comparators

public final class Comparators
extends Object

General purpose comparators.

Since:
2.5
Author:
Martin Desruisseaux

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

Method Detail

forLists

public static <T extends Comparable<T>> Comparator<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 Comparable<T>> Comparator<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 Comparable<T>> Comparator<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-2014 Geotools. All Rights Reserved.