@GwtCompatible
public class MapExtensions
extends java.lang.Object
maps.| Constructor and Description |
|---|
MapExtensions() |
| Modifier and Type | Method and Description |
|---|---|
static <K,V> java.util.Map<K,V> |
filter(java.util.Map<K,V> original,
Functions.Function2<? super K,? super V,java.lang.Boolean> predicate)
Returns a filtered live view on top of the original map.
|
static <K,V> void |
forEach(java.util.Map<K,V> map,
Procedures.Procedure2<? super K,? super V> procedure)
Applies the given
procedure for each key value pair of the given map. |
static <K,V> void |
forEach(java.util.Map<K,V> map,
Procedures.Procedure3<? super K,? super V,? super java.lang.Integer> procedure)
Applies the given
procedure for each key value pair of the given map. |
static <K,V1,V2> java.util.Map<K,V2> |
mapValues(java.util.Map<K,V1> original,
Functions.Function1<? super V1,? extends V2> transformation)
Returns a map that performs the given
transformation for each value of original when requested. |
static <K,V> void |
operator_add(java.util.Map<K,V> outputMap,
java.util.Map<? extends K,? extends V> inputMap)
Add the given entries of the input map into the output map.
|
static <K,V> V |
operator_add(java.util.Map<K,V> map,
Pair<? extends K,? extends V> entry)
Add the given pair into the map.
|
static <K,V> java.util.Map<K,V> |
operator_minus(java.util.Map<K,V> map,
java.lang.Iterable<?> keys)
Replies the elements of the given map except the pairs with the given keys.
|
static <K,V> java.util.Map<K,V> |
operator_minus(java.util.Map<K,V> map,
K key)
Replies the elements of the given map except the pair with the given key.
|
static <K,V> java.util.Map<K,V> |
operator_minus(java.util.Map<K,V> left,
java.util.Map<? extends K,? extends V> right)
Replies the elements of the left map without the pairs in the right map.
|
static <K,V> java.util.Map<K,V> |
operator_minus(java.util.Map<K,V> left,
Pair<? extends K,? extends V> right)
Remove the given pair from a given map for obtaining a new map.
|
static <K,V> java.util.Map<K,V> |
operator_plus(java.util.Map<K,V> left,
java.util.Map<? extends K,? extends V> right)
Merge the two maps.
|
static <K,V> java.util.Map<K,V> |
operator_plus(java.util.Map<K,V> left,
Pair<? extends K,? extends V> right)
Add the given pair to a given map for obtaining a new map.
|
static <K,V> void |
operator_remove(java.util.Map<K,V> map,
java.lang.Iterable<? super K> keysToRemove)
Remove pairs with the given keys from the map.
|
static <K,V> V |
operator_remove(java.util.Map<K,V> map,
K key)
Remove a key from the given map.
|
static <K,V> boolean |
operator_remove(java.util.Map<K,V> map,
Pair<? extends K,? extends V> entry)
Remove the given pair into the map.
|
static <K,V> java.util.Map<K,V> |
union(java.util.Map<? extends K,? extends V> left,
java.util.Map<? extends K,? extends V> right)
Merge the given maps.
|
public static <K,V> void forEach(java.util.Map<K,V> map,
Procedures.Procedure2<? super K,? super V> procedure)
procedure for each key value pair of the given map.map - the map. May not be null.procedure - the procedure. May not be null.public static <K,V> void forEach(java.util.Map<K,V> map,
Procedures.Procedure3<? super K,? super V,? super java.lang.Integer> procedure)
procedure for each key value pair of the given map.
The procedure takes the key, the value and a loop counter. If the counter would overflow, Integer.MAX_VALUE
is returned for all subsequent pairs. The first pair is at index zero.map - the map. May not be null.procedure - the procedure. May not be null.public static <K,V> java.util.Map<K,V> filter(java.util.Map<K,V> original,
Functions.Function2<? super K,? super V,java.lang.Boolean> predicate)
Returns a filtered live view on top of the original map. Changes to one affect the other.
The mapping is done lazily. That is, subsequent access of the values in the map will repeatedly apply the transformation. Characteristics of the original map, such as iteration order, are left intact. Changes in the original map are reflected in the result map. The results supports removal if the original map supports removal.
original - the original map. May not be null.predicate - the predicate. May not be null.null.public static <K,V> V operator_add(java.util.Map<K,V> map,
Pair<? extends K,? extends V> entry)
If the pair key already exists in the map, its value is replaced by the value in the pair, and the old value in the map is returned.
K - type of the map keys.V - type of the map values.map - the map to update.entry - the entry (key, value) to add into the map.null
if the key was not present in the map before the addition.public static <K,V> void operator_add(java.util.Map<K,V> outputMap,
java.util.Map<? extends K,? extends V> inputMap)
If a key in the inputMap already exists in the outputMap, its value is replaced in the outputMap by the value from the inputMap.
K - type of the map keys.V - type of the map values.outputMap - the map to update.inputMap - the entries to add.@Pure public static <K,V> java.util.Map<K,V> operator_plus(java.util.Map<K,V> left, Pair<? extends K,? extends V> right)
The replied map is a view on the given map. It means that any change in the original map is reflected to the result of this operation.
Even if the key of the right operand exists in the left operand, the value in the right operand is preferred.
K - type of the map keys.V - type of the map values.left - the map to consider.right - the entry (key, value) to add into the map.java.lang.IllegalArgumentException - - when the right operand key exists in the left operand.@Pure public static <K,V> java.util.Map<K,V> operator_plus(java.util.Map<K,V> left, java.util.Map<? extends K,? extends V> right)
The replied map is a view on the given map. It means that any change in the original map is reflected to the result of this operation.
If a key exists in the left and right operands, the value in the right operand is preferred.
K - type of the map keys.V - type of the map values.left - the left map.right - the right map.java.lang.IllegalArgumentException - - when a right operand key exists in the left operand.public static <K,V> V operator_remove(java.util.Map<K,V> map,
K key)
K - type of the map keys.V - type of the map values.map - the map to update.key - the key to remove.null if the key was not
present in the map.public static <K,V> boolean operator_remove(java.util.Map<K,V> map,
Pair<? extends K,? extends V> entry)
If the given key is inside the map, but is not mapped to the given value, the map will not be changed.
K - type of the map keys.V - type of the map values.map - the map to update.entry - the entry (key, value) to remove from the map.true if the pair was removed.public static <K,V> void operator_remove(java.util.Map<K,V> map,
java.lang.Iterable<? super K> keysToRemove)
K - type of the map keys.V - type of the map values.map - the map to update.keysToRemove - the keys of the pairs to remove.@Pure public static <K,V> java.util.Map<K,V> operator_minus(java.util.Map<K,V> left, Pair<? extends K,? extends V> right)
If the given key is inside the map, but is not mapped to the given value, the map will not be changed.
The replied map is a view on the given map. It means that any change in the original map is reflected to the result of this operation.
K - type of the map keys.V - type of the map values.left - the map to consider.right - the entry (key, value) to remove from the map.java.lang.IllegalArgumentException - - when the right operand key exists in the left operand.@Pure public static <K,V> java.util.Map<K,V> operator_minus(java.util.Map<K,V> map, K key)
The replied map is a view on the given map. It means that any change in the original map is reflected to the result of this operation.
K - type of the map keys.V - type of the map values.map - the map to update.key - the key to remove.@Pure public static <K,V> java.util.Map<K,V> operator_minus(java.util.Map<K,V> left, java.util.Map<? extends K,? extends V> right)
The difference is an immutable snapshot of the state of the maps at the time this method is called. It will never change, even if the maps change at a later time.
Since this method uses HashMap instances internally, the keys of
the supplied maps must be well-behaved with respect to
Object.equals(java.lang.Object) and Object.hashCode().
K - type of the map keys.V - type of the map values.left - the map to update.right - the pairs to remove.@Pure public static <K,V> java.util.Map<K,V> operator_minus(java.util.Map<K,V> map, java.lang.Iterable<?> keys)
The replied map is a view on the given map. It means that any change in the original map is reflected to the result of this operation.
K - type of the map keys.V - type of the map values.map - the map to update.keys - the keys of the pairs to remove.@Pure public static <K,V> java.util.Map<K,V> union(java.util.Map<? extends K,? extends V> left, java.util.Map<? extends K,? extends V> right)
The replied map is a view on the given two maps. If a key exists in the two maps, the replied value is the value of the right operand.
Even if the key of the right operand exists in the left operand, the value in the right operand is preferred.
The replied map is unmodifiable.
K - type of the map keys.V - type of the map values.left - the left map.right - the right map.@Pure public static <K,V1,V2> java.util.Map<K,V2> mapValues(java.util.Map<K,V1> original, Functions.Function1<? super V1,? extends V2> transformation)
Returns a map that performs the given transformation for each value of original when requested.
The mapping is done lazily. That is, subsequent access of the values in the map will repeatedly apply the transformation. Characteristics of the original map, such as iteration order, are left intact. Changes in the original map are reflected in the result map. The results supports removal if the original map supports removal.
original - the original map. May not be null.transformation - the transformation. May not be null.null.