public class ListUtil
extends java.lang.Object
List
.Constructor and Description |
---|
ListUtil() |
Modifier and Type | Method and Description |
---|---|
static <T> boolean |
all(java.util.List<T> collection,
Predicate<T> predicate)
Checks whether all list items satisfy specified predicate.
|
static <T> boolean |
any(java.util.List<T> collection,
Predicate<T> predicate)
Checks whether the list contains at least one item which satisfies specified predicate.
|
static <T> int |
count(java.util.List<T> collection,
Predicate<T> predicate)
Gets count of items from the list which satisfy specified predicate.
|
static <T> T |
first(java.util.List<T> collection)
Selects the first item from the list, if list is empty throws exception.
|
static <T> T |
first(java.util.List<T> collection,
Predicate<T> predicate)
Selects the first item from the list which satisfies specified predicate, if list is empty or match not found throws exception.
|
static <T> T |
firstOrDefault(java.util.List<T> collection)
Selects the first item from the list, if list is empty returns null.
|
static <T> T |
firstOrDefault(java.util.List<T> collection,
Predicate<T> predicate)
Selects the first item from the list which satisfies specified predicate, if list is empty or match not found returns null.
|
static <T> boolean |
isNullOrEmpty(java.util.List<T> collection)
Checks whether list is null or empty.
|
static <T> void |
safeAdd(java.util.List<T> collection,
T item)
Adds items into list if it wasn't added before, otherwise nothing happens.
|
static <T,TResult> |
select(java.util.List<T> collection,
Func1<T,TResult> selector)
Selects all items from the list and transforms them according to provided selector.
|
static <T> T |
single(java.util.List<T> collection,
Predicate<T> predicate)
Selects single item which satisfies specified predicate, if there are more than one item which satisfies predicate then throws exception.
|
static <T> T |
singleOrDefault(java.util.List<T> collection,
Predicate<T> predicate)
Selects single item which satisfies specified predicate, If list is empty returns null and if there are more than one item which satisfies predicate then throws exception.
|
static <T> java.util.List<T> |
where(java.util.List<T> collection,
Predicate<T> predicate)
Selects all items from the list which satisfy specified predicate.
|
public static <T> boolean isNullOrEmpty(java.util.List<T> collection)
T
- The type of elements in the .collection
- The list to check.public static <T> T firstOrDefault(java.util.List<T> collection)
T
- The type of elements in the list.collection
- The list to process.public static <T> T firstOrDefault(java.util.List<T> collection, Predicate<T> predicate)
T
- The type of elements in the list.collection
- The list to process.predicate
- The predicate to check.public static <T> T first(java.util.List<T> collection)
T
- The type of elements in the list.collection
- The list to process.public static <T> T first(java.util.List<T> collection, Predicate<T> predicate)
T
- The type of elements in the list.collection
- The list to process.predicate
- The predicate to check.public static <T> T singleOrDefault(java.util.List<T> collection, Predicate<T> predicate)
T
- The type of elements in the list.collection
- The list to process.predicate
- The predicate to check.public static <T> T single(java.util.List<T> collection, Predicate<T> predicate)
T
- The type of elements in the list.collection
- The list to process.predicate
- The predicate to check.public static <T> boolean any(java.util.List<T> collection, Predicate<T> predicate)
T
- The type of elements in the list.collection
- The list to process.predicate
- The predicate to check.public static <T> boolean all(java.util.List<T> collection, Predicate<T> predicate)
T
- The type of elements in the list.collection
- The list to process.predicate
- The predicate to check.public static <T> java.util.List<T> where(java.util.List<T> collection, Predicate<T> predicate)
T
- The type of elements in the list.collection
- The list to process.predicate
- The predicate to check.public static <T> int count(java.util.List<T> collection, Predicate<T> predicate)
T
- The type of elements in the list.collection
- The list to process.predicate
- The predicate to check.public static <T,TResult> java.util.List<TResult> select(java.util.List<T> collection, Func1<T,TResult> selector)
T
- The type of elements in the list.TResult
- The type of elements which will be returned by selector.collection
- The list to process.selector
- The selector which transform list item to target type.public static <T> void safeAdd(java.util.List<T> collection, T item)
T
- The type of elements in the list.collection
- The list to add item to.item
- The item to add into the list.