public final class Maps extends Object
maps
and map entries
.Modifier and Type | Method and Description |
---|---|
static <I,O> Fn<I,O> |
asFn(Map<I,O> map)
|
static <K,V> Map<K,V> |
asMap(Fn<K,V> fn)
|
static <K1,V1,K2,V2> |
combine(Map<K1,V1> first,
Fn<? super V1,? extends K2> connector,
Map<K2,V2> second)
Creates a combined view of two maps, where the values of the first map will be mapped (no pun
intended) to keys of the second map.
|
static <K,I,V> Map<K,V> |
combine(Map<K,I> first,
Map<I,V> second)
Creates a combined view of two maps, where the values of the first map corresponds
to keys of the second map.
|
static <K> Fn<Map.Entry<K,?>,K> |
key()
Gets the key of a
map entry . |
static <K> Predicate<K> |
keyIn(Map<K,?> map)
Evaluate if objects are a key
contained in
the given Map . |
static <V> Fn<Map.Entry<?,V>,V> |
value()
Gets the value of a
map entry . |
static <V> Predicate<V> |
valueIn(Map<?,? extends V> map)
Evaluate if objects are a value
contained in
the given Map . |
public static <K> Predicate<K> keyIn(Map<K,?> map)
contained in
the given Map
.public static <V> Predicate<V> valueIn(Map<?,? extends V> map)
contained in
the given Map
.public static <K,V> Map<K,V> asMap(Fn<K,V> fn)
Fn
as a Map
.
Any key which resolves to null
using the given Fn are not
considered to be contained
in the map, all other keys
are contained in the map.
This imposes some very limiting
constraints on the returned Map
. Especially, any method which
queries values without a key
, its size
,
whether it is empty
, and retrieving all
keys
, values
and entries
is not possible, and will throw NotPossibleOnMapViewOfFn
.
The returned Map
is mostly useable for retrieval of values based on
keys which must be known beforehand. If the map is cleared
, it
"becomes" a HashMap
, and thus will fully adhere to the Map
contract as its entries are no longer being dependent of the Fn
.
Fully supported Map
-operations:
Map.containsKey(Object)
Map.get(Object)
Map.put(Object, Object)
Map.putAll(Map)
Map.remove(Object)
Map.clear()
Map
interface, but it may still be appropriate for certain cases.
Careful considerations should be taken before using a Map
returned by this method.public static <I,O> Fn<I,O> asFn(Map<I,O> map)
Map
as the basis for a Fn
.
The value of the Fn
is resolved simply my calling
.get(I)
on the map with the given argument for
Fn.$(I)
. The semantics for null
are the
same as for Map.get(Object)
; the Fn
yields null
both for keys not present in the map, and for mapped null
values if
the map permits it.public static <K,I,V> Map<K,V> combine(Map<K,I> first, Map<I,V> second)
combine(Map, Fn, Map)
public static <K1,V1,K2,V2> Map<K1,V2> combine(Map<K1,V1> first, Fn<? super V1,? extends K2> connector, Map<K2,V2> second)
Similarily, the semantics of the containsKey(key)
works transitively.
It returns true only if the given key is contained in the first map, and yields a value
which is contained as a key in the second map. The usual behavior considering possible
null
s as keys and values applies as specified in the Map
interface, and is
dependent of the two maps the view is based on.
first
- The first map. All or a subset of the keys of this map will be keys in the returned view.connector
- A connector Fn
to map values of the first map to keys of the second map.second
- The second map. All or a subset of the values of this map will be values in the returned view.CombinedMapsView
.Copyright © 2016. All Rights Reserved.