public class IndexedMap<K,V> extends Object implements Map<K,V>, Cloneable, Serializable
IndexedSet
which implements Map
interface.
The IndexedMap does not support null values, but it supports null keys
if they are supported by corresponding IndexerFunction
. The IndexedMap is serializable.
Modifier | Constructor and Description |
---|---|
|
IndexedMap()
Creates new empty map with default indexer
IndexerFunction.DEFAULT . |
|
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)
Deprecated.
Use
create(indexer) |
|
IndexedMap(Indexer<K,? super V> indexer,
Collection<? extends V> c)
Deprecated.
|
|
IndexedMap(Indexer<K,? super V> indexer,
int initialCapacity)
Deprecated.
|
|
IndexedMap(Indexer<K,? super V> indexer,
Map<? extends K,? extends V> map)
Deprecated.
|
protected |
IndexedMap(IndexerFunction<K,? super V> indexer)
Creates new empty map with specified indexer.
|
protected |
IndexedMap(IndexerFunction<K,? super V> indexer,
Collection<? extends V> c)
Creates a new map with specified indexer containing the elements in the specified collection.
|
protected |
IndexedMap(IndexerFunction<K,? super V> indexer,
int initialCapacity)
Creates new empty map with specified indexer and specified initial capacity.
|
protected |
IndexedMap(IndexerFunction<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 initialCapacity)
Creates new empty map with default indexer
IndexerFunction.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.
|
static <V> Collector<V,?,? extends IndexedMap<V,V>> |
collector()
Returns a
Collector that accumulates the input elements into a new IndexedMap with default indexer. |
static <V> Collector<V,?,? extends IndexedMap<Integer,V>> |
collector(IndexerFunction.IntKey<? super V> indexer)
Deprecated.
|
static <V> Collector<V,?,? extends IndexedMap<Long,V>> |
collector(IndexerFunction.LongKey<? super V> indexer)
Deprecated.
|
static <K,V> Collector<V,?,? extends IndexedMap<K,V>> |
collector(IndexerFunction<K,? super V> indexer)
Returns a
Collector that accumulates the input elements into a new IndexedMap with specified indexer. |
static <V> Collector<V,?,? extends IndexedMap<V,V>> |
collectorIdentity()
Returns a
Collector that accumulates the input elements into a new IndexedMap with default identity indexer. |
static <K,V> Collector<V,?,? extends IndexedMap<K,V>> |
collectorIdentity(IndexerFunction.IdentityKey<K,? super V> indexer)
Returns a
Collector that accumulates the input elements into a new IndexedMap with specified identity indexer. |
static <V> Collector<V,?,? extends IndexedMap<Integer,V>> |
collectorInt(IndexerFunction.IntKey<? super V> indexer)
Returns a
Collector that accumulates the input elements into a new IndexedMap with specified int indexer. |
static <V> Collector<V,?,? extends IndexedMap<Long,V>> |
collectorLong(IndexerFunction.LongKey<? super V> indexer)
Returns a
Collector that accumulates the input elements into a new IndexedMap with specified long indexer. |
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.
|
static <V> IndexedMap<V,V> |
create()
Creates new empty map with default indexer
IndexerFunction.DEFAULT . |
static <V> IndexedMap<Integer,V> |
create(IndexerFunction.IntKey<? super V> indexer)
Deprecated.
|
static <V> IndexedMap<Integer,V> |
create(IndexerFunction.IntKey<? super V> indexer,
Collection<? extends V> c)
Deprecated.
|
static <V> IndexedMap<Integer,V> |
create(IndexerFunction.IntKey<? super V> indexer,
int initialCapacity)
Deprecated.
|
static <V> IndexedMap<Integer,V> |
create(IndexerFunction.IntKey<? super V> indexer,
Map<Integer,? extends V> map)
Deprecated.
|
static <V> IndexedMap<Long,V> |
create(IndexerFunction.LongKey<? super V> indexer)
Deprecated.
|
static <V> IndexedMap<Long,V> |
create(IndexerFunction.LongKey<? super V> indexer,
Collection<? extends V> c)
Deprecated.
|
static <V> IndexedMap<Long,V> |
create(IndexerFunction.LongKey<? super V> indexer,
int initialCapacity)
Deprecated.
|
static <V> IndexedMap<Long,V> |
create(IndexerFunction.LongKey<? super V> indexer,
Map<Long,? extends V> map)
Deprecated.
|
static <K,V> IndexedMap<K,V> |
create(IndexerFunction<K,? super V> indexer)
Creates new empty map with specified indexer.
|
static <K,V> IndexedMap<K,V> |
create(IndexerFunction<K,? super V> indexer,
Collection<? extends V> c)
Deprecated.
|
static <K,V> IndexedMap<K,V> |
create(IndexerFunction<K,? super V> indexer,
int initialCapacity)
Deprecated.
|
static <K,V> IndexedMap<K,V> |
create(IndexerFunction<K,? super V> indexer,
Map<? extends K,? extends V> map)
Deprecated.
|
static <V> IndexedMap<V,V> |
createIdentity()
Creates new empty map with default identity indexer.
|
static <K,V> IndexedMap<K,V> |
createIdentity(IndexerFunction.IdentityKey<K,? super V> indexer)
Creates new empty map with specified identity indexer.
|
static <V> IndexedMap<Integer,V> |
createInt(IndexerFunction.IntKey<? super V> indexer)
Creates new empty map with specified int indexer.
|
static <V> IndexedMap<Long,V> |
createLong(IndexerFunction.LongKey<? super V> indexer)
Creates new empty map with specified long indexer.
|
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()
Deprecated.
|
IndexerFunction<K,? super V> |
getIndexerFunction()
Returns indexer function 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.
|
IndexedMap<K,V> |
withCapacity(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.
|
IndexedMap<K,V> |
withElements(Collection<? extends V> c)
Puts all of the elements in the specified collection into this map.
|
IndexedMap<K,V> |
withElements(Map<K,? extends V> map)
Puts all of the elements in the specified map into this map.
|
finalize, getClass, notify, notifyAll, wait, wait, wait
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
public IndexedMap()
IndexerFunction.DEFAULT
.public IndexedMap(int initialCapacity)
IndexerFunction.DEFAULT
and specified initial capacity.protected IndexedMap(IndexerFunction<K,? super V> indexer)
@Deprecated public IndexedMap(Indexer<K,? super V> indexer)
create(indexer)
protected IndexedMap(IndexerFunction<K,? super V> indexer, int initialCapacity)
@Deprecated public IndexedMap(Indexer<K,? super V> indexer, int initialCapacity)
create(indexer)
.withCapacity(initialCapacity)
public IndexedMap(Collection<V> c)
IndexedSet
, then new indexed map uses same indexer,
otherwise it uses default indexer IndexerFunction.DEFAULT
.protected IndexedMap(IndexerFunction<K,? super V> indexer, Collection<? extends V> c)
@Deprecated public IndexedMap(Indexer<K,? super V> indexer, Collection<? extends V> c)
create(indexer)
.withElements(c)
public IndexedMap(Map<K,V> map)
IndexedMap
, then new indexed map uses same indexer,
otherwise it uses default indexer IndexerFunction.DEFAULT
.protected IndexedMap(IndexerFunction<K,? super V> indexer, Map<? extends K,? extends V> map)
@Deprecated public IndexedMap(Indexer<K,? super V> indexer, Map<? extends K,? extends V> map)
create(indexer)
.withElements(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 static <V> IndexedMap<V,V> create()
IndexerFunction.DEFAULT
.public static <V> IndexedMap<V,V> createIdentity()
public static <K,V> IndexedMap<K,V> create(IndexerFunction<K,? super V> indexer)
public static <K,V> IndexedMap<K,V> createIdentity(IndexerFunction.IdentityKey<K,? super V> indexer)
public static <V> IndexedMap<Integer,V> createInt(IndexerFunction.IntKey<? super V> indexer)
public static <V> IndexedMap<Long,V> createLong(IndexerFunction.LongKey<? super V> indexer)
@Deprecated public static <V> IndexedMap<Integer,V> create(IndexerFunction.IntKey<? super V> indexer)
createInt(indexer)
@Deprecated public static <V> IndexedMap<Long,V> create(IndexerFunction.LongKey<? super V> indexer)
createLong(indexer)
@Deprecated public static <K,V> IndexedMap<K,V> create(IndexerFunction<K,? super V> indexer, int initialCapacity)
create(indexer)
.withCapacity(initialCapacity)
@Deprecated public static <V> IndexedMap<Integer,V> create(IndexerFunction.IntKey<? super V> indexer, int initialCapacity)
createInt(indexer)
.withCapacity(initialCapacity)
@Deprecated public static <V> IndexedMap<Long,V> create(IndexerFunction.LongKey<? super V> indexer, int initialCapacity)
createLong(indexer)
.withCapacity(initialCapacity)
@Deprecated public static <K,V> IndexedMap<K,V> create(IndexerFunction<K,? super V> indexer, Collection<? extends V> c)
create(indexer)
.withElements(c)
@Deprecated public static <V> IndexedMap<Integer,V> create(IndexerFunction.IntKey<? super V> indexer, Collection<? extends V> c)
createInt(indexer)
.withElements(c)
@Deprecated public static <V> IndexedMap<Long,V> create(IndexerFunction.LongKey<? super V> indexer, Collection<? extends V> c)
createLong(indexer)
.withElements(c)
@Deprecated public static <K,V> IndexedMap<K,V> create(IndexerFunction<K,? super V> indexer, Map<? extends K,? extends V> map)
create(indexer)
.withElements(map)
@Deprecated public static <V> IndexedMap<Integer,V> create(IndexerFunction.IntKey<? super V> indexer, Map<Integer,? extends V> map)
createInt(indexer)
.withElements(map)
@Deprecated public static <V> IndexedMap<Long,V> create(IndexerFunction.LongKey<? super V> indexer, Map<Long,? extends V> map)
createLong(indexer)
.withElements(map)
public static <V> Collector<V,?,? extends IndexedMap<V,V>> collector()
Collector
that accumulates the input elements into a new IndexedMap
with default indexer.
This is an unordered
Collector.public static <V> Collector<V,?,? extends IndexedMap<V,V>> collectorIdentity()
Collector
that accumulates the input elements into a new IndexedMap
with default identity indexer.
This is an unordered
Collector.public static <K,V> Collector<V,?,? extends IndexedMap<K,V>> collector(IndexerFunction<K,? super V> indexer)
Collector
that accumulates the input elements into a new IndexedMap
with specified indexer.
This is an unordered
Collector.public static <K,V> Collector<V,?,? extends IndexedMap<K,V>> collectorIdentity(IndexerFunction.IdentityKey<K,? super V> indexer)
Collector
that accumulates the input elements into a new IndexedMap
with specified identity indexer.
This is an unordered
Collector.public static <V> Collector<V,?,? extends IndexedMap<Integer,V>> collectorInt(IndexerFunction.IntKey<? super V> indexer)
Collector
that accumulates the input elements into a new IndexedMap
with specified int indexer.
This is an unordered
Collector.public static <V> Collector<V,?,? extends IndexedMap<Long,V>> collectorLong(IndexerFunction.LongKey<? super V> indexer)
Collector
that accumulates the input elements into a new IndexedMap
with specified long indexer.
This is an unordered
Collector.@Deprecated public static <V> Collector<V,?,? extends IndexedMap<Integer,V>> collector(IndexerFunction.IntKey<? super V> indexer)
collectorInt(indexer)
Collector
that accumulates the input elements into a new IndexedMap
with specified indexer.
This is an unordered
Collector.@Deprecated public static <V> Collector<V,?,? extends IndexedMap<Long,V>> collector(IndexerFunction.LongKey<? super V> indexer)
collectorLong(indexer)
Collector
that accumulates the input elements into a new IndexedMap
with specified indexer.
This is an unordered
Collector.public IndexedMap<K,V> clone()
public IndexedMap<K,V> withCapacity(int capacity)
Returns this map instance for convenience.
public IndexedMap<K,V> withElements(Collection<? extends V> c)
Returns this map instance for convenience.
public IndexedMap<K,V> withElements(Map<K,? extends V> map)
Returns this map instance for convenience.
public void ensureCapacity(int capacity)
public void trimToSize()
public void clear()
@Deprecated public Indexer<K,? super V> getIndexer()
getIndexerFunction()
public IndexerFunction<K,? super V> getIndexerFunction()
public IndexedSet<K,V> getIndexedSet()
@Nonnull public Collection<V> values()
@Nonnull public Set<K> keySet()
@Nonnull 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 © 2002–2025 Devexperts LLC. All rights reserved.