Package com.yahoo.collections
Class CollectionComparator
java.lang.Object
com.yahoo.collections.CollectionComparator
Utility class which is useful when implementing
Comparable
and one needs to
compare Collections of Comparables as instance variables.- Author:
- Einar M R Rosenvinge
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic int
compare
(Collection<? extends Comparable> first, Collection<? extends Comparable> second) Compare the arguments.
-
Constructor Details
-
CollectionComparator
public CollectionComparator()
-
-
Method Details
-
compare
public static int compare(Collection<? extends Comparable> first, Collection<? extends Comparable> second) Compare the arguments. Shorter Collections are always considered smaller than longer Collections. For Collections of equal lengths, the elements are compared one-by-one. Whenever two corresponding elements in the two Collections are non-equal, the method returns. If all elements at corresponding positions in the two Collections are equal, the Collections are considered equal.- Parameters:
first
- a Collection of Comparables to be comparedsecond
- a Collection of Comparables to be compared- Returns:
- 0 if the arguments are equal, -1 if the first argument is smaller, 1 if the second argument is smaller
- Throws:
NullPointerException
- if any of the arguments are null
-