Package ptolemy.actor.gt.data
Class TwoWayHashMap<K,V>
- java.lang.Object
-
- java.util.AbstractMap<K,V>
-
- java.util.HashMap<K,V>
-
- ptolemy.actor.gt.data.TwoWayHashMap<K,V>
-
- Type Parameters:
K
- The key type.V
- The value type.
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Cloneable
,java.util.Map<K,V>
- Direct Known Subclasses:
SequentialTwoWayHashMap
public class TwoWayHashMap<K,V> extends java.util.HashMap<K,V>
A hash map that has one-to-one relationship between keys and values. With the implementation of two hash maps instead of one, the lookup for keys with values is just as efficient as the lookup for values with keys.- Since:
- Ptolemy II 6.1
- Version:
- $Id$
- Author:
- Thomas Huining Feng
- See Also:
- Serialized Form
- Pt.AcceptedRating:
- Red (tfeng)
- Pt.ProposedRating:
- Yellow (tfeng)
-
-
Constructor Summary
Constructors Constructor Description TwoWayHashMap()
Construct an empty two-way hash map.TwoWayHashMap(int initialCapacity)
Construct an empty two-way hash map with an initial capacity.TwoWayHashMap(int initialCapacity, float loadFactor)
Construct an empty two-way hash map with an initial capacity and a load factor.TwoWayHashMap(java.util.Map<? extends K,? extends V> map)
Construct a two-way hash map with the given hash map, which must have a one-to-one relationship between elements.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
Clear this two-way hash map.java.lang.Object
clone()
Clone this two-way hash map and return the clone.boolean
containsValue(java.lang.Object value)
Test whether this two-way hash map contains the given value.K
getKey(java.lang.Object value)
Given a value, return the corresponding key in this two-way hash map.V
put(K key, V value)
Put a value into this two-way hash map and associate it with a key.V
remove(java.lang.Object key)
Remove the value associated with the given key.java.util.Set<V>
values()
Return a set containing all the values in this two-way hash map.-
Methods inherited from class java.util.HashMap
compute, computeIfAbsent, computeIfPresent, containsKey, entrySet, forEach, get, getOrDefault, isEmpty, keySet, merge, putAll, putIfAbsent, remove, replace, replace, replaceAll, size
-
-
-
-
Constructor Detail
-
TwoWayHashMap
public TwoWayHashMap()
Construct an empty two-way hash map.
-
TwoWayHashMap
public TwoWayHashMap(java.util.Map<? extends K,? extends V> map)
Construct a two-way hash map with the given hash map, which must have a one-to-one relationship between elements.- Parameters:
map
- The hash map.
-
TwoWayHashMap
public TwoWayHashMap(int initialCapacity)
Construct an empty two-way hash map with an initial capacity.- Parameters:
initialCapacity
- The initial capacity.
-
TwoWayHashMap
public TwoWayHashMap(int initialCapacity, float loadFactor)
Construct an empty two-way hash map with an initial capacity and a load factor.- Parameters:
initialCapacity
- The initial capacity.loadFactor
- The load factor.
-
-
Method Detail
-
clear
public void clear()
Clear this two-way hash map.
-
clone
public java.lang.Object clone()
Clone this two-way hash map and return the clone.
-
containsValue
public boolean containsValue(java.lang.Object value)
Test whether this two-way hash map contains the given value.
-
getKey
public K getKey(java.lang.Object value)
Given a value, return the corresponding key in this two-way hash map.- Parameters:
value
- The value.- Returns:
- the key.
-
put
public V put(K key, V value)
Put a value into this two-way hash map and associate it with a key.
-
remove
public V remove(java.lang.Object key)
Remove the value associated with the given key.
-
-