Package com.yahoo.collections
Class CollectionComparator
- java.lang.Object
-
- com.yahoo.collections.CollectionComparator
-
public class CollectionComparator extends Object
Utility class which is useful when implementingComparable
and one needs to compare Collections of Comparables as instance variables.- Author:
- Einar M R Rosenvinge
-
-
Constructor Summary
Constructors Constructor Description CollectionComparator()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static int
compare(Collection<? extends Comparable> first, Collection<? extends Comparable> second)
Compare the arguments.
-
-
-
Method Detail
-
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
-
-