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