Package org.elasticsearch.common.collect
Class ImmutableOpenMap<KType,VType>
java.lang.Object
org.elasticsearch.common.collect.ImmutableOpenMap<KType,VType>
- All Implemented Interfaces:
Iterable<com.carrotsearch.hppc.cursors.ObjectObjectCursor<KType,VType>>
public final class ImmutableOpenMap<KType,VType>
extends Object
implements Iterable<com.carrotsearch.hppc.cursors.ObjectObjectCursor<KType,VType>>
An immutable map implementation based on open hash map.
Can be constructed using a builder(), or using builder(ImmutableOpenMap) (which is an optimized
option to copy over existing content and modify it).
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionstatic <KType,VType>
ImmutableOpenMap.Builder<KType,VType> builder()static <KType,VType>
ImmutableOpenMap.Builder<KType,VType> builder(int size) static <KType,VType>
ImmutableOpenMap.Builder<KType,VType> builder(ImmutableOpenMap<KType, VType> map) booleancontainsKey(KType key) Returnstrueif this container has an association to a value for the given key.static <KType,VType>
ImmutableOpenMap<KType,VType> copyOf(com.carrotsearch.hppc.ObjectObjectMap<KType, VType> map) entrySet()booleangetOrDefault(KType key, VType defaultValue) inthashCode()booleanisEmpty()iterator()Returns a cursor over the entries (key-value pairs) in this map.com.carrotsearch.hppc.ObjectLookupContainer<KType>keys()Returns a specialized view of the keys of this associated container.keySet()Returns aSetview of the keys contained in this map.keysIt()Returns a direct iterator over the keys.static <KType,VType>
ImmutableOpenMap<KType,VType> of()intsize()stream()Returns a sequential unordered stream of the map entries.toMap()Convert this ImmutableOpenMap to an immutable Java collection MaptoString()values()Returns aCollectionview of the values contained in the map.valuesIt()Returns a direct iterator over the keys.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Method Details
-
get
- Returns:
- Returns the value associated with the given key or the default value
for the key type, if the key is not associated with any value.
Important note: For primitive type values, the value returned for a non-existing key may not be the default value of the primitive type (it may be any value previously assigned to that slot).
-
getOrDefault
- Returns:
- Returns the value associated with the given key or the provided default value if the key is not associated with any value.
-
containsKey
Returnstrueif this container has an association to a value for the given key. -
size
public int size()- Returns:
- Returns the current size (number of assigned keys) in the container.
-
isEmpty
public boolean isEmpty()- Returns:
- Return
trueif this hash map contains no assigned keys.
-
iterator
Returns a cursor over the entries (key-value pairs) in this map. The iterator is implemented as a cursor and it returns the same cursor instance on every call toIterator.next(). To read the current key and value use the cursor's public fields. An example is shown below.for (IntShortCursor c : intShortMap) { System.out.println("index=" + c.index + " key=" + c.key + " value=" + c.value); }The
indexfield inside the cursor gives the internal index inside the container's implementation. The interpretation of this index depends on to the container. -
entrySet
-
keys
Returns a specialized view of the keys of this associated container. The view additionally implementsObjectLookupContainer. -
keysIt
Returns a direct iterator over the keys. -
keySet
Returns aSetview of the keys contained in this map. -
valuesIt
Returns a direct iterator over the keys. -
values
Returns aCollectionview of the values contained in the map. -
stream
Returns a sequential unordered stream of the map entries. -
toString
-
toMap
Convert this ImmutableOpenMap to an immutable Java collection Map -
equals
-
hashCode
public int hashCode() -
of
-
copyOf
public static <KType,VType> ImmutableOpenMap<KType,VType> copyOf(com.carrotsearch.hppc.ObjectObjectMap<KType, VType> map) - Returns:
- An immutable copy of the given map
-
builder
-
builder
-
builder
public static <KType,VType> ImmutableOpenMap.Builder<KType,VType> builder(ImmutableOpenMap<KType, VType> map)
-