Added Kit.makeHashKeyFromPair to make combined key for hashtables from 2 objects

This commit is contained in:
igor%mir2.org 2003-11-03 18:04:27 +00:00
parent 2e7b972ae2
commit 2c30bb423d

View File

@ -297,6 +297,42 @@ public class Kit
return initialValue;
}
private final static class ComplexKey
{
private Object key1;
private Object key2;
private int hash;
ComplexKey(Object key1, Object key2)
{
this.key1 = key1;
this.key2 = key2;
}
public boolean equals(Object anotherObj)
{
if (!(anotherObj instanceof ComplexKey))
return false;
ComplexKey another = (ComplexKey)anotherObj;
return key1.equals(another.key1) && key2.equals(another.key2);
}
public int hashCode()
{
if (hash == 0) {
hash = key1.hashCode() ^ key2.hashCode();
}
return hash;
}
}
public static Object makeHashKeyFromPair(Object key1, Object key2)
{
if (key1 == null) throw new IllegalArgumentException();
if (key2 == null) throw new IllegalArgumentException();
return new ComplexKey(key1, key2);
}
public static String readReader(Reader r)
throws IOException
{