Package com.yahoo.collections
Class ByteArrayComparator
java.lang.Object
com.yahoo.collections.ByteArrayComparator
Utility class which is useful when implementing
Comparable
and one needs to
compare byte arrays as instance variables.- Author:
- Einar M R Rosenvinge
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic int
compare
(byte[] first, byte[] second) Compare the arguments.
-
Constructor Details
-
ByteArrayComparator
public ByteArrayComparator()
-
-
Method Details
-
compare
public static int compare(byte[] first, byte[] second) Compare the arguments. Shorter arrays are always considered smaller than longer arrays. For arrays of equal lengths, the elements are compared one-by-one. Whenever two corresponding elements in the two arrays are non-equal, the method returns. If all elements at corresponding positions in the two arrays are equal, the arrays are considered equal.- Parameters:
first
- a byte array to be comparedsecond
- a byte array 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
-