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 extends Object,
V extends Object>, AbstractMap.SimpleImmutableEntry<K extends Object, V extends Object> -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
clone()
Returns a copy of this.@PolyNull V
@PolyNull V
computeIfAbsent
(K key, Function<? super K, ? extends @PolyNull V> mappingFunction) @PolyNull V
computeIfPresent
(K key, BiFunction<? super K, ? super V, ? extends @PolyNull V> remappingFunction) boolean
containsKey
(@GuardSatisfied @Nullable @UnknownSignedness Object key) boolean
containsValue
(@GuardSatisfied @Nullable @UnknownSignedness Object value) entrySet()
void
forEach
(BiConsumer<? super K, ? super V> action) @Nullable V
getOrDefault
(@GuardSatisfied @Nullable @UnknownSignedness Object key, V defaultValue) boolean
isEmpty()
keySet()
@PolyNull V
merge
(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 V
void
@Nullable V
putIfAbsent
(K key, V value) @Nullable V
boolean
remove
(@GuardSatisfied @Nullable @UnknownSignedness Object key, @GuardSatisfied @Nullable @UnknownSignedness Object value) @Nullable V
boolean
void
replaceAll
(BiFunction<? super K, ? super V, ? extends V> function) @org.checkerframework.checker.index.qual.NonNegative int
size()
values()
Methods inherited from class java.util.AbstractMap
equals, hashCode, toString
-
Constructor Details
-
ArrayMap
@SideEffectFree public ArrayMap(int initialCapacity) Constructs an emptyArrayMap
with the specified initial capacity.- Parameters:
initialCapacity
- the initial capacity- Throws:
IllegalArgumentException
- if the initial capacity is negative
-
ArrayMap
@SideEffectFree public ArrayMap()Constructs an emptyArrayMap
with the default initial capacity. -
ArrayMap
Constructs a newArrayMap
with 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:
containsKey
in interfaceMap<K extends @UnknownSignedness Object,
V extends @UnknownSignedness Object> - Overrides:
containsKey
in classAbstractMap<K extends @UnknownSignedness Object,
V extends @UnknownSignedness Object>
-
containsValue
- Specified by:
containsValue
in interfaceMap<K extends @UnknownSignedness Object,
V extends @UnknownSignedness Object> - Overrides:
containsValue
in 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.
-