java.util
Class Map

Method Summary
boolean any(groovy.lang.Closure closure)
Iterates over the entries of a map, and checks whether a predicate is valid for at least one entry
java.util.Map asImmutable()
A convenience method for creating an immutable map
java.util.Map asSynchronized()
A convenience method for creating a synchronized Map
java.lang.Object asType(java.lang.Class clazz)
java.util.Collection collect(java.util.Collection collection, groovy.lang.Closure closure)
Iterates through this Map transforming each entry into a new value using the closure as a transformer, returning a list of transformed values
java.util.List collect(groovy.lang.Closure closure)
Iterates through this Map transforming each entry into a new value using the closure as a transformer, returning a list of transformed values
java.util.Map each(groovy.lang.Closure closure)
Allows a Map to be iterated through using a closure
boolean every(groovy.lang.Closure closure)
Iterates over the entries of a map, and checks whether a predicate is valid for all entries
java.lang.Object find(groovy.lang.Closure closure)
Finds the first value matching the closure condition
java.util.Map findAll(groovy.lang.Closure closure)
Finds all entries matching the closure condition
java.lang.Object get(java.lang.Object key, java.lang.Object defaultValue)
Looks up an item in a Map for the given key and returns the value - unless there is no entry for the given key in which case add the default value to the map and return that
java.lang.Object getAt(java.lang.Object key)
Support the subscript operator for a List
java.util.Map groupBy(groovy.lang.Closure closure)
Groups all map members into groups determined by the supplied mapping closure
java.util.Map plus(java.util.Map right)

Returns a new Map containg all entries from left and right, giving precedence to right

java.lang.Object putAt(java.lang.Object key, java.lang.Object value)
A helper method to allow lists to work with subscript operators
groovy.lang.SpreadMap spread()
java.util.Map subMap(java.util.Collection keys)
Creates a sub-Map containing the given keys
java.lang.String toMapString()
Returns the string representation of the given map with bracket boundaries
groovy.lang.SpreadMap toSpreadMap()
Returns the converted SpreadLMap of the given self
java.lang.String toString()
Returns the string representation of the given map with bracket boundaries
 
Method Detail

any

public boolean any(groovy.lang.Closure closure)
Iterates over the entries of a map, and checks whether a predicate is valid for at least one entry

Parameters:
closure - the closure predicate used for matching.
Returns:
true if any entry in the map matches the closure predicate

asImmutable

public java.util.Map asImmutable()
A convenience method for creating an immutable map

Returns:
an immutable Map

asSynchronized

public java.util.Map asSynchronized()
A convenience method for creating a synchronized Map

Returns:
a synchronized Map

asType

public java.lang.Object asType(java.lang.Class clazz)

Parameters:
Returns:

collect

public java.util.Collection collect(java.util.Collection collection, groovy.lang.Closure closure)
Iterates through this Map transforming each entry into a new value using the closure as a transformer, returning a list of transformed values.

Parameters:
collection - the Collection to which the mapped values are added.
closure - the closure used for mapping, which can be with one(Map.Entry) or two(key, value) parameters.
Returns:
a List of the mapped values

collect

public java.util.List collect(groovy.lang.Closure closure)
Iterates through this Map transforming each entry into a new value using the closure as a transformer, returning a list of transformed values.

Parameters:
closure - the closure used to map each element of the collection.
Returns:
the resultant collection

each

public java.util.Map each(groovy.lang.Closure closure)
Allows a Map to be iterated through using a closure. If the closure takes one parameter then it will be passed the Map.Entry otherwise if the closure takes two parameters then it will be passed the key and the value.

Parameters:
closure - the closure applied on each entry of the map.
Returns:
returns the self parameter

every

public boolean every(groovy.lang.Closure closure)
Iterates over the entries of a map, and checks whether a predicate is valid for all entries.

Parameters:
closure - the closure predicate used for matching.
Returns:
true if every entry of the map matches the closure predicate

find

public java.lang.Object find(groovy.lang.Closure closure)
Finds the first value matching the closure condition

Parameters:
closure - a closure condition.
Returns:
the first Object found

findAll

public java.util.Map findAll(groovy.lang.Closure closure)
Finds all entries matching the closure condition. If the closure takes one parameter then it will be passed the Map.Entry otherwise if the closure takes two parameters then it will be passed the key and the value.

Parameters:
closure - a closure condition applying on the entries.
Returns:
a new subMap

get

public java.lang.Object get(java.lang.Object key, java.lang.Object defaultValue)
Looks up an item in a Map for the given key and returns the value - unless there is no entry for the given key in which case add the default value to the map and return that.

Parameters:
key - the key to lookup the value of.
defaultValue - the value to return and add to the map for this key if there is no entry for the given key.
Returns:
the value of the given key or the default value, added to the map if the key did not exist

getAt

public java.lang.Object getAt(java.lang.Object key)
Support the subscript operator for a List

Parameters:
key - an Object as a key for the map.
Returns:
the value corresponding to the given key

groupBy

public java.util.Map groupBy(groovy.lang.Closure closure)
Groups all map members into groups determined by the supplied mapping closure.

Parameters:
closure - a closure mapping entries on keys.
Returns:
a new Map grouped by keys

plus

public java.util.Map plus(java.util.Map right)

Returns a new Map containg all entries from left and right, giving precedence to right.

Equivalent to Map m = new HashMap(); m.putAll(left); m.putAll(right); return m;

Parameters:
right - a Map.
Returns:
a new Map containing all entries from left and right

putAt

public java.lang.Object putAt(java.lang.Object key, java.lang.Object value)
A helper method to allow lists to work with subscript operators

Parameters:
key - an Object as a key for the map.
value - the value to put into the map.
Returns:
the value corresponding to the given key

spread

public groovy.lang.SpreadMap spread()

Returns:

subMap

public java.util.Map subMap(java.util.Collection keys)
Creates a sub-Map containing the given keys. This method is similar to List.subList() but uses keys rather than index ranges.

Parameters:
keys - a Collection of keys.
Returns:
a new Map containing the given keys

toMapString

public java.lang.String toMapString()
Returns the string representation of the given map with bracket boundaries.

Returns:
the string representation

toSpreadMap

public groovy.lang.SpreadMap toSpreadMap()
Returns the converted SpreadLMap of the given self.

For examples, if there is defined a function like as

 def fn(a, b, c, d) { return a + b + c + d } 
, then all of the following three have the same meaning.
 println fn(a:1, [b:2, c:3].toSpreadMap(), d:4) println fn(a:1, *:[b:2, c:3], d:4) println fn(a:1, b:2, c:3, d:4) 

Returns:
a newly created Spreadmap if this list is not null and its size is positive.

toString

public java.lang.String toString()
Returns the string representation of the given map with bracket boundaries.

Returns:
the string representation