K - the type of the keysV - the type of the valuespublic class LazyMap<K,V> extends Object implements Map<K,V>
The basic idea is that, if the map is not initialized, it is considered empty.
| Constructor and Description |
|---|
LazyMap()
Creates an empty object.
|
LazyMap(Collection<V> objects,
Function<V,K> IDMapper)
Creates a lazy map from a given collection.
|
LazyMap(int size)
Creates an empty lazy map of specified capacity.
|
LazyMap(Map<K,V> map)
Creates a lazy map from the given map.
|
| Modifier and Type | Method and Description |
|---|---|
void |
clear() |
boolean |
containsKey(Object key) |
boolean |
containsValue(Object value) |
Set<Map.Entry<K,V>> |
entrySet() |
boolean |
equals(Object o) |
V |
get(Object key) |
int |
hashCode() |
boolean |
isEmpty() |
protected boolean |
isInitialized()
Is this object initialized?
|
Set<K> |
keySet() |
V |
put(K key,
V value) |
void |
putAll(Map<? extends K,? extends V> m) |
V |
remove(Object key) |
protected void |
requireInitialized()
Specifies that, in the case where this object is not initialized, it should be initialized now before further
exploitation.
|
int |
size() |
Collection<V> |
values() |
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitcompute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAllpublic LazyMap()
The default capacity of the Map created by this constructor is voluntarily unspecified, as it may depend on
how the underlying map is instantiated, later in the life of this object. If the capacity is important to you,
use LazyMap(int) instead.
public LazyMap(int size)
In this case, the underlying map object is a HashMap, see HashMap.HashMap(int).
size - the capacity of the underlying map object.public LazyMap(Map<K,V> map)
map - the map object that will be used as underlying map.public LazyMap(Collection<V> objects, Function<V,K> IDMapper)
Here is an example of call, assuming we want to store Users, indexed by their ID:
Collection<User> users = ...
LazyMap<Integer, User> map = new LazyMap<>(users, u -> u.getID());
objects - the values that will be stored in the mapIDMapper - the way to get the key from an objectprotected boolean isInitialized()
true if this object is initialized.protected void requireInitialized()
public boolean containsKey(Object key)
containsKey in interface Map<K,V>public boolean containsValue(Object value)
containsValue in interface Map<K,V>public boolean equals(Object o)