Package com.atlassian.bamboo.utils.map
Class TypedIdentityMap<V>
- java.lang.Object
-
- com.atlassian.bamboo.utils.map.TypedIdentityMap<V>
-
- Type Parameters:
V
- value
- All Implemented Interfaces:
ConcurrentMap<Key<? extends V>,V>
,Map<Key<? extends V>,V>
public class TypedIdentityMap<V> extends Object implements ConcurrentMap<Key<? extends V>,V>
A map which maintains its values type safety through aKey
instance without having to cast fromReferences inside the map are automatically garbage collected when the reference to Key
is lost. SeeWeakHashMap
. Example: TypedIdentityMap<Object> map = new TypedIdentityMap<Object>(); Key<Foo> fooKey = Key.create(Foo.class); map.putIfAbsent(fooKey, new Foo()); Foo foo = map.getValue(fooKey);
-
-
Constructor Summary
Constructors Constructor Description TypedIdentityMap()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
boolean
containsKey(Object key)
boolean
containsValue(Object value)
Set<Map.Entry<Key<? extends V>,V>>
entrySet()
boolean
equals(Object o)
V
get(Object key)
<T extends V>
TgetValue(Key<? extends V> key)
Retrieves the value represented byKey
in a type safe manner.int
hashCode()
boolean
isEmpty()
Set<Key<? extends V>>
keySet()
V
put(Key<? extends V> key, V value)
void
putAll(Map<? extends Key<? extends V>,? extends V> m)
V
putIfAbsent(Key<? extends V> key, V value)
V
remove(Object key)
boolean
remove(Object key, Object value)
V
replace(Key<? extends V> key, V value)
boolean
replace(Key<? extends V> key, V oldValue, V newValue)
int
size()
Collection<V>
values()
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.util.concurrent.ConcurrentMap
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, replaceAll
-
-
-
-
Method Detail
-
getValue
@Nullable public <T extends V> T getValue(Key<? extends V> key)
Retrieves the value represented byKey
in a type safe manner.- Type Parameters:
T
-- Parameters:
key
-- Returns:
- value
-
equals
public boolean equals(Object o)
-
hashCode
public int hashCode()
-
putIfAbsent
public V putIfAbsent(Key<? extends V> key, V value)
- Specified by:
putIfAbsent
in interfaceConcurrentMap<Key<? extends V>,V>
- Specified by:
putIfAbsent
in interfaceMap<Key<? extends V>,V>
-
containsKey
public boolean containsKey(Object key)
- Specified by:
containsKey
in interfaceMap<Key<? extends V>,V>
-
containsValue
public boolean containsValue(Object value)
- Specified by:
containsValue
in interfaceMap<Key<? extends V>,V>
-
-