API: IMap
IMap
is the interface for key-value associations, analogous to java.util.Map
.
Key Methods
IMap<K, V> put(K key, V value)
Returns a new map with the specified key-value association. If the key already exists, its value is overwritten.
IMap<K, V> put(K key, V value, BinaryOperator<V> merge)
Associates key
with value
. If the key already exists, the merge
function is called with the old and new values to produce the resulting value.
IMap<K, V> remove(K key)
Returns a new map without an association for key
.
Optional<V> get(K key)
Returns an Optional
containing the value associated with key
, or an empty Optional
if no such key exists.
V get(K key, V defaultValue)
Returns the value for key
, or defaultValue
if the key is not in the map.
boolean contains(K key)
Returns true
if the map contains an association for key
.
ISet<K> keys()
Returns a set view of the keys contained in this map.
IList<V> values()
Returns a list view of the values contained in this map.
IList<IEntry<K, V>> entries()
Returns a list of all key-value entries in the map.
IMap<K, V> union(IMap<K, V> m)
Returns a new map containing all entries from both maps. If a key exists in both, the value from map m
is used.
IMap<K, V> difference(ISet<K> keys)
Returns a new map without the specified keys.
IMap<K, V> intersection(ISet<K> keys)
Returns a new map containing only the entries whose keys are in the specified set.
API: ISortedMap
ISortedMap
extends IMap
for maps that maintain their keys in a sorted order.
Additional Methods
Comparator<K> comparator()
Returns the Comparator
used to order the keys.
IEntry<K, V> floor(K key)
Returns the entry with the greatest key less than or equal to the given key, or null
if there is no such key.
IEntry<K, V> ceil(K key)
Returns the entry with the least key greater than or equal to the given key, or null
if there is no such key.
ISortedMap<K, V> slice(K min, K max)
Returns a view of the portion of this map whose keys range from min
(inclusive) to max
(exclusive).
IEntry<K, V> first()
Returns the first entry in the map, according to the key sort order.
IEntry<K, V> last()
Returns the last entry in the map.