Class LongHashMap<V>
java.lang.Object
de.tomatengames.util.map.LongHashMap<V>
- Type Parameters:
V- The type of the values.
A
HashMap-like data structure that maps long keys to object values.
Equality of keys is checked by using the == operator
This map does not allow null values.
This implementation does not allow concurrent modifications.
- Since:
- 1.3
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new and emptyLongHashMap.LongHashMap(LongHashMap<V> map) Creates a newLongHashMapthat contains all the mappings of the specified map. -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Removes all entries from this map.booleancontainsKey(long key) Returns if the specified key is present in this map.booleanvoidget(long key) Returns the value that is mapped to the specified key.inthashCode()booleanisEmpty()Returns if this map does not contain any entry.iterator()Associates the specified key with the specified value.voidputAll(LongHashMap<V> otherMap) Puts all mappings of the specified map into this map.putIfAbsent(long key, V value) Associates the specified key with the specified value.remove(long key) Removes the entry with the specified key from this map.longsize()Returns the number of entries in this map.Methods inherited from class Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Iterable
spliterator
-
Constructor Details
-
LongHashMap
public LongHashMap()Creates a new and emptyLongHashMap. -
LongHashMap
Creates a newLongHashMapthat contains all the mappings of the specified map.- Parameters:
map- The mappings that should be cloned.
-
-
Method Details
-
size
public long size()Returns the number of entries in this map.- Returns:
- The number of entries.
-
isEmpty
public boolean isEmpty()Returns if this map does not contain any entry.- Returns:
- If this map has no entries.
-
put
Associates the specified key with the specified value. If the key is already present in this map, the previous value is replaced.- Parameters:
key- The key of the new mapping.value- The value of the new mapping. Must notnull.- Returns:
- The value that was previously mapped to the key.
If the key was not present in this map,
nullis returned. - Throws:
IllegalArgumentException- If the value isnull.
-
putIfAbsent
Associates the specified key with the specified value. If the key is already present in this map, nothing happens.- Parameters:
key- The key of the new mapping.value- The value of the new mapping. Must notnull.- Returns:
- The value that was previously mapped to the key.
If
null, the new value has been put into the map. Otherwise, the previous value is still present. - Throws:
IllegalArgumentException- If the value isnull.
-
get
Returns the value that is mapped to the specified key.- Parameters:
key- The key whose value should be returned.- Returns:
- The value that the specified key is mapped to.
If this map does not contain the key,
nullis returned.
-
containsKey
public boolean containsKey(long key) Returns if the specified key is present in this map. This method is semantically equivalent toget(key) != null
- Parameters:
key- The key that should be checked.- Returns:
- If the specified key is present in this map.
-
remove
Removes the entry with the specified key from this map. If the map does not contain the key, nothing happens.- Parameters:
key- The key of the entry that should be removed.- Returns:
- The value of the entry that was removed.
If no entry was removed,
nullis returned.
-
clear
public void clear()Removes all entries from this map. -
forEach
-
putAll
Puts all mappings of the specified map into this map. Keys that are present in both maps are replaced in this map. If the specified map isnullor this map, nothing happens.- Parameters:
otherMap- The map whose mappings should be put into this map. May benull.
-
equals
-
hashCode
-
iterator
-