Package org.plumelib.util
Class ArrayMap<K extends @UnknownSignedness Object,V extends @UnknownSignedness Object>
java.lang.Object
java.util.AbstractMap<K,V>
org.plumelib.util.ArrayMap<K,V>
- Type Parameters:
K- the type of keys maintained by this mapV- the type of mapped values
- All Implemented Interfaces:
Map<K,V>
public class ArrayMap<K extends @UnknownSignedness Object,V extends @UnknownSignedness Object>
extends AbstractMap<K,V>
A map backed by two arrays. It permits null keys and values, and its iterator has deterministic
ordering.
Compared to a HashMap or LinkedHashMap: For very small maps, this uses much less space, has comparable performance, and (like a LinkedHashMap) is deterministic, with elements returned in the order their keys were inserted. For large maps, this is significantly less performant than other map implementations.
Compared to a TreeMap: This uses somewhat less space, and it does not require defining a comparator. This isn't sorted but does have deterministic ordering. For large maps, this is significantly less performant than other map implementations.
A number of other ArrayMap implementations exist, including
- android.util.ArrayMap
- com.google.api.client.util.ArrayMap
- it.unimi.dsi.fastutil.objects.Object2ObjectArrayMap
- oracle.dss.util.ArrayMap
- org.apache.myfaces.trinidad.util.ArrayMap
-
Nested Class Summary
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K, V> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()clone()Returns a copy of this.@PolyNull V@PolyNull VcomputeIfAbsent(K key, Function<? super K, ? extends @PolyNull V> mappingFunction) @PolyNull VcomputeIfPresent(K key, BiFunction<? super K, ? super V, ? extends @PolyNull V> remappingFunction) booleancontainsKey(@GuardSatisfied @Nullable @UnknownSignedness Object key) booleancontainsValue(@GuardSatisfied @Nullable @UnknownSignedness Object value) entrySet()voidforEach(BiConsumer<? super K, ? super V> action) @Nullable VgetOrDefault(@GuardSatisfied @Nullable @UnknownSignedness Object key, V defaultValue) booleanisEmpty()keySet()@PolyNull Vmerge(K key, @NonNull V value, BiFunction<? super V, ? super V, ? extends @PolyNull V> remappingFunction) static <K,V> Map <K, V> newArrayMapOrHashMap(int capacity) Returns a new ArrayMap or HashMap with the given capacity.static <K,V> Map <K, V> newArrayMapOrHashMap(Map<K, V> m) Returns a new ArrayMap or HashMap with the given elements.static <K,V> Map <K, V> newArrayMapOrLinkedHashMap(int capacity) Returns a new ArrayMap or LinkedHashMap with the given capacity.static <K,V> Map <K, V> newArrayMapOrLinkedHashMap(Map<K, V> m) Returns a new ArrayMap or LinkedHashMap with the given elements.@Nullable Vvoid@Nullable VputIfAbsent(K key, V value) @Nullable Vbooleanremove(@GuardSatisfied @Nullable @UnknownSignedness Object key, @GuardSatisfied @Nullable @UnknownSignedness Object value) @Nullable VbooleanvoidreplaceAll(BiFunction<? super K, ? super V, ? extends V> function) @org.checkerframework.checker.index.qual.NonNegative intsize()values()Methods inherited from class java.util.AbstractMap
equals, hashCode, toString
-
Constructor Details
-
ArrayMap
@SideEffectFree public ArrayMap(int initialCapacity) Constructs an emptyArrayMapwith the specified initial capacity.- Parameters:
initialCapacity- the initial capacity- Throws:
IllegalArgumentException- if the initial capacity is negative
-
ArrayMap
@SideEffectFree public ArrayMap()Constructs an emptyArrayMapwith the default initial capacity. -
ArrayMap
Constructs a newArrayMapwith the same mappings as the givenMap.- Parameters:
m- the map whose mappings are to be placed in this map- Throws:
NullPointerException- if the given map is null
-
-
Method Details
-
newArrayMapOrHashMap
Returns a new ArrayMap or HashMap with the given capacity. Uses an ArrayMap if the capacity is small, and a HashMap otherwise.- Type Parameters:
K- the type of the keysV- the type of the values- Parameters:
capacity- the expected maximum number of elements in the set- Returns:
- a new ArrayMap or HashMap with the given capacity
-
newArrayMapOrHashMap
Returns a new ArrayMap or HashMap with the given elements. Uses an ArrayMap if the capacity is small, and a HashMap otherwise.- Type Parameters:
K- the type of the keysV- the type of the values- Parameters:
m- the elements to put in the returned set- Returns:
- a new ArrayMap or HashMap with the given elements
-
newArrayMapOrLinkedHashMap
Returns a new ArrayMap or LinkedHashMap with the given capacity. Uses an ArrayMap if the capacity is small, and a LinkedHashMap otherwise.- Type Parameters:
K- the type of the keysV- the type of the values- Parameters:
capacity- the expected maximum number of elements in the set- Returns:
- a new ArrayMap or LinkedHashMap with the given capacity
-
newArrayMapOrLinkedHashMap
Returns a new ArrayMap or LinkedHashMap with the given elements. Uses an ArrayMap if the capacity is small, and a LinkedHashMap otherwise.- Type Parameters:
K- the type of the keysV- the type of the values- Parameters:
m- the elements to put in the returned set- Returns:
- a new ArrayMap or LinkedHashMap with the given elements
-
size
@Pure public @org.checkerframework.checker.index.qual.NonNegative int size() -
isEmpty
@Pure public boolean isEmpty() -
containsKey
- Specified by:
containsKeyin interfaceMap<K extends @UnknownSignedness Object,V extends @UnknownSignedness Object> - Overrides:
containsKeyin classAbstractMap<K extends @UnknownSignedness Object,V extends @UnknownSignedness Object>
-
containsValue
- Specified by:
containsValuein interfaceMap<K extends @UnknownSignedness Object,V extends @UnknownSignedness Object> - Overrides:
containsValuein classAbstractMap<K extends @UnknownSignedness Object,V extends @UnknownSignedness Object>
-
get
-
put
-
remove
-
putAll
-
clear
public void clear() -
keySet
-
values
-
entrySet
-
getOrDefault
-
forEach
-
replaceAll
-
putIfAbsent
-
remove
-
replace
-
replace
-
computeIfAbsent
-
computeIfPresent
-
compute
-
merge
-
clone
Returns a copy of this.
-