org.omnaest.utils.structure.collection
Class ListUtils

java.lang.Object
  extended by org.omnaest.utils.structure.collection.ListUtils

public class ListUtils
extends Object

Helper class for modifying List instances.

Author:
Omnaest

Nested Class Summary
static interface ListUtils.ElementTransformer<FROM,TO>
          The provides the transformation method to transform one generic element instance into another.
static class ListUtils.ElementTransformerIdentitiyCast<FROM,TO>
          Simple ListUtils.ElementTransformer implementation which casts the given object and returns it.
static interface ListUtils.MultiElementTransformer<FROM,TO>
          The provides the transformation method to transform one generic Collection instance into one or multiple elements of other type.
 
Constructor Summary
ListUtils()
           
 
Method Summary
static
<E> List<E>
intersection(Collection<? extends Collection<E>> listCollection)
          Returns a new List with only this elements which are in all of the given Lists
static
<E> List<E>
iteratorAsList(Iterator<E> iterator)
          Creates a List from a given Iterator
static
<E> E
lastElementOf(List<E> list)
          Returns the last element of the given List.
static
<E> E
lastElementOf(List<E> list, int reverseIndexPosition)
          Returns the element of the given List at the given reverse index position which is counted beginning from the last element.
static
<E> List<E>
mergeAll(Collection<? extends Collection<E>> collections)
          Merges all elements of the given Collection instances into one single List instance which keeps the order of the elements.
static
<E> List<E>
mergeAll(Collection<E>... collections)
          Merges all elements of the given Collection instances into one single List instance which keeps the order of the elements.
static
<FROM,TO> List<TO>
transform(Collection<FROM> collection, ListUtils.ElementTransformer<FROM,TO> elementTransformer)
          Transforms a given Collection instance from one generic type into the other using a given ListUtils.ElementTransformer.
static
<FROM,TO> List<TO>
transform(Collection<FROM> collection, ListUtils.ElementTransformer<FROM,TO> elementTransformer, boolean eliminateNullValues)
          Transforms a given Collection instance from one generic type into the other using a given ListUtils.ElementTransformer.
static
<FROM,TO> List<TO>
transform(Collection<FROM> collection, ListUtils.MultiElementTransformer<FROM,TO> multiElementTransformer)
          Transforms a given Collection instance from one generic type into the other using a given ListUtils.MultiElementTransformer.
static
<FROM,TO> List<TO>
transform(Collection<FROM> collection, ListUtils.MultiElementTransformer<FROM,TO> multiElementTransformer, boolean eliminateNullValues)
          Transforms a given Collection instance from one generic type into the other using a given ListUtils.ElementTransformer.
static
<FROM,TO> List<TO>
transformListExcludingNullElements(Collection<FROM> collection, ListUtils.ElementTransformer<FROM,TO> elementTransformer)
          Transforms a given Collection instance from one generic type into the other using a given ListUtils.ElementTransformer.
static
<FROM,TO> List<TO>
transformListExcludingNullElements(Collection<FROM> collection, ListUtils.MultiElementTransformer<FROM,TO> multiElementTransformer)
          Transforms a given Collection instance from one generic type into the other using a given ListUtils.MultiElementTransformer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ListUtils

public ListUtils()
Method Detail

iteratorAsList

public static <E> List<E> iteratorAsList(Iterator<E> iterator)
Creates a List from a given Iterator

Parameters:
iterator -
Returns:

transform

public static <FROM,TO> List<TO> transform(Collection<FROM> collection,
                                           ListUtils.ElementTransformer<FROM,TO> elementTransformer)
Transforms a given Collection instance from one generic type into the other using a given ListUtils.ElementTransformer.

Parameters:
collection -
elementTransformer -
See Also:
transform(Collection, ElementTransformer, boolean)

transform

public static <FROM,TO> List<TO> transform(Collection<FROM> collection,
                                           ListUtils.MultiElementTransformer<FROM,TO> multiElementTransformer)
Transforms a given Collection instance from one generic type into the other using a given ListUtils.MultiElementTransformer.

Parameters:
collection -
multiElementTransformer -
See Also:
transform(Collection, ElementTransformer, boolean)

transformListExcludingNullElements

public static <FROM,TO> List<TO> transformListExcludingNullElements(Collection<FROM> collection,
                                                                    ListUtils.ElementTransformer<FROM,TO> elementTransformer)
Transforms a given Collection instance from one generic type into the other using a given ListUtils.ElementTransformer. Every null value returned by the ListUtils.ElementTransformer will be discarded and not put into the result list.

Parameters:
collection -
elementTransformer -
See Also:
transform(Collection, ElementTransformer, boolean)

transformListExcludingNullElements

public static <FROM,TO> List<TO> transformListExcludingNullElements(Collection<FROM> collection,
                                                                    ListUtils.MultiElementTransformer<FROM,TO> multiElementTransformer)
Transforms a given Collection instance from one generic type into the other using a given ListUtils.MultiElementTransformer. Every null value returned by the ListUtils.ElementTransformer will be discarded and not put into the result list.

Parameters:
collection -
multiElementTransformer -
See Also:
transform(Collection, ElementTransformer, boolean)

transform

public static <FROM,TO> List<TO> transform(Collection<FROM> collection,
                                           ListUtils.ElementTransformer<FROM,TO> elementTransformer,
                                           boolean eliminateNullValues)
Transforms a given Collection instance from one generic type into the other using a given ListUtils.ElementTransformer.

Parameters:
collection -
elementTransformer -
eliminateNullValues - : true->all null results from the element transformer will be discarded and not inserted into the result list.
See Also:
transform(Collection, ElementTransformer)

transform

public static <FROM,TO> List<TO> transform(Collection<FROM> collection,
                                           ListUtils.MultiElementTransformer<FROM,TO> multiElementTransformer,
                                           boolean eliminateNullValues)
Transforms a given Collection instance from one generic type into the other using a given ListUtils.ElementTransformer.

Parameters:
collection -
multiElementTransformer -
eliminateNullValues - : true->all null results from the element transformer will be discarded and not inserted into the result list.
Returns:
always new (ordered) list instance containing transformed elements
See Also:
transform(Collection, ElementTransformer)

mergeAll

public static <E> List<E> mergeAll(Collection<E>... collections)
Merges all elements of the given Collection instances into one single List instance which keeps the order of the elements.

Type Parameters:
E -
Parameters:
collections -
Returns:
See Also:
mergeAll(Collection)

mergeAll

public static <E> List<E> mergeAll(Collection<? extends Collection<E>> collections)
Merges all elements of the given Collection instances into one single List instance which keeps the order of the elements.

Type Parameters:
E -
Parameters:
collections -
Returns:
See Also:
mergeAll(Collection...)

lastElementOf

public static <E> E lastElementOf(List<E> list)
Returns the last element of the given List. Returns null if the list is null or empty.

Parameters:
list -
Returns:

lastElementOf

public static <E> E lastElementOf(List<E> list,
                                  int reverseIndexPosition)
Returns the element of the given List at the given reverse index position which is counted beginning from the last element. This means the last element has the reversed index position 0. Returns null if the list is null or empty.

Parameters:
list -
reverseIndexPosition -
Returns:

intersection

public static <E> List<E> intersection(Collection<? extends Collection<E>> listCollection)
Returns a new List with only this elements which are in all of the given Lists

Parameters:
listCollection -
Returns:


Copyright © 2011. All Rights Reserved.