Class HashMap<K,V>
- java.lang.Object
-
- com.github.andrewoma.dexx.collection.internal.base.AbstractTraversable<E>
-
- com.github.andrewoma.dexx.collection.internal.base.AbstractIterable<Pair<K,V>>
-
- com.github.andrewoma.dexx.collection.internal.base.AbstractMap<K,V>
-
- com.github.andrewoma.dexx.collection.HashMap<K,V>
-
- All Implemented Interfaces:
Iterable<Pair<K,V>>
,Map<K,V>
,Traversable<Pair<K,V>>
,java.lang.Iterable<Pair<K,V>>
public class HashMap<K,V> extends AbstractMap<K,V>
HashMap
is an implementation ofMap
based on a hash trie.The underlying implementation is a port of Scala's HashMap which is an implementation of a hash array mapped trie.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
HashMap.Itr<K,V>
-
Field Summary
Fields Modifier and Type Field Description private CompactHashMap<K,Pair<K,V>>
compactHashMap
private static HashMap
EMPTY
private static KeyFunction
keyFunction
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
containsKey(K key)
Returns true if this map contains the specified key.static <K,V>
@NotNull HashMap<K,V>empty()
static <K,V>
@NotNull BuilderFactory<Pair<K,V>,HashMap<K,V>>factory()
<U> void
forEach(@NotNull Function<Pair<K,V>,U> f)
All collection methods can be built upon thisforEach
definition.V
get(K key)
Returns the value associated with the key ornull
if the no value exists with the key specified.@NotNull java.util.Iterator<Pair<K,V>>
iterator()
private KeyFunction<K,Pair<K,V>>
keyFunction()
@NotNull HashMap<K,V>
put(K key, V value)
Returns a map with the value specified associated to the key specified.@NotNull HashMap<K,V>
remove(K key)
Returns a map with the value associated with the key removed if it exists.int
size()
Returns the size of the collection.-
Methods inherited from class com.github.andrewoma.dexx.collection.internal.base.AbstractMap
asMap, equals, hashCode, keys, values
-
Methods inherited from class com.github.andrewoma.dexx.collection.internal.base.AbstractTraversable
isEmpty, makeString, makeString, to, toArray, toArray, toIndexedList, toSet, toSortedSet, toString
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.github.andrewoma.dexx.collection.Traversable
isEmpty, makeString, makeString, to, toArray, toArray, toIndexedList, toSet, toSortedSet
-
-
-
-
Field Detail
-
EMPTY
private static final HashMap EMPTY
-
keyFunction
private static final KeyFunction keyFunction
-
compactHashMap
private final CompactHashMap<K,Pair<K,V>> compactHashMap
-
-
Constructor Detail
-
HashMap
public HashMap()
-
HashMap
private HashMap(CompactHashMap<K,Pair<K,V>> compactHashMap)
-
-
Method Detail
-
empty
@NotNull public static <K,V> @NotNull HashMap<K,V> empty()
-
factory
@NotNull public static <K,V> @NotNull BuilderFactory<Pair<K,V>,HashMap<K,V>> factory()
-
keyFunction
private KeyFunction<K,Pair<K,V>> keyFunction()
-
containsKey
public boolean containsKey(@NotNull K key)
Description copied from interface:Map
Returns true if this map contains the specified key.
-
put
@NotNull public @NotNull HashMap<K,V> put(@NotNull K key, V value)
Description copied from interface:Map
Returns a map with the value specified associated to the key specified.If value already exists for the key, it will be replaced.
-
get
@Nullable public V get(@NotNull K key)
Description copied from interface:Map
Returns the value associated with the key ornull
if the no value exists with the key specified.
-
remove
@NotNull public @NotNull HashMap<K,V> remove(@NotNull K key)
Description copied from interface:Map
Returns a map with the value associated with the key removed if it exists.
-
size
public int size()
Description copied from interface:Traversable
Returns the size of the collection.Warning: infinite collections are possible, as are collections that require traversal to calculate the size.
- Specified by:
size
in interfaceTraversable<K>
- Overrides:
size
in classAbstractTraversable<Pair<K,V>>
-
forEach
public <U> void forEach(@NotNull @NotNull Function<Pair<K,V>,U> f)
Description copied from interface:Traversable
All collection methods can be built upon thisforEach
definition.- Specified by:
forEach
in interfaceTraversable<K>
- Overrides:
forEach
in classAbstractIterable<Pair<K,V>>
-
-