| Constructor and Description |
|---|
Helpers() |
| Modifier and Type | Method and Description |
|---|---|
static <T> boolean |
all(List<T> list,
ConditionFunction<T> function)
Returns true if all of the values in the list pass the predicate truth test
|
static <T> boolean |
any(List<T> list,
ConditionFunction<T> function)
Returns true if any of the values in the list pass the predicate truth test
|
static <T> T |
at(List<T> list,
int index)
Return the element at index.
|
static <T> void |
compact$(List<T> list)
Remove null values in list
|
static <T> int |
count(List<T> list)
Return size of list or 0 to empty list.
|
static <T> int |
count(List<T> list,
ConditionFunction<T> function)
Return size of list where function returns true, or 0 to empty list.
|
static <T> List<T> |
drop(List<T> list,
int n)
Get the elements of list excluding the first n elements
|
static <T> void |
each(List<T> list,
EachFunction<T> function)
Execute a custom action for each element of list.
|
static <T> T |
fetch(List<T> list,
int index)
Identical to
List.get(int) |
static <T> T |
fetch(List<T> list,
int index,
T def)
Null-safe, get element at index, with default value.
|
static <T> T |
first(List<T> list)
Get the first element of list.
|
static <T> boolean |
isEmpty(List<T> list)
Check if list is empty
|
static <T> boolean |
isNotEmpty(List<T> list)
Check if list is not empty
|
static <T> T |
last(List<T> list)
Get the last element of list.
|
static <T> List<T> |
map(List<T> list,
MapFunction<T> function)
Return a new list of same type element, applying new value for each element.
|
static <T> void |
map$(List<T> list,
MapFunction<T> function)
Modifing list applying new value for each element.
|
static <T> void |
push(List<T> list,
T... ts)
Adding multiple elements to the end of list.
|
static <T> ListHelper<T> |
push(List<T> list,
T t)
Adding element to the end of list.
|
static <T,R> R |
reduce(List<T> list,
R initialValue,
ReduceFunction<T,R> function)
Transform a list on a single value
|
static <T> List<T> |
reject(List<T> list,
ConditionFunction<T> function)
Select all elements that condition returns false.
|
static <T> void |
reject$(List<T> list,
ConditionFunction<T> function)
Select all elements that condition returns false.
|
static <T> List<T> |
select(List<T> list,
ConditionFunction<T> function)
Select all elements that condition returns true.
|
static <T> void |
select$(List<T> list,
ConditionFunction<T> function)
Select all elements that condition returns true.
|
static <T> int |
size(List<T> list)
Identical to List#size()
|
static <T> List<T> |
take(List<T> list,
int n)
Get the first n elements of list
|
static <T,R> List<R> |
transform(List<T> list,
TransformFunction<T,R> function)
Return a new list of another type element, applying a function for each element.
|
public static <T> void each(List<T> list, EachFunction<T> function)
list - list of elements to iteratefunction - function to execute in each elementpublic static <T> List<T> map(List<T> list, MapFunction<T> function)
list - list of elements to iteratefunction - function to apply in each value that returns the new valuepublic static <T,R> List<R> transform(List<T> list, TransformFunction<T,R> function)
list - list of elements to iteratefunction - function to apply in each element of listpublic static <T> List<T> select(List<T> list, ConditionFunction<T> function)
list - list of elements to iteratefunction - Apply in each element and select if returns true.public static <T> List<T> reject(List<T> list, ConditionFunction<T> function)
list - list of elements to iteratefunction - Apply in each element and select if returns true.public static <T> void map$(List<T> list, MapFunction<T> function)
list - values list of elementsfunction - function to apply in each value that returns the new valuepublic static <T> void select$(List<T> list, ConditionFunction<T> function)
list - values list of elementsfunction - Apply in each element and select if returns true.public static <T> void reject$(List<T> list, ConditionFunction<T> function)
list - values list of elementsfunction - Apply in each element and select if returns false.public static <T> void compact$(List<T> list)
list - values list of elementspublic static <T> void push(List<T> list, T... ts)
list - values list of elementsts - elements to pushpublic static <T> ListHelper<T> push(List<T> list, T t)
list - values list of elementst - element to pushpublic static <T> T at(List<T> list, int index)
index - index of elementpublic static <T> T fetch(List<T> list, int index)
List.get(int)list - list of elementsindex - index of elementIndexOutOfBoundsExceptionpublic static <T> T fetch(List<T> list, int index, T def)
list - list of elementsindex - index of elementdef - Default valuepublic static <T> T first(List<T> list)
list - list of elementspublic static <T> T last(List<T> list)
list - list of elementspublic static <T> List<T> take(List<T> list, int n)
list - values list of type Tn - number of elementspublic static <T> List<T> drop(List<T> list, int n)
list - list of elementsn - number of elements to excludepublic static <T> boolean isEmpty(List<T> list)
public static <T> boolean isNotEmpty(List<T> list)
public static <T> int size(List<T> list)
list - the list of elementspublic static <T> int count(List<T> list)
public static <T> int count(List<T> list, ConditionFunction<T> function)
list - the list of elementsfunction - the condition to consider element in countpublic static <T> boolean all(List<T> list, ConditionFunction<T> function)
function - apply in each element and return false if one of them failpublic static <T> boolean any(List<T> list, ConditionFunction<T> function)
function - apply in each element and return true if one of them passpublic static <T,R> R reduce(List<T> list, R initialValue, ReduceFunction<T,R> function)
list - list of elementsinitialValue - initial value of the to be returnedfunction - the reduce functionCopyright © 2015. All rights reserved.