public class ArrayHashMap<K,V> extends Object implements Cloneable, Map<K,V>
HashMap
implementation backed by an ArrayList
to preserve order of values.
Implementation properties are:
Object.hashCode()
for O(1) operations, see below.RecursiveLock
.Modifier and Type | Field | Description |
---|---|---|
static int |
DEFAULT_INITIAL_CAPACITY |
The default initial capacity: 16
|
static float |
DEFAULT_LOAD_FACTOR |
Default load factor: 0.75f
|
Constructor | Description |
---|---|
ArrayHashMap(boolean supportNullValue,
int initialCapacity,
float loadFactor) |
|
ArrayHashMap(ArrayHashMap<K,V> o) |
Modifier and Type | Method | Description |
---|---|---|
void |
clear() |
|
Object |
clone() |
Implementation uses
ArrayHashMap(ArrayHashMap) . |
boolean |
containsKey(Object key) |
|
boolean |
containsValue(Object value) |
|
Set<Map.Entry<K,V>> |
entrySet() |
|
boolean |
equals(Object arrayHashMap) |
|
V |
get(Object key) |
|
ArrayList<V> |
getData() |
Returns this object ordered ArrayList.
|
HashMap<K,V> |
getMap() |
Returns this object hash map.
|
int |
hashCode() |
|
boolean |
isEmpty() |
|
Set<K> |
keySet() |
|
V |
put(K key,
V value) |
|
void |
putAll(Map<? extends K,? extends V> m) |
|
V |
remove(Object key) |
|
int |
size() |
|
boolean |
supportsNullValue() |
Returns
true for default behavior, i.e. |
ArrayList<V> |
toArrayList() |
|
String |
toString() |
|
Collection<V> |
values() |
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
public static final float DEFAULT_LOAD_FACTOR
public static final int DEFAULT_INITIAL_CAPACITY
public ArrayHashMap(boolean supportNullValue, int initialCapacity, float loadFactor)
supportNullValue
- Use true
for default behavior, i.e. null
can be a valid value.
Use false
if null
is not a valid value,
here put(Object, Object)
and remove(Object)
will be optimized.initialCapacity
- use DEFAULT_INITIAL_CAPACITY
for defaultloadFactor
- use DEFAULT_LOAD_FACTOR
for defaultsupportsNullValue()
public ArrayHashMap(ArrayHashMap<K,V> o)
public final boolean supportsNullValue()
true
for default behavior, i.e. null
can be a valid value.
Returns false
if null
is not a valid value,
here put(Object, Object)
and remove(Object)
are optimized operations.
ArrayHashMap(boolean, int, float)
public final Object clone()
ArrayHashMap(ArrayHashMap)
.public final ArrayList<V> getData()
toArrayList()
public final ArrayList<V> toArrayList()
getData()
public final HashMap<K,V> getMap()
public Collection<V> values()
See getData()
and toArrayList()
.
public final V put(K key, V value) throws NullPointerException
This is an O(1) operation, in case the key does not exist, otherwise O(n).
put
in interface Map<K,V>
NullPointerException
- if value
is null
but supportsNullValue()
== false
public final V remove(Object key)
This is an O(1) operation, in case the key does not exist, otherwise O(n).
public final boolean containsKey(Object key)
containsKey
in interface Map<K,V>
public boolean containsValue(Object value)
containsValue
in interface Map<K,V>
public final boolean equals(Object arrayHashMap)
public final int hashCode()