org.afcs.warts.db
Class BinaryDataHolder

java.lang.Object
  extended byorg.afcs.warts.db.BinaryDataHolder
All Implemented Interfaces:
java.lang.Comparable

public final class BinaryDataHolder
extends java.lang.Object
implements java.lang.Comparable

The BinaryDataHolder class is reponsible for holding binary column data (which it stores internally as an array of bytes), and implementing methods like equals(java.lang.Object), compareTo(java.lang.Object), and hashCode(), so that instances can be processed easily.

LICENSE: This code is released to the public domain and may be used for any purpose whatsoever without permission or acknowledgment.

Version:
Last Modified 18 September 2003
Author:
Warren Hedley ( whedley at sdsc dot edu )

Constructor Summary
BinaryDataHolder(byte[] data)
          Constructs a new instance to contain the specified binary data, which must not be null.
 
Method Summary
 int compareTo(java.lang.Object otherObj)
          Compares the specified object to the current instance, returning a number that could be used to sort a list of BinaryDataHolder instances into ascending order, or 0 if the specified object is not a BinaryDataHolder instance.
 boolean equals(java.lang.Object otherObj)
          Returns true if the specified object is a BinaryDataHolder instance that contains exactly the same binary data as this one.
 byte[] getData()
          Returns the binary data cached in ths instance.
 int hashCode()
          Returns a reasonable hashcode derived from the binary data contained within the current instance.
 java.lang.String toString()
          Returns the first 10 values (or less) of the binary data encoded as hex.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BinaryDataHolder

public BinaryDataHolder(byte[] data)
Constructs a new instance to contain the specified binary data, which must not be null.

Parameters:
data - The binary data to store.
Throws:
java.lang.NullPointerException - If data is null.
Method Detail

getData

public byte[] getData()
Returns the binary data cached in ths instance. This is the original array, not a duplicate.

WARNING: changing the contents of the array returned will change the results of the equals(java.lang.Object) and hashCode() methods, which may disrupt the behaviour of collections containing instances.

Returns:
The binary data cached in ths instance.

compareTo

public int compareTo(java.lang.Object otherObj)
Compares the specified object to the current instance, returning a number that could be used to sort a list of BinaryDataHolder instances into ascending order, or 0 if the specified object is not a BinaryDataHolder instance. The comparison is based on the binary data and on the first byte that differs.

Specified by:
compareTo in interface java.lang.Comparable
Parameters:
otherObj - The object to compare this instance to.
Returns:
A number that could be used to sort a list of BinaryDataHolder instances into ascending order, or 0 if the specified object is not a BinaryDataHolder instance.

equals

public boolean equals(java.lang.Object otherObj)
Returns true if the specified object is a BinaryDataHolder instance that contains exactly the same binary data as this one.

Parameters:
otherObj - The object to compare this instance to.
Returns:
True if the specified object is a BinaryDataHolder instance that contains exactly the same binary data as this one.

hashCode

public int hashCode()
Returns a reasonable hashcode derived from the binary data contained within the current instance. Up to 50 evenly spaced bytes are sampled and included in the hash.

Returns:
A reasonable hashcode derived from the binary data contained within the current instance.

toString

public java.lang.String toString()
Returns the first 10 values (or less) of the binary data encoded as hex.

Returns:
The first 10 values (or less) of the binary data encoded as hex.