Class InformationRecord2

InformationRecord2

public class InformationRecord2

Class InformationRecord2 defines a simple record structure, suitable for use in testing the LookupTable class of assignment 3.


Field Summary
protected  java.lang.String address
          Street address
protected  int age
          Age
protected  int id
          Unique 9-digit id
protected  java.lang.String name
          Person name
 
Constructor Summary
InformationRecord2(java.lang.String name, int age, int id, java.lang.String address)
          Construct an InformationRecord with the given field values.
 
Method Summary
 boolean equals(java.lang.Object obj)
          Define equals as elementwise equality.
 java.lang.Object getKey()
          Return the id field of this as the key value.
 java.lang.Object getKey2()
          Return the id field of this as the key value.
 int hash(java.lang.Object key, int tableSize)
          Compute the hash index for this record as the given key modulo the given table size.
 int hash2(java.lang.Object key, int tableSize)
          Compute the hash index for this record by summing all of the characters of the given String key with the following formula: (37 * char[0]) + (37^2 * char[1]) + ...
 java.lang.String toString()
          Convert this to a four-tuple of the form {name, age, id, address}.
 

Field Detail

name

protected java.lang.String name
Person name

age

protected int age
Age

id

protected int id
Unique 9-digit id

address

protected java.lang.String address
Street address
Constructor Detail

InformationRecord2

public InformationRecord2(java.lang.String name,
                          int age,
                          int id,
                          java.lang.String address)
Construct an InformationRecord with the given field values.
Method Detail

getKey

public java.lang.Object getKey()
Return the id field of this as the key value.

getKey2

public java.lang.Object getKey2()
Return the id field of this as the key value.

hash

public int hash(java.lang.Object key,
                int tableSize)
Compute the hash index for this record as the given key modulo the given table size. The given key is assumed to be an Integer id.

hash2

public int hash2(java.lang.Object key,
                 int tableSize)
Compute the hash index for this record by summing all of the characters of the given String key with the following formula: (37 * char[0]) + (37^2 * char[1]) + ... + (37^(l-1) * char[l]) where 37 is an empirically chosen value to provide good distribution and l = key.length(). Return the sum mod the given table size.

toString

public java.lang.String toString()
Convert this to a four-tuple of the form {name, age, id, address}.

equals

public boolean equals(java.lang.Object obj)
Define equals as elementwise equality.