K
- the type of keys maintained by this map.V
- the type of mapped values.public abstract class AbstractWeakPackedMap<K,V> extends AbstractPackedMap<K,V>
keysValues
Constructor and Description |
---|
AbstractWeakPackedMap()
Constructs an empty map.
|
AbstractWeakPackedMap(AbstractWeakPackedMap<K,V> map)
Constructs a map with the same mappings as the specified map.
|
Modifier and Type | Method and Description |
---|---|
boolean |
containsKey(Object key)
Returns
true if this map contains a mapping for the specified key. |
protected boolean |
containsUnwrappedKey(Object key)
Returns
true if this map contains a mapping for the specified key. |
boolean |
containsValue(Object value)
Returns
true if this map maps one or more keys to the specified value. |
V |
get(Object key)
Returns the value to which the specified key is mapped, or
null if this map contains no mapping for the
key. |
protected int |
getWrappedKeyHashCode(Object wrappedKey)
Gets the hash code of a key stored in the packed map.
|
Set<K> |
keySet()
Returns an unmodifiable
Set view of the keys contained in this map. |
V |
put(K key,
V value)
Associates the specified value with the specified key in this map.
|
V |
remove(Object key)
Removes the mapping for a key from this map if it is present.
|
int |
size()
Returns the number of key-value mappings in this map.
|
protected K |
unwrapKey(Object wrappedKey)
Unwraps a wrapped key.
|
protected Object |
wrapKey(K key)
Wraps a key.
|
clear, clone, equals, getKeyHashCode, hashCode, isEmpty, isSame, values
public AbstractWeakPackedMap()
public AbstractWeakPackedMap(AbstractWeakPackedMap<K,V> map)
map
- the map whose mappings are to be placed in this map.NullPointerException
- if the specified map is null
.public boolean containsKey(Object key)
AbstractPackedMap
true
if this map contains a mapping for the specified key. More formally, returns true
if
and only if this map contains a mapping for a key same than the given key (see AbstractPackedMap.isSame(Object, Object)
).
(There can be at most one such mapping.)containsKey
in class AbstractPackedMap<K,V>
key
- key whose presence in this map is to be tested.true
if this map contains a mapping for the specified key.protected boolean containsUnwrappedKey(@Nullable Object key)
AbstractPackedMap
true
if this map contains a mapping for the specified key. More formally, returns true
if
and only if this map contains a mapping for a key same than the given key (see AbstractPackedMap.isSame(Object, Object)
).
(There can be at most one such mapping.)containsUnwrappedKey
in class AbstractPackedMap<K,V>
key
- key whose presence in this map is to be tested. Can be null
if and only if
AbstractPackedMap.unwrapKey(Object)
implementation can return null
.true
if this map contains a mapping for the specified key.public boolean containsValue(@Nullable Object value)
AbstractPackedMap
true
if this map maps one or more keys to the specified value. More formally, returns
true
if and only if this map contains at least one mapping to a value v
such that
(value==null ? v==null : value.equals(v))
. This operation requires time linear in the map size.containsValue
in class AbstractPackedMap<K,V>
value
- value whose presence in this map is to be tested.true
if this map maps one or more keys to the specified value.@Nullable public V get(Object key)
AbstractPackedMap
null
if this map contains no mapping for the
key.
More formally, if this map contains a mapping from a key k
to a value v
such that key is the same
as k (see AbstractPackedMap.isSame(Object, Object)
), then this method returns v
otherwise it returns null
.
(There can be at most one such mapping.)
A return value of null
does not necessarily indicate that the map contains no mapping for the key:
it is also possible that the map explicitly maps the key to null
. The containsKey(key)
operation may be used to distinguish these two cases.
get
in class AbstractPackedMap<K,V>
key
- the key whose associated value is to be returned.null
if this map contains no mapping for the
key.protected int getWrappedKeyHashCode(Object wrappedKey)
AbstractPackedMap
AbstractPackedMap.wrapKey(Object)
.
By default, the given parameter is unwrapped using AbstractPackedMap.unwrapKey(Object)
then the hash code is computed
using AbstractPackedMap.getKeyHashCode(Object)
.
getWrappedKeyHashCode
in class AbstractPackedMap<K,V>
wrappedKey
- the wrapped key.public Set<K> keySet()
AbstractPackedMap
Set
view of the keys contained in this map. The set is backed by the map, so
changes to the map are reflected in the set. If the map is modified while an iteration over the set is in
progress, the results of the iteration are undefined. The set cannot be modified and attempts to modify the
returned collection, whether direct or via its iterator, result in an UnsupportedOperationException
.keySet
in class AbstractPackedMap<K,V>
@Nullable public V put(K key, V value)
AbstractPackedMap
m
is said to contain a mapping for a
key k
if and only if m.containsKey(k)
would return true
.)put
in class AbstractPackedMap<K,V>
key
- key with which the specified value is to be associated.value
- value to be associated with the specified key.key
, or null
if there was no mapping for key
.
(A null
return can also indicate that the map previously associated null
with
key
.)@Nullable public V remove(Object key)
AbstractPackedMap
AbstractPackedMap.isSame(Object, Object)
), that mapping is removed. (The map
can contain at most one such mapping.)
Returns the value to which this map previously associated the key, or null
if the map contained no
mapping for the key.
A return value of null
does not necessarily indicate that the map contained no mapping for the key
it's also possible that the map explicitly mapped the key to null
.
The map will not contain a mapping for the specified key once the call returns.
remove
in class AbstractPackedMap<K,V>
key
- key whose mapping is to be removed from the map.key
, or null
if there was no mapping for key
.public int size()
AbstractPackedMap
Integer.MAX_VALUE
elements, returns Integer.MAX_VALUE
.size
in class AbstractPackedMap<K,V>
@Nullable protected K unwrapKey(Object wrappedKey)
AbstractPackedMap
AbstractPackedMap.wrapKey(Object)
).
The result is the key contained by this wrapper.
By default, the given object is returned (casted in the right type).
Beware that the returned key may be null
, for instance if the key is wrapped in a weak reference. In
this case, to avoid throwing NullPointerException
, the subclass must at least check the null
parameters in AbstractPackedMap.isSame(Object, Object)
, AbstractPackedMap.containsKey(Object)
and AbstractPackedMap.getKeyHashCode(Object)
.
unwrapKey
in class AbstractPackedMap<K,V>
wrappedKey
- the object to unwrap.protected Object wrapKey(K key)
AbstractPackedMap
By default, the key is returned.
wrapKey
in class AbstractPackedMap<K,V>
key
- the key to wrap.