com.ibm.etill.framework.supervisor
Class GenericKey

java.lang.Object
  |
  +--com.ibm.etill.framework.supervisor.GenericKey
All Implemented Interfaces:
Serializable

public abstract class GenericKey
extends Object
implements Serializable

GenericKey is a convenience class which provides function to easily generate Hashtable keys from compound strings. As an example, the Framework extends this class to generate hash keys from a combination of

Such keys are useful in maintaining a collection of similar objects within a Hashtable.

To create your own key type, create a class that extends GenericKey and implement a constructor for the class that:

  1. creates the keys Vector with one element for each string to be included in the hash value and then
  2. sets the protected hashcodeValue instance variable using the calculateHashCode method.

As an example, here is the source code for the Payment key mentioned above:

public PaymentKey (String merchantNumber, String orderNumber, String paymentNumber)
{
keys = new Vector(3);
keys.addElement(merchantNumber);
keys.addElement(orderNumber);
keys.addElement(paymentNumber);
hashcodeValue = calculateHashCode();
}

Once this key object has been created, it can be used as the key value in a Hashtable since this class also implements the methods that Hashtable requires for an object to serve as a key (equals and hashCode).

See Also:
Hashtable, Serialized Form

Field Summary
protected  int hashcodeValue
          Contains the hashcode for the given set of strings.
protected  Vector keys
          Contains the strings that will be combined to determine the hashcode value
protected static String SEPARATOR
           
 
Constructor Summary
GenericKey()
           
 
Method Summary
 int calculateHashCode()
          Returns a Java-generated hash code based on the contents of the keys Vector.
 int calculateHashCode11()
           
protected  String elementAt(int i)
          Convenience method to provide access to the individual strings contained in the protected keys Vector.
 boolean equals(Object aKey)
          Indicates whether the input object is an equivalent of this key object.
 int hashCode()
          Returns this key object's hashcode value.
 String toString()
          Returns a string representation of this object for tracing purposes.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

SEPARATOR

protected static final String SEPARATOR

keys

protected Vector keys
Contains the strings that will be combined to determine the hashcode value

hashcodeValue

protected int hashcodeValue
Contains the hashcode for the given set of strings. This value is computed by the calculateHashCode method.
Constructor Detail

GenericKey

public GenericKey()
Method Detail

elementAt

protected String elementAt(int i)
Convenience method to provide access to the individual strings contained in the protected keys Vector.
Parameters:
i - an int containing the index if the Vector element to be returned.
Returns:
String - the contents of the string referenced by the input Vector index.

calculateHashCode

public int calculateHashCode()
Returns a Java-generated hash code based on the contents of the keys Vector.

Concatenates all of the strings in the keys Vector together and then calcuates a hashcode value using the resulting String's hashCode method.

Returns:
int - the resulting hash code. This code should be stored in the protected hashcodeValue instance variable.

calculateHashCode11

public int calculateHashCode11()

equals

public boolean equals(Object aKey)
Indicates whether the input object is an equivalent of this key object. This method is called by Java when it searches a Hashtable that contains this key. Java requires this method to be implemented in order for this class to serve as a Hashtable key.
Overrides:
equals in class Object
Returns:
boolean - true if the objects match, false if not.

hashCode

public int hashCode()
Returns this key object's hashcode value. This method is called by Java when it searches a Hashtable that contains this key. Java requires this method to be implemented in order for this class to serve as a Hashtable key.
Overrides:
hashCode in class Object
Returns:
int - the value of the hashcodeValue instance variable.

toString

public String toString()
Returns a string representation of this object for tracing purposes. This is a default toString method for generated hashtable key. It only displays the value portions of parameters used to construct the key. It is recommended that each subclass overwrites this method to provide both the keywords and values used for constructing the key object.
Overrides:
toString in class Object
Returns:
String - a string representation of the key elements of this object.