Package com.jogamp.common.util
Class ArrayHashMap<K,V>
- java.lang.Object
-
- com.jogamp.common.util.ArrayHashMap<K,V>
-
public class ArrayHashMap<K,V> extends Object implements Cloneable, Map<K,V>
HashMap
implementation backed by anArrayList
to preserve order of values. Implementation properties are:- Unique elements utilizing
Object.hashCode()
for O(1) operations, see below. - Java 1.5 compatible
- put new key-value-pair(s)
- test for containment
- trying to remove non existent elements
- put existing key-value-pair(s)
- removing existing elements
RecursiveLock
. - Unique elements utilizing
-
-
Field Summary
Fields Modifier and Type Field Description static int
DEFAULT_INITIAL_CAPACITY
The default initial capacity: 16static float
DEFAULT_LOAD_FACTOR
Default load factor: 0.75f
-
Constructor Summary
Constructors Constructor Description ArrayHashMap(boolean supportNullValue, int initialCapacity, float loadFactor)
ArrayHashMap(ArrayHashMap<K,V> o)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
Object
clone()
Implementation usesArrayHashMap(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()
Returnstrue
for default behavior, i.e.ArrayList<V>
toArrayList()
String
toString()
Collection<V>
values()
-
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
-
-
-
-
Field Detail
-
DEFAULT_LOAD_FACTOR
public static final float DEFAULT_LOAD_FACTOR
Default load factor: 0.75f- See Also:
- Constant Field Values
-
DEFAULT_INITIAL_CAPACITY
public static final int DEFAULT_INITIAL_CAPACITY
The default initial capacity: 16- See Also:
- Constant Field Values
-
-
Constructor Detail
-
ArrayHashMap
public ArrayHashMap(boolean supportNullValue, int initialCapacity, float loadFactor)
- Parameters:
supportNullValue
- Usetrue
for default behavior, i.e.null
can be a valid value. Usefalse
ifnull
is not a valid value, hereput(Object, Object)
andremove(Object)
will be optimized.initialCapacity
- useDEFAULT_INITIAL_CAPACITY
for defaultloadFactor
- useDEFAULT_LOAD_FACTOR
for default- See Also:
supportsNullValue()
-
ArrayHashMap
public ArrayHashMap(ArrayHashMap<K,V> o)
-
-
Method Detail
-
supportsNullValue
public final boolean supportsNullValue()
Returnstrue
for default behavior, i.e.null
can be a valid value.Returns
false
ifnull
is not a valid value, hereput(Object, Object)
andremove(Object)
are optimized operations.- See Also:
ArrayHashMap(boolean, int, float)
-
clone
public final Object clone()
Implementation usesArrayHashMap(ArrayHashMap)
.
-
getData
public final ArrayList<V> getData()
Returns this object ordered ArrayList. Use w/ care, it's not a copy.- See Also:
toArrayList()
-
toArrayList
public final ArrayList<V> toArrayList()
- Returns:
- a shallow copy of this ArrayHashMap's ArrayList, elements are not copied.
- See Also:
getData()
-
getMap
public final HashMap<K,V> getMap()
Returns this object hash map. Use w/ care, it's not a copy.
-
values
public Collection<V> values()
See
getData()
andtoArrayList()
.
-
put
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).
- Specified by:
put
in interfaceMap<K,V>
- Throws:
NullPointerException
- ifvalue
isnull
butsupportsNullValue()
==false
-
remove
public final V remove(Object key)
This is an O(1) operation, in case the key does not exist, otherwise O(n).
-
containsKey
public final boolean containsKey(Object key)
- Specified by:
containsKey
in interfaceMap<K,V>
-
containsValue
public boolean containsValue(Object value)
- Specified by:
containsValue
in interfaceMap<K,V>
-
equals
public final boolean equals(Object arrayHashMap)
-
hashCode
public final int hashCode()
-
-