public class KeyedHashMap<K,V>
extends java.lang.Object
implements java.util.Map<K,V>
A hash map where the key specified in the put and get methods is not really used as the key but instead another object is derived from it which is then used as the key. In some cases it would be useful to have the equals and hashCode methods behave differently depending on the situation. For example you may want to have the original behavior of equals method (that is the == check) but have it check the actual contents of the object instead of object equality when you use it as a key in a HashMap.
To use this class you need to specify in constructor the function that transforms the key into another object that has the new implementation for equals and hashCode methods. Typically this object will wrap the original key and use some information in there. Later you use get and put methods normally. The function transforming keys is called automatically.
Modifier and Type | Field and Description |
---|---|
protected Delegate<? extends java.lang.Object,K> |
keyMaker |
protected java.util.HashMap<Wrapper<K>,V> |
map |
Constructor and Description |
---|
KeyedHashMap(Delegate<? extends java.lang.Object,K> keyMaker)
Creates a new instance of TopicMapMap
|
Modifier and Type | Method and Description |
---|---|
void |
clear() |
boolean |
containsKey(java.lang.Object key) |
boolean |
containsValue(java.lang.Object value) |
java.util.Set<java.util.Map.Entry<K,V>> |
entrySet() |
boolean |
equals(java.lang.Object o) |
V |
get(java.lang.Object key) |
Wrapper |
getWrapper(K k) |
int |
hashCode() |
boolean |
isEmpty() |
java.util.Set<K> |
keySet() |
V |
put(K key,
V value) |
void |
putAll(java.util.Map<? extends K,? extends V> t) |
V |
remove(java.lang.Object key) |
int |
size() |
java.util.Collection<V> |
values() |
public boolean containsKey(java.lang.Object key)
public boolean containsValue(java.lang.Object value)
public boolean equals(java.lang.Object o)
public int hashCode()
Copyright 2004-2015 Wandora Team