Class AionMap<K,V>
- java.lang.Object
-
- org.aion.avm.userlib.AionMap<K,V>
-
- All Implemented Interfaces:
java.util.Map<K,V>
public class AionMap<K,V> extends java.lang.Object implements java.util.Map<K,V>
Hash table based implementation of theMap
interface.This implementation provides all of the optional map operations, and permits
null
values.null
key will be rejected for this map.An instance of
AionMap
has two parameters that affect its performance: initial capacity and load factor. capacity is the number of buckets in the hash table, and load factor is a measure of how full the hash table is allowed to get before its capacity is automatically increased. Threshold for initiating a rehashing operation is calculated as the product of the load factor and the current capacity. When the number of hash table entries exceed this threshold, the capacity is doubled and the internal structure is rebuilt by rehashing all the keys.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
Removes all of the mappings from this map.boolean
containsKey(java.lang.Object key)
Returnstrue
if this map contains a mapping for the specified key.boolean
containsValue(java.lang.Object value)
Returnstrue
if this map maps one or more keys to the specified value.java.util.Set<java.util.Map.Entry<K,V>>
entrySet()
Returns aSet
view of the mappings contained in this map.V
get(java.lang.Object key)
Returns the value to which the specified key is mapped, ornull
if this map contains no mapping for the key.V
getOrDefault(java.lang.Object key, V defaultValue)
Returns the value to which the specified key is mapped, ordefaultValue
if this map contains no mapping for the key.boolean
isEmpty()
Returnstrue
if this map contains no key-value mappings.java.util.Set<K>
keySet()
Returns aSet
view of the keys contained in this map.V
put(K key, V value)
Associates the specified value with the specified key in this map.void
putAll(java.util.Map<? extends K,? extends V> m)
Copies all of the mappings from the specified map to this map.V
remove(java.lang.Object key)
Removes the mapping for the specified key from this map if present.int
size()
Returns the number of key-value mappings in this map.java.util.Collection<V>
values()
Returns aCollection
view of the values contained in this map.
-
-
-
Constructor Detail
-
AionMap
public AionMap(int initialCapacity, float loadFactor)
Constructs an emptyAionMap
.- Parameters:
initialCapacity
- The initial initialCapacity of theAionMap
loadFactor
- The load factor for the hash table.
-
AionMap
public AionMap()
Constructs an emptyAionMap
with the default capacity (16) and load factor (0.75).
-
-
Method Detail
-
size
public int size()
Returns the number of key-value mappings in this map.
-
isEmpty
public boolean isEmpty()
Returnstrue
if this map contains no key-value mappings.
-
containsKey
public boolean containsKey(java.lang.Object key)
Returnstrue
if this map contains a mapping for the specified key.
-
containsValue
public boolean containsValue(java.lang.Object value)
Returnstrue
if this map maps one or more keys to the specified value.
-
get
public V get(java.lang.Object key)
Returns the value to which the specified key is mapped, ornull
if this map contains no mapping for the key.A return value of
null
does not necessarily indicate that the map contains no mapping for the key; it's also possible that the map explicitly maps the key tonull
. ThecontainsKey
operation may be used to distinguish these two cases.
-
put
public V put(K key, V value)
Associates the specified value with the specified key in this map. If the map previously contained a mapping for the key, the old value is replaced.- Specified by:
put
in interfacejava.util.Map<K,V>
- Parameters:
key
- key with which the specified value is to be associatedvalue
- value to be associated with the specified key- Returns:
- the previous value associated with
key
, ornull
if there was no mapping forkey
. (Anull
return can also indicate that the map previously associatednull
withkey
.) - Throws:
java.lang.NullPointerException
- if the specified key is null
-
remove
public V remove(java.lang.Object key)
Removes the mapping for the specified key from this map if present.- Specified by:
remove
in interfacejava.util.Map<K,V>
- Parameters:
key
- key whose mapping is to be removed from the map- Returns:
- the previous value associated with
key
, ornull
if there was no mapping forkey
. (Anull
return can also indicate that the map previously associatednull
withkey
.) - Throws:
java.lang.NullPointerException
- if the specified key is null
-
putAll
public void putAll(java.util.Map<? extends K,? extends V> m)
Copies all of the mappings from the specified map to this map. These mappings will replace any mappings that this map had for any of the keys currently in the specified map.
-
clear
public void clear()
Removes all of the mappings from this map. The map will be empty after this call returns. The capacity of this map will remain the same.
-
keySet
public java.util.Set<K> keySet()
Returns aSet
view of the keys contained in this map. The key set is based on a snapshot of the map. Modifications of the map after key set generation will not be reflected back to existing key set, and vice-versa.
-
values
public java.util.Collection<V> values()
Returns aCollection
view of the values contained in this map. Values is based on a snapshot of the map. Modifications of the map after values generation will not be reflected back to existing values, and vice-versa.
-
entrySet
public java.util.Set<java.util.Map.Entry<K,V>> entrySet()
Returns aSet
view of the mappings contained in this map. The entry set is based on a snapshot of the map. Modifications of the map after entry set generation will not be reflected back to existing entry set, and vice-versa.
-
-