mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-01-08 12:22:34 +00:00
Added Kit.makeHashKeyFromPair to make combined key for hashtables from 2 objects
This commit is contained in:
parent
2e7b972ae2
commit
2c30bb423d
@ -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
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user