public class IndexedMap<K,V> extends Object implements Map<K,V>, Cloneable, Serializable
IndexedSet
which implements Map
interface.
Note that in order to operate normally the IndexedMap shall be used with an Indexer
which supports explicit object keys. See IndexedSet
for more implementation details.
The IndexedMap does not support null values, but it supports null keys
if they are supported by corresponding Indexer
. The IndexedMap can be serialized
if all elements and the Indexer
are serializable.
Constructor and Description |
---|
IndexedMap()
Creates new empty map with default indexer
Indexer.DEFAULT and default initial capacity. |
IndexedMap(Collection<V> c)
Creates a new map containing the elements in the specified collection.
|
IndexedMap(IndexedSet<K,V> set,
boolean wrap)
Creates a new map which wraps specified indexed set and provides a
Map view for it. |
IndexedMap(Indexer<K,? super V> indexer)
Creates new empty map with specified indexer and default initial capacity.
|
IndexedMap(Indexer<K,? super V> indexer,
Collection<? extends V> c)
Creates a new map with specified indexer containing the elements in the specified collection.
|
IndexedMap(Indexer<K,? super V> indexer,
int initial_capacity)
Creates new empty map with specified indexer and specified initial capacity.
|
IndexedMap(Indexer<K,? super V> indexer,
Map<? extends K,? extends V> map)
Creates a new map with specified indexer containing the elements in the specified map.
|
IndexedMap(int initial_capacity)
Creates new empty map with default indexer
Indexer.DEFAULT and specified initial capacity. |
IndexedMap(Map<K,V> map)
Creates a new map containing the elements in the specified map.
|
Modifier and Type | Method and Description |
---|---|
void |
clear()
Removes all elements from this map.
|
IndexedMap<K,V> |
clone()
Returns a shallow copy of this map - the keys and values themselves are not cloned.
|
boolean |
containsKey(long key)
Returns true if this map contains element which matches specified key.
|
boolean |
containsKey(Object key)
Returns true if this map contains element which matches specified key.
|
boolean |
containsValue(Object value)
Returns true if this map contains element which matches specified value.
|
void |
ensureCapacity(int capacity)
Increases the capacity of this map instance, if necessary, to ensure that it
can hold at least the number of elements specified by the capacity argument.
|
Set<Map.Entry<K,V>> |
entrySet()
Returns a set view of the mapping contained in this map.
|
boolean |
equals(Object o)
Compares the specified object with this map for equality.
|
V |
get(Object key)
Deprecated.
Use
getByKey(K) to be explicit about type and intent. |
V |
getByKey(K key)
Returns the element from this map which matches specified key or null if none were found.
|
V |
getByKey(long key)
Returns the element from this map which matches specified key or null if none were found.
|
V |
getByValue(V value)
Returns the element from this map which matches specified value or null if none were found.
|
IndexedSet<K,V> |
getIndexedSet()
Returns indexed set used by this map for actual data storage.
|
Indexer<K,? super V> |
getIndexer()
Returns indexer used to distinguish and identify elements in this map.
|
int |
hashCode()
Returns the hash code value for this map.
|
boolean |
isEmpty()
Tests if this map has no elements.
|
Set<K> |
keySet()
Returns a set view of the keys contained in this map.
|
V |
put(K key,
V value)
Puts specified element into this map and returns previous element that matches specified one.
|
V |
put(V value)
Puts specified element into this map and returns previous element that matches specified one.
|
void |
putAll(Collection<? extends V> c)
Puts all of the elements in the specified collection into this map.
|
void |
putAll(Map<? extends K,? extends V> map)
Puts all of the elements in the specified map into this map.
|
V |
remove(Object key)
Deprecated.
Use
removeKey(K) to be explicit about type and intent. |
V |
removeKey(K key)
Removes the element from this map which matches specified key if it is present
and returns removed element or null if none were found.
|
V |
removeKey(long key)
Removes the element from this map which matches specified key if it is present
and returns removed element or null if none were found.
|
V |
removeValue(V value)
Removes the element from this map which matches specified value if it is present
and returns removed element or null if none were found.
|
int |
size()
Returns the number of elements in this map.
|
String |
toString()
Returns a string representation of this map.
|
void |
trimToSize()
Trims the capacity of this map instance to be the map's current size.
|
Collection<V> |
values()
Returns a collection view of the values contained in this map.
|
public IndexedMap()
Indexer.DEFAULT
and default initial capacity.public IndexedMap(int initial_capacity)
Indexer.DEFAULT
and specified initial capacity.public IndexedMap(Indexer<K,? super V> indexer)
public IndexedMap(Indexer<K,? super V> indexer, int initial_capacity)
public IndexedMap(Collection<V> c)
IndexedSet
, then new indexed map uses same indexer,
otherwise it uses default indexer Indexer.DEFAULT
.public IndexedMap(Indexer<K,? super V> indexer, Collection<? extends V> c)
public IndexedMap(Map<K,V> map)
IndexedMap
, then new indexed map uses same indexer,
otherwise it uses default indexer Indexer.DEFAULT
.public IndexedMap(Indexer<K,? super V> indexer, Map<? extends K,? extends V> map)
public IndexedMap(IndexedSet<K,V> set, boolean wrap)
Map
view for it.
The wrapping works only if wrap parameter is true. If wrap parameter is
false then new independent map is created containing the elements in the specified set -
see IndexedMap(Collection)
constructor.public IndexedMap<K,V> clone()
public void ensureCapacity(int capacity)
public void trimToSize()
public void clear()
public Indexer<K,? super V> getIndexer()
public IndexedSet<K,V> getIndexedSet()
public Collection<V> values()
public Set<K> keySet()
public Set<Map.Entry<K,V>> entrySet()
Map.Entry
. The set is backed by the map, so changes to the map are
reflected in the set, and vice-versa. The view supports all operations.public int size()
public boolean isEmpty()
public V get(Object key)
getByKey(K)
to be explicit about type and intent.
Note, that unlike HashMap.get(java.lang.Object)
,
this method might throw ClassCastException
if key is of the wrong class.
public V getByValue(V value)
public V getByKey(K key)
public V getByKey(long key)
public boolean containsValue(Object value)
Note, that unlike HashMap.containsValue(java.lang.Object)
,
this method might throw ClassCastException
if value is of the wrong class.
containsValue
in interface Map<K,V>
public boolean containsKey(Object key)
Note, that unlike HashMap.containsKey(java.lang.Object)
,
this method might throw ClassCastException
if key is of the wrong class.
containsKey
in interface Map<K,V>
public boolean containsKey(long key)
public V put(V value)
public V put(K key, V value)
put
in interface Map<K,V>
IllegalArgumentException
- if specified key does not match specified value.public V remove(Object key)
removeKey(K)
to be explicit about type and intent.
Note, that unlike HashMap.remove(java.lang.Object)
,
this method might throw ClassCastException
if key is of the wrong class.
public V removeValue(V value)
public V removeKey(K key)
public V removeKey(long key)
public void putAll(Collection<? extends V> c)
public void putAll(Map<? extends K,? extends V> map)
putAll
in interface Map<K,V>
IllegalArgumentException
- if specified keys do not match specified values.public boolean equals(Object o)
Map.equals(Object)
method.public int hashCode()
Map.hashCode()
method.Copyright © 2015 Devexperts. All Rights Reserved.