Java Reference
In-Depth Information
For example:
{3,4,500}.forAll(i | i < 10) // evaluates to false
exists
Often you need to know whether there is at least one element in a collection for
which a Boolean is true . The exists() operation enables you to specify a
Boolean expression that must be true for at least one object in a collection:
collection.exists( v | boolean-expression-with-v )
The result of the exists() operation is true if boolean-expression-
with-v is true for at least one element of collection. If the boolean-expres-
sion-with-v is false for all elements in collection, then the complete
expression evaluates to false .
For example:
{3,4,500}.exists(i | i < 10)
// evaluates to true
sortBy
If you want to sort a list of elements, you can use the function sortBy() . The
list processed using sortBy is sorted by the results of the given expression.
For example:
elements.sortBy(e | e.name)
In the example, the list of elements is sorted by the name of the element .
Note that no Comparable type exists in the expression language. If the values
returned from the expression are instances of java.util.Comparable , the
compareTo() method is used; otherwise, toString() is invoked and the result
is compared.
Consider some more examples. (The following expressions return true .)
{'C','B','A'}.sortBy(e | e) == {'A','B','C'}
{'AAA','BB','C'}.sortBy(e | e.length) == {'C','BB','AAA'}
{5,3,1,2}.sortBy(e | e) == {1,2,3,5}
Search WWH ::




Custom Search