jdsl.core.ref
Class LexicographicalByteArrayComparator

java.lang.Object
  |
  +--jdsl.core.ref.AbstractComparator
        |
        +--jdsl.core.ref.ByteArrayComparator
              |
              +--jdsl.core.ref.LexicographicalByteArrayComparator
All Implemented Interfaces:
Comparator, EqualityComparator

public class LexicographicalByteArrayComparator
extends ByteArrayComparator

A Lexicographical comparator for byte arrays.

Version:
$Id: LexicographicalByteArrayComparator.java,v 1.1 2000/12/06 00:40:10 bg Exp $
Author:
Benety Goh (bg@cs.brown.edu)

Constructor Summary
LexicographicalByteArrayComparator()
           
 
Method Summary
 int compare(byte[] a, byte[] b)
          This is the definition of lexicographic ordering.
 
Methods inherited from class jdsl.core.ref.ByteArrayComparator
compare, isComparable
 
Methods inherited from class jdsl.core.ref.AbstractComparator
isEqualTo, isGreaterThan, isGreaterThanOrEqualTo, isLessThan, isLessThanOrEqualTo
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface jdsl.core.api.Comparator
isGreaterThan, isGreaterThanOrEqualTo, isLessThan, isLessThanOrEqualTo
 
Methods inherited from interface jdsl.core.api.EqualityComparator
isEqualTo
 

Constructor Detail

LexicographicalByteArrayComparator

public LexicographicalByteArrayComparator()
Method Detail

compare

public int compare(byte[] a,
                   byte[] b)
This is the definition of lexicographic ordering. If two byte arrays are different, then either they have different elements at some index that is a valid index for both byte arrays, or their lengths are different, or both. If they have different elements at one or more index positions, let k be the smallest such index; then the byte array whose element at position k has the smaller value, as determined by using the < operator, lexicographically precedes the other byte array. In this case, compareTo returns the difference of the two character values at position k in the two byte array -- that is, the value: a[k]-b[k] If there is no index position at which they differ, then the shorter byte array lexicographically precedes the longer byte array. In this case, compareTo returns the difference of the lengths of the byte arrays -- that is, the value: this.length-anotherByteArray.length
Overrides:
compare in class ByteArrayComparator
Returns:
the value 0 if the argument byte array is equal to this byte array; a value less than 0 if this byte array is lexicographically less than the byte array argument; and a value greater than 0 if this byte array is lexicographically greater than the byte array argument.