Problem with Hashtable key.
Hi all,
I need a hashtable with multi-dimensional keys (e.g. 3 keys per value).
My test harness looks like this:
My HashIndex class for 1 key-, 2 keys- and 3 keys-per-value indexing:
Code:
public class HashIndex extends Object
{
public HashIndex(Object key1) {
m_keys.add(key1);
}
public HashIndex(Object key1, Object key2) {
m_keys.add(key1);
m_keys.add(key2);
}
public HashIndex(Object key1, Object key2, Object key3) {
m_keys.add(key1);
m_keys.add(key2);
m_keys.add(key3);
}
public boolean equals(HashIndex idx)
{
System.out.println("got here");
return m_keys.equals(idx.m_keys);
}
protected Vector<Object> m_keys = new Vector<Object>();
}
And an example of the HashIndex in use:
Code:
Hashtable<HashIndex, String> ht = new Hashtable<HashIndex, String>();
ht.put(new HashIndex("a", "b", "c"), new String("The quick brown fox jumps over the lazy dog."));
System.out.println(ht.get(new HashIndex("a", "b", "c")));
I would expect the output from this to be:
got here
true
But what I am actually getting is just:
null
Therefore, the Hashtable is not using the HashIndex's equals method.
Any ideas? :confused::confused::confused: