org.eclipse.xtext.xbase.lib
Class MapExtensions

java.lang.Object
  extended by org.eclipse.xtext.xbase.lib.MapExtensions

@GwtCompatible
public class MapExtensions
extends Object

This is an extension library for maps.

Author:
Sebastian Zarnekow - Initial contribution and API

Constructor Summary
MapExtensions()
           
 
Method Summary
static
<K,V> Map<K,V>
filter(Map<K,V> original, Functions.Function2<? super K,? super V,Boolean> predicate)
           Returns a filtered live view on top of the original map.
static
<K,V> void
forEach(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(Map<K,V> map, Procedures.Procedure3<? super K,? super V,? super Integer> procedure)
          Applies the given procedure for each key value pair of the given map.
static
<K,V1,V2> Map<K,V2>
mapValues(Map<K,V1> original, Functions.Function1<? super V1,V2> transformation)
          Returns a map that performs the given transformation for each value of original when requested.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MapExtensions

public MapExtensions()
Method Detail

forEach

public static <K,V> void forEach(Map<K,V> map,
                                 Procedures.Procedure2<? super K,? super V> procedure)
Applies the given procedure for each key value pair of the given map.

Parameters:
map - the map. May not be null.
procedure - the procedure. May not be null.

forEach

public static <K,V> void forEach(Map<K,V> map,
                                 Procedures.Procedure3<? super K,? super V,? super Integer> procedure)
Applies the given 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.

Parameters:
map - the map. May not be null.
procedure - the procedure. May not be null.

filter

public static <K,V> Map<K,V> filter(Map<K,V> original,
                                    Functions.Function2<? super K,? super V,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.

Parameters:
original - the original map. May not be null.
predicate - the predicate. May not be null.
Returns:
a filtered view on top of the original map. Never null.

mapValues

public static <K,V1,V2> Map<K,V2> mapValues(Map<K,V1> original,
                                            Functions.Function1<? super V1,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.

Parameters:
original - the original map. May not be null.
transformation - the transformation. May not be null.
Returns:
a map with equal keys but transformed values. Never null.


Copyright © 2013. All Rights Reserved.