public class HashEntry implements Entry { private K key; private V value; /** Constructor */ HashEntry( K k, V v) { key = k; value = v; } /** Returns the key stored in this entry. */ public K getKey() { return key; } /** Returns the value stored in this entry. */ public V getValue() { return value; } public V setValue(V val) { V oldValue = value; value = val; // Update value return oldValue; // Return old value } public boolean equals(Object o) { HashEntry ent; try { ent = (HashEntry) o; // Try casting it to a HashEntry } catch (ClassCastException ex) { return false; // Casting failed, can't compare } /* ------------------------------------------------------- Object is equal is key and value are same object... ------------------------------------------------------- */ return (ent.getKey() == key) && (ent.getValue() == value); } public String toString() { return "(" + key + "," + value + ")"; } }