public class LinqUtils extends Object
Constructor and Description |
---|
LinqUtils() |
Modifier and Type | Method and Description |
---|---|
static <VALUE> VALUE |
aggregate(Collection<VALUE> values,
Aggregator<VALUE> aggregator) |
static <T> List<T> |
filter(Collection<T> collection,
Predicate<T> predicate)
Replaces LINQ WHERE
Returns list containing all objects from original collection that matches the predicate
|
static <T> T |
first(Collection<T> collection)
Replaces first() LINQ
Returns first object of collection or null if empty
|
static <T> T |
firstOrNull(Collection<T> collection,
Predicate<T> predicate)
Replaces firstOrDefault() LINQ
Returns first object from the collection that matches the predicate, or null if no such object was found
|
static <IN,OUT> List<OUT> |
foreach(Collection<IN> collection,
Function<IN,OUT> f)
Replaces LINQ's select()
Returns a new list which contains all the objects from original collection with function applied to them.
|
static <IN,KEY,VALUE> |
toMap(Collection<IN> collection,
Mapper<IN,KEY,VALUE> mapper)
Replaces LINQ ToDictionary()
Transforms given collection into map using mapper
|
public static <T> T firstOrNull(Collection<T> collection, Predicate<T> predicate)
public static <T> T first(Collection<T> collection)
public static <IN,OUT> List<OUT> foreach(Collection<IN> collection, Function<IN,OUT> f)
public static <T> List<T> filter(Collection<T> collection, Predicate<T> predicate)
public static <IN,KEY,VALUE> Map<KEY,VALUE> toMap(Collection<IN> collection, Mapper<IN,KEY,VALUE> mapper)
See DefaultMapper if you want to map keys only (similar to single parameter toDictionary())
public static <VALUE> VALUE aggregate(Collection<VALUE> values, Aggregator<VALUE> aggregator)
Copyright © 2012. All Rights Reserved.