org.metastatic.rsync
Class TwoKeyMap.StrongKey

java.lang.Object
  |
  +--org.metastatic.rsync.TwoKeyMap.StrongKey
All Implemented Interfaces:
Comparable, Serializable
Enclosing class:
TwoKeyMap

public class TwoKeyMap.StrongKey
extends Object
implements Serializable, Comparable

The stronger of the two keys in this Map. It is basically a wrapper around an array of bytes, providing methods important for using this class as the key in a Map, namely the hashCode() and compareTo(java.lang.Object) methods.

Since:
1.1
See Also:
Serialized Form

Field Summary
protected  byte[] key
          The key itself.
 
Method Summary
 int compareTo(Object o)
          Compare this object to another.
 boolean equals(Object o)
          Test if this key equals another.
 byte[] getBytes()
          Return the bytes that compose this Key.
 int hashCode()
          The hash code for this key.
 int length()
          The length, in bytes, of this key.
 void setBytes(byte[] key)
          Set the byte array that composes this key.
 String toString()
          Return a zero-padded hexadecimal string representing this key.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

key

protected byte[] key
The key itself. An array of some number of bytes.

Since:
1.0
Method Detail

getBytes

public byte[] getBytes()
Return the bytes that compose this Key.

Returns:
key, the bytes that compose this key.
Since:
1.0

setBytes

public void setBytes(byte[] key)
Set the byte array that composes this key.

Parameters:
key - The bytes that will compose this key.
Since:
1.0

length

public int length()
The length, in bytes, of this key.

Returns:
The length of this key in bytes.
Since:
1.0

toString

public String toString()
Return a zero-padded hexadecimal string representing this key.

Overrides:
toString in class Object
Returns:
A hexadecimal string of the bytes in key.
Since:
1.0

hashCode

public int hashCode()
The hash code for this key. This is defined as the XOR of all 32-bit blocks of the key array.

Overrides:
hashCode in class Object
Returns:
The hash code for this key.
Since:
1.0

equals

public boolean equals(Object o)
Test if this key equals another. Two keys are equal if the method Arrays.equals(byte[],byte[]) returns true for thier key arrays.

Overrides:
equals in class Object
Parameters:
o - The object to compare to.
Returns:
true If this key is equivalent to the argument.
Throws:
ClassCastException - If o is not a StrongKey.
Since:
1.0

compareTo

public int compareTo(Object o)
Compare this object to another. This method returns an integer value less than, equal to, or greater than zero if this key is less than, equal to, or greater than the given key. This method will return

Specified by:
compareTo in interface Comparable
Parameters:
o - The key to compare to.
Returns:
An integer derived from the differences of the two keys.
Throws:
ClassCastException - If o is not a StrongKey.
Since:
1.0