public final class HashMap<K,V>
extends java.lang.Object
implements java.lang.Iterable<K>
HashMap
Constructor and Description |
---|
HashMap(Equal<K> e,
Hash<K> h)
Construct a hash map with the given equality and hashing strategy.
|
HashMap(Equal<K> e,
Hash<K> h,
int initialCapacity)
Construct a hash map with the given equality and hashing strategy.
|
HashMap(Equal<K> e,
Hash<K> h,
int initialCapacity,
float loadFactor)
Construct a hash map with the given equality and hashing strategy.
|
HashMap(java.util.Map<K,V> map) |
HashMap(java.util.Map<K,V> map,
Equal<K> e,
Hash<K> h) |
Modifier and Type | Method and Description |
---|---|
static <K,V> HashMap<K,V> |
arrayHashMap(Equal<K> equal,
Hash<K> hash,
P2<K,V>... entries)
Converts the array to a HashMap
|
static <K,V> HashMap<K,V> |
arrayHashMap(P2<K,V>... entries)
Converts the array to a HashMap
|
void |
clear()
Clear all entries from this hash map.
|
boolean |
contains(K k)
Determines if the given key value exists in this hash map.
|
void |
delete(K k)
Deletes the entry in the hash map that corresponds to the given key.
|
boolean |
eq(K k1,
K k2)
Compare two key values for equality using the underlying equality strategy.
|
void |
foreach(F<P2<K,V>,Unit> function) |
void |
foreachDoEffect(Effect1<P2<K,V>> effect) |
static <K,V> HashMap<K,V> |
from(java.lang.Iterable<P2<K,V>> entries)
Deprecated.
As of release 4.5, use
iterableHashMap(Iterable) |
static <K,V> HashMap<K,V> |
from(java.lang.Iterable<P2<K,V>> entries,
Equal<K> equal,
Hash<K> hash)
Deprecated.
As of release 4.5, use
iterableHashMap(fj.Equal<K>, fj.Hash<K>, java.lang.Iterable<fj.P2<K, V>>) |
static <K,V> HashMap<K,V> |
fromMap(Equal<K> eq,
Hash<K> h,
java.util.Map<K,V> map) |
static <K,V> HashMap<K,V> |
fromMap(java.util.Map<K,V> map) |
F<K,Option<V>> |
get()
A curried version of
get(Object) . |
Option<V> |
get(K k)
Returns a potential value that the given key maps to.
|
Option<V> |
getDelete(K k)
Deletes the entry in the hash map that corresponds to the given key and returns any associated value.
|
int |
hash(K k)
Compute the hash of the given key value using the underlying hashing strategy.
|
static <K,V> HashMap<K,V> |
hashMap()
Construct a hash map that uses
Object.equals(java.lang.Object) and Object.hashCode() . |
static <K,V> HashMap<K,V> |
hashMap(Equal<K> e,
Hash<K> h)
Construct a hash map.
|
boolean |
isEmpty()
Determines if this hash map has any entries.
|
static <K,V> HashMap<K,V> |
iterableHashMap(Equal<K> equal,
Hash<K> hash,
java.lang.Iterable<P2<K,V>> entries)
Converts the Iterable to a HashMap
|
static <K,V> HashMap<K,V> |
iterableHashMap(java.lang.Iterable<P2<K,V>> entries)
Converts the Iterable to a HashMap
|
java.util.Iterator<K> |
iterator()
Returns an iterator for this map's keys.
|
static <K,V> HashMap<K,V> |
iteratorHashMap(Equal<K> equal,
Hash<K> hash,
java.util.Iterator<P2<K,V>> entries)
Converts the Iterator to a HashMap
|
static <K,V> HashMap<K,V> |
iteratorHashMap(java.util.Iterator<P2<K,V>> entries)
Converts the Iterator to a HashMap
|
List<K> |
keys()
Returns all key entries in this hash map.
|
<A,B> HashMap<A,B> |
map(F<K,A> keyFunction,
F<V,B> valueFunction) |
<A,B> HashMap<A,B> |
map(F<K,A> keyFunction,
F<V,B> valueFunction,
Equal<A> equal,
Hash<A> hash) |
<A,B> HashMap<A,B> |
map(F<P2<K,V>,P2<A,B>> function) |
<A,B> HashMap<A,B> |
map(F<P2<K,V>,P2<A,B>> function,
Equal<A> equal,
Hash<A> hash) |
<A> HashMap<A,V> |
mapKeys(F<K,A> function) |
<A> HashMap<A,V> |
mapKeys(F<K,A> keyFunction,
Equal<A> equal,
Hash<A> hash) |
<B> HashMap<K,B> |
mapValues(F<V,B> function) |
void |
set(K k,
V v)
Inserts the given key and value association into the hash map.
|
int |
size()
Returns the number of entries in this hash map.
|
Array<P2<K,V>> |
toArray() |
java.util.Collection<P2<K,V>> |
toCollection()
Projects an immutable collection of this hash map.
|
List<P2<K,V>> |
toList() |
java.util.Map<K,V> |
toMap() |
Option<P2<K,V>> |
toOption() |
Stream<P2<K,V>> |
toStream() |
List<V> |
values()
Returns all values in this hash map.
|
public HashMap(Equal<K> e, Hash<K> h)
e
- The equality strategy.h
- The hashing strategy.public HashMap(Equal<K> e, Hash<K> h, int initialCapacity)
e
- The equality strategy.h
- The hashing strategy.initialCapacity
- The initial capacity.public java.util.Iterator<K> iterator()
for
-each loop.iterator
in interface java.lang.Iterable<K>
public static <K,V> HashMap<K,V> hashMap()
Object.equals(java.lang.Object)
and Object.hashCode()
.Object.equals(java.lang.Object)
and Object.hashCode()
.public static <K,V> HashMap<K,V> hashMap(Equal<K> e, Hash<K> h)
public boolean eq(K k1, K k2)
k1
- One key value to compare.k2
- The other key value to compare.true
if the two key values are equal, false
otherwise.public int hash(K k)
k
- The key value to computer the hash of.public Option<V> get(K k)
k
- The key to look up in the hash map.public F<K,Option<V>> get()
get(Object)
.get(Object)
.public void clear()
public boolean contains(K k)
k
- The key value to look for in this hash map.true
if this hash map contains the given key, false
otherwise.public List<K> keys()
public List<V> values()
public boolean isEmpty()
true
if this hash map has no entries, false
otherwise.public int size()
public void set(K k, V v)
k
- The key to insert.v
- The value to insert.public void delete(K k)
k
- The key to delete from this hash map.public Option<V> getDelete(K k)
k
- The key to delete from this hash map.public <A,B> HashMap<A,B> map(F<K,A> keyFunction, F<V,B> valueFunction, Equal<A> equal, Hash<A> hash)
public java.util.Collection<P2<K,V>> toCollection()
@Deprecated public static <K,V> HashMap<K,V> from(java.lang.Iterable<P2<K,V>> entries)
iterableHashMap(Iterable)
public static <K,V> HashMap<K,V> fromMap(java.util.Map<K,V> map)
@Deprecated public static <K,V> HashMap<K,V> from(java.lang.Iterable<P2<K,V>> entries, Equal<K> equal, Hash<K> hash)
iterableHashMap(fj.Equal<K>, fj.Hash<K>, java.lang.Iterable<fj.P2<K, V>>)
public static <K,V> HashMap<K,V> iterableHashMap(Equal<K> equal, Hash<K> hash, java.lang.Iterable<P2<K,V>> entries)
public static <K,V> HashMap<K,V> iterableHashMap(java.lang.Iterable<P2<K,V>> entries)
@SafeVarargs public static <K,V> HashMap<K,V> arrayHashMap(P2<K,V>... entries)
@SafeVarargs public static <K,V> HashMap<K,V> arrayHashMap(Equal<K> equal, Hash<K> hash, P2<K,V>... entries)
public static <K,V> HashMap<K,V> iteratorHashMap(Equal<K> equal, Hash<K> hash, java.util.Iterator<P2<K,V>> entries)