/* Equality can be based on key alone because there can't be * 2 nodes with the same key in the table */ public boolean equals(Object obj) { if (obj instanceof HashtableNode) { HashtableNode node = (HashtableNode) obj; return this.key.equals(node.getKey()); } else { return false; } }
/** * Remove an item from the hashtable * * @param key The item to remove */ public void remove(Object key) { int hashVal = this.hash(key); if (this.table[hashVal] != null) { HashtableNode node = new HashtableNode(); node.setKey(key); if (((LinkedList) this.table[hashVal]).indexOf(node) > -1) { ((LinkedList) this.table[hashVal]).remove(node); this.numElements--; } } }
/** * Check if the table contains a certain element or not * * @param data The data to search for * @return Whether or not the element exists */ public boolean contains(Object key) { boolean result = false; int hash = this.hash(key); if (this.table[hash] != null) { HashtableNode node = new HashtableNode(); node.setKey(key); if (((LinkedList) this.table[hash]).indexOf(node) > -1) { result = true; } } return result; }