|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.omnaest.utils.structure.collection.list.ListUtils
public class ListUtils
Helper class for modifying List instances.
| Constructor Summary | |
|---|---|
ListUtils()
|
|
| Method Summary | ||
|---|---|---|
static
|
adapter(List<FROM> list,
ElementBidirectionalConverter<FROM,TO> elementBidirectionalConverter)
Returns a new ListToListAdapter instance |
|
static
|
add(List<? extends E> list,
E... elements)
Returns the given List instance or a new List instance if the given one is null. |
|
static
|
add(List<? extends E> list,
E element)
Returns the given List instance or a new List instance if the given one is null. |
|
static
|
add(List<? extends E> list,
int index,
E... elements)
Similar to add(List, Object...) allowing to specify an index position |
|
static
|
add(List<? extends E> list,
int index,
E element)
Similar to add(List, Object) allowing to specify an index position |
|
static
|
addAll(List<? extends E> list,
E... elements)
Similar to add(List, Object...) |
|
static
|
addAll(List<? extends E> list,
int index,
E... elements)
Similar to add(List, int, Object...) |
|
static
|
addAll(List<? extends E> list,
Iterable<? extends E> iterable)
Adds all the elements from the Iterable to the given List instance. |
|
static
|
addToNewList(List<? extends E> list,
E... elements)
Returns a new List instance which contains all elements of the given List and additionally all further given
elements. |
|
static
|
addToNewList(List<? extends E> list,
E element)
Returns a new List instance which contains all elements of the given List and additionally the further given
element. |
|
static
|
asArray(List<? extends E> list,
Class<E> type)
Similar to List.toArray(Object[]), returns null if a null reference is given. |
|
static
|
convert(Collection<FROM> collection,
ElementConverter<FROM,TO> elementConverter)
Transforms a given Collection instance from one generic type into the other using a given ElementConverter. |
|
static
|
convert(Collection<FROM> collection,
ElementConverter<FROM,TO> elementConverter,
boolean eliminateNullValues)
Transforms a given Collection instance from one generic type into the other using a given ElementConverter. |
|
static
|
convert(Collection<FROM> collection,
ElementConverterOneToMany<FROM,TO> multiElementConverter)
Transforms a given Collection instance from one generic type into the other using a given
ElementConverterOneToMany. |
|
static
|
convert(Collection<FROM> collection,
ElementConverterOneToMany<FROM,TO> multiElementConverter,
boolean eliminateNullValues)
Transforms a given Collection instance from one generic type into the other using a given ElementConverter. |
|
static
|
convert(ElementConverter<FROM,TO> elementConverter,
FROM... elements)
|
|
static
|
convert(Iterable<FROM> iterable,
ElementConverter<FROM,TO> elementConverter)
Transforms a given Iterable instance from one generic type into the other using a given ElementConverter |
|
static
|
convertExcludingNullElements(Collection<FROM> collection,
ElementConverter<FROM,TO> elementConverter)
Transforms a given Collection instance from one generic type into the other using a given ElementConverter. |
|
static
|
convertListExcludingNullElements(Collection<FROM> collection,
ElementConverterOneToMany<FROM,TO> multiElementConverter)
Transforms a given Collection instance from one generic type into the other using a given
ElementConverterOneToMany. |
|
static
|
elementAt(List<E> list,
int index)
Returns the element at the given index position of the given List. |
|
static
|
elementAtInverseIndex(List<E> list,
int inverseIndex)
Returns the element at the given inverse index position of the given List. |
|
static
|
elementWithReverseIndexPosition(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
|
emptyList()
Returns an empty ArrayList |
|
static
|
filter(Collection<E> collection,
ElementFilter<E> elementFilter)
Returns a filtered List using a ElementFilter on the given Collection |
|
static
|
filter(Iterable<E> iterable,
ElementFilter<E> elementFilter)
Returns a filtered List using a ElementFilter on the given Iterable |
|
static
|
filter(List<E> list,
BitSet bitSet)
Returns a new List instance which contains all elements from the given List which have a related bit within
the BitSet set to true |
|
static
|
filter(List<E> list,
ExcludingElementFilterIndexPositionBased elementFilterIndexBased)
Returns a filtered List using a ExcludingElementFilterIndexPositionBased |
|
static
|
filterAndOrderBy(Iterable<E> sourceIterable,
Iterable<E>... filterAndOrderProvidingIterables)
Creates a new List instance based on the given source Iterable. |
|
static
|
filterExcludingBlankElements(Collection<String> collection)
Filters all blank elements from the given Collection with elements of type String and returns a new
List instance. |
|
static
|
filterExcludingElement(Collection<E> collection,
E element)
Returns a filtered List which does not contain the given element |
|
static
|
filterExcludingIndexPositions(List<E> list,
Collection<Integer> indexPositionCollection)
|
|
static
|
filterExcludingIndexPositions(List<E> list,
int... indexPositions)
|
|
static
|
filterExcludingNullElements(Collection<E> collection)
Filters all null elements from the given Collection and returns a new List instance. |
|
static
|
filterIncludingIndexPositions(List<E> list,
Collection<Integer> indexPositionCollection)
|
|
static
|
filterIncludingIndexPositions(List<E> list,
Integer... indexPositions)
|
|
static
|
firstElement(List<E> list)
Returns the first element of the given List. |
|
static
|
firstElementOf(List<E> list,
int reverseIndexPosition)
Returns the first element of a given List |
|
static
|
generateList(int numberOfElements,
Factory<E> valueFactory)
Generates a new List using the given value Factory to create all the elements the given number of times. |
|
static
|
get(List<E> list,
int index)
Returns the element at the given index position within the given List instance. |
|
static
|
indexListOf(List<E> list,
E element)
Returns a List of all index positions for the given element. |
|
static
|
intersection(Collection<? extends Collection<E>> collectionOfCollections)
Returns a new List with only this elements which are in all of the given Collections |
|
static
|
intersection(Collection<E>... collections)
Returns a new List with only this elements which are in all of the given Collections |
|
static boolean |
isListType(Class<?> type)
Returns true if the given type is not null and assignable to a List |
|
static
|
iterableAsList(Iterable<E> iterable)
Creates a new List from a given Iterable |
|
static
|
iteratorAsList(Iterator<E> iterator)
Creates a new List from a given Iterator |
|
static
|
lastElement(List<E> list)
Returns the last element of the given List. |
|
static
|
lastElementOf(List<E> list)
Returns the last element of the given List. |
|
static
|
locked(List<E> list,
Lock lock)
Returns a view of the given List using the given Lock to synchronize all of its methods |
|
static
|
locked(ListIterator<E> listIterator,
Lock lock)
Returns a view on the given ListIterator which uses a Lock to synchronize all its methods. |
|
static
|
lockedByReentrantLock(List<E> list)
Returns a view of the given List using a new ReentrantLock instance to synchronize all of its methods |
|
static
|
lockedByReentrantLock(ListIterator<E> listIterator)
Returns a view on the given ListIterator which uses a ReentrantLock to synchronize all its methods. |
|
static
|
max(List<E> list,
int maximumSize)
Returns a sublist of the given List with the maximum given size. |
|
static
|
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
|
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
|
remove(List<E> list,
int index)
Removes the element at the given index position of a given List instance. |
|
static
|
removeFirst(List<E> list)
Removes the first element of a given List instance. |
|
static
|
removeFirstToNewList(List<? extends E> list)
Short for valueOf(Iterable) and removeFirst(List) applied to the new List The source List is kept unaffected by this operation. |
|
static
|
removeLast(List<E> list)
Removes the last element of a given List instance. |
|
static
|
reverse(Iterable<E> iterable)
Returns a new List instance with the same elements of the given Iterable but in reversed order. |
|
static
|
set(List<E> list,
int index,
E element)
List.set(int, Object) the value of the given List instance at the given index position to the given element. |
|
static
|
sorted(Collection<E> collection)
Similar to sorted(Collection, Comparator) using the Comparable interface of the given elements |
|
static
|
sorted(Collection<E> collection,
Comparator<E> comparator)
Returns a new List instance which is based on the elements of the given Collection and which is sorted using
the given ComparatorIf the given Comparator is null the natural order is used. |
|
static
|
toMap(Iterable<E> iterable,
ElementConverterElementToMapEntry<E,K,V> elementToMapEntryTransformer)
|
|
static
|
toMap(KeyExtractor<? extends K,V> keyExtractor,
Iterable<? extends V> iterable)
Same as MapUtils.valueOf(KeyExtractor, Iterable) |
|
static
|
valueOf(E... elements)
Same as valueOf(Iterable) for one or more elements |
|
static
|
valueOf(ElementStream<E> elementStream)
Returns a new List instance for a given ElementStream |
|
static
|
valueOf(Iterable<? extends E> iterable)
Returns a new ArrayList instance containing the elements of a given Iterable |
|
static
|
valueOf(Iterator<E> iterator)
Returns a new List instance for a given Iterator |
|
static
|
valueOf(Iterator<E> iterator,
int toIndexPosition)
Returns a new List instance for all the elements up to the given end index position based on the given
Iterator. |
|
static
|
valueOf(Iterator<E> iterator,
int fromIndexPosition,
int toIndexPosition)
Returns a new List instance for all the elements between the two index position boundaries based on the given
Iterator. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public ListUtils()
| Method Detail |
|---|
public static <FROM,TO> List<TO> convert(Collection<FROM> collection,
ElementConverter<FROM,TO> elementConverter)
Collection instance from one generic type into the other using a given ElementConverter.
collection - elementConverter - convert(Collection, ElementConverter, boolean)
public static <FROM,TO> List<TO> convert(ElementConverter<FROM,TO> elementConverter,
FROM... elements)
elementConverter - elements -
convert(Collection, ElementConverter),
valueOf(Object...)
public static <FROM,TO> List<TO> convert(Iterable<FROM> iterable,
ElementConverter<FROM,TO> elementConverter)
Iterable instance from one generic type into the other using a given ElementConverter
iterable - elementConverter - convert(Collection, ElementConverter)
public static <FROM,TO> List<TO> convert(Collection<FROM> collection,
ElementConverter<FROM,TO> elementConverter,
boolean eliminateNullValues)
Collection instance from one generic type into the other using a given ElementConverter.
collection - elementConverter - eliminateNullValues - : true->all null results from the element transformer will be discarded and not inserted into the result list.convert(Collection, ElementConverter)
public static <FROM,TO> List<TO> convert(Collection<FROM> collection,
ElementConverterOneToMany<FROM,TO> multiElementConverter)
Collection instance from one generic type into the other using a given
ElementConverterOneToMany.
collection - multiElementConverter - convert(Collection, ElementConverter, boolean)
public static <FROM,TO> List<TO> convert(Collection<FROM> collection,
ElementConverterOneToMany<FROM,TO> multiElementConverter,
boolean eliminateNullValues)
Collection instance from one generic type into the other using a given ElementConverter.
collection - multiElementConverter - eliminateNullValues - : true->all null results from the element transformer will be discarded and not inserted into the result list.
convert(Collection, ElementConverter)
public static <FROM,TO> List<TO> convertExcludingNullElements(Collection<FROM> collection,
ElementConverter<FROM,TO> elementConverter)
Collection instance from one generic type into the other using a given ElementConverter.
Every null value returned by the ElementConverter will be discarded and not put into the result list.
collection - elementConverter - convert(Collection, ElementConverter, boolean)
public static <FROM,TO> List<TO> convertListExcludingNullElements(Collection<FROM> collection,
ElementConverterOneToMany<FROM,TO> multiElementConverter)
Collection instance from one generic type into the other using a given
ElementConverterOneToMany. Every null value returned by the ElementConverter will be discarded and not put
into the result list.
collection - multiElementConverter - convert(Collection, ElementConverter, boolean)
public static <E> List<E> filter(Collection<E> collection,
ElementFilter<E> elementFilter)
List using a ElementFilter on the given Collection
collection - elementFilter -
List instance containing only the not filtered elements of the given ListElementFilter,
ExcludingElementFilter
public static <E> List<E> filter(Iterable<E> iterable,
ElementFilter<E> elementFilter)
List using a ElementFilter on the given Iterable
iterable - IterableelementFilter -
List instance containing only the not filtered elements of the given ListElementFilter,
ExcludingElementFilter
public static <E> List<E> filter(List<E> list,
ExcludingElementFilterIndexPositionBased elementFilterIndexBased)
List using a ExcludingElementFilterIndexPositionBased
list - elementFilterIndexBased -
List instance containing only the not filtered elements of the given List
public static <E> List<E> filterAndOrderBy(Iterable<E> sourceIterable,
Iterable<E>... filterAndOrderProvidingIterables)
List instance based on the given source Iterable. The given Iterable is then filtered
by the additional filter and order providing Iterables. Filtering means that the list of source elements will only
retain elements, which are in the filter list, too. Additionally the order of the filter lists will be used to sort the ouput
List. Naturally the last applied filter will decide the order only.List
instance is returned.
sourceIterable - filterAndOrderProvidingIterables -
public static <E> List<E> filterExcludingElement(Collection<E> collection,
E element)
List which does not contain the given element
collection - element -
List instance containing only the not filtered elements of the given Listfilter(Iterable, ElementFilter)
public static <E> List<E> filterExcludingIndexPositions(List<E> list,
Collection<Integer> indexPositionCollection)
list - indexPositionCollection -
filter(List, ExcludingElementFilterIndexPositionBased)
public static <E> List<E> filterExcludingIndexPositions(List<E> list,
int... indexPositions)
list - indexPositions -
filter(List, ExcludingElementFilterIndexPositionBased)public static <E> List<E> filterExcludingNullElements(Collection<E> collection)
Collection and returns a new List instance.
collection -
public static <E> List<String> filterExcludingBlankElements(Collection<String> collection)
Collection with elements of type String and returns a new
List instance.
collection -
public static <E> List<E> filterIncludingIndexPositions(List<E> list,
Collection<Integer> indexPositionCollection)
list - indexPositionCollection -
filter(List, ExcludingElementFilterIndexPositionBased)
public static <E> List<E> filterIncludingIndexPositions(List<E> list,
Integer... indexPositions)
list - indexPositions -
filter(List, ExcludingElementFilterIndexPositionBased)
public static <E> List<E> filter(List<E> list,
BitSet bitSet)
List instance which contains all elements from the given List which have a related bit within
the BitSet set to true
list - ListbitSet - BitSet
List instancepublic static <E> List<E> valueOf(Iterable<? extends E> iterable)
ArrayList instance containing the elements of a given Iterable
iterable -
ArrayListpublic static <E> List<E> valueOf(Iterator<E> iterator)
List instance for a given Iterator
iterator -
public static <E> List<E> valueOf(Iterator<E> iterator,
int toIndexPosition)
List instance for all the elements up to the given end index position based on the given
Iterator. The upper boundary is exclusive.
iterator - toIndexPosition -
List instance
public static <E> List<E> valueOf(Iterator<E> iterator,
int fromIndexPosition,
int toIndexPosition)
List instance for all the elements between the two index position boundaries based on the given
Iterator. The lower boundary is inclusive, the upper boundary is exclusive.
iterator - fromIndexPosition - toIndexPosition -
List instancepublic static <E> List<E> valueOf(ElementStream<E> elementStream)
List instance for a given ElementStream
elementStream -
public static <E> List<E> valueOf(E... elements)
valueOf(Iterable) for one or more elements
elements -
public static <E> List<Integer> indexListOf(List<E> list,
E element)
List of all index positions for the given element. If no element can be found at all an empty List
is returned.
list - element -
public static <E> List<E> intersection(Collection<E>... collections)
List with only this elements which are in all of the given Collections
collections -
List instancepublic static <E> List<E> intersection(Collection<? extends Collection<E>> collectionOfCollections)
List with only this elements which are in all of the given Collections
collectionOfCollections -
List instancepublic static <E> List<E> iterableAsList(Iterable<E> iterable)
List from a given Iterable
iterable -
public static <E> List<E> iteratorAsList(Iterator<E> iterator)
List from a given Iterator
iterator -
public static <E> E lastElementOf(List<E> list)
List. Returns null if the list is null or empty.
list -
public static <E> E elementWithReverseIndexPosition(List<E> list,
int reverseIndexPosition)
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.
list - reverseIndexPosition -
public static <E> E firstElementOf(List<E> list,
int reverseIndexPosition)
List
list - reverseIndexPosition -
public static <E> List<E> mergeAll(Collection<? extends Collection<E>> collections)
Collection instances into one single List instance which keeps the order of
the elements.
E - collections -
mergeAll(Collection...)public static <E> List<E> mergeAll(Collection<E>... collections)
Collection instances into one single List instance which keeps the order of
the elements.
E - collections -
mergeAll(Collection)
public static <E> List<E> addToNewList(List<? extends E> list,
E... elements)
List instance which contains all elements of the given List and additionally all further given
elements.
list - elements -
List instance
public static <E> List<E> addToNewList(List<? extends E> list,
E element)
List instance which contains all elements of the given List and additionally the further given
element.
list - element -
List instance
public static <E> List<E> add(List<? extends E> list,
E element)
List instance or a new List instance if the given one is null. The returned instance will
contain all elements of the given List and additionally the further given element.
list - element -
List instance or new List instance if given List instance is null
public static <E> List<E> add(List<? extends E> list,
int index,
E element)
add(List, Object) allowing to specify an index position
list - index - element -
List instance or a new one
public static <E> List<E> addAll(List<? extends E> list,
Iterable<? extends E> iterable)
Iterable to the given List instance. If the given List instance is
null a new ArrayList is created. Iterable nothing will be added to the List.
list - iterable -
List instance or a new ArrayList if null is given
public static <E> List<E> addAll(List<? extends E> list,
E... elements)
add(List, Object...)
list - elements -
public static <E> List<E> add(List<? extends E> list,
E... elements)
List instance or a new List instance if the given one is null. The returned instance will
contain all elements of the given List and additionally all further given elements.
list - elements -
List instance or new List instance if given List instance is null
public static <E> List<E> addAll(List<? extends E> list,
int index,
E... elements)
add(List, int, Object...)
list - index - elements -
public static <E> List<E> add(List<? extends E> list,
int index,
E... elements)
add(List, Object...) allowing to specify an index position
list - index - elements -
List instance or a new one
public static <E> List<E> set(List<E> list,
int index,
E element)
List.set(int, Object) the value of the given List instance at the given index position to the given element. List, the List will be filled with null
values up to the index position. List instance a new ArrayList is created
list - Listindex - element -
List instance
public static <K,V,E> Map<K,V> toMap(KeyExtractor<? extends K,V> keyExtractor,
Iterable<? extends V> iterable)
MapUtils.valueOf(KeyExtractor, Iterable)
keyExtractor - KeyExtractoriterable - Iterable
MapUtils.valueOf(KeyExtractor, Iterable)
public static <K,V,E> Map<K,V> toMap(Iterable<E> iterable,
ElementConverterElementToMapEntry<E,K,V> elementToMapEntryTransformer)
iterable - elementToMapEntryTransformer -
MapUtils.valueOf(Iterable, ElementConverterElementToMapEntry)
public static <E> List<E> locked(List<E> list,
Lock lock)
List using the given Lock to synchronize all of its methods
list - lock -
lockedByReentrantLock(List)public static <E> List<E> lockedByReentrantLock(List<E> list)
List using a new ReentrantLock instance to synchronize all of its methods
list -
locked(List, Lock)
public static <E> ListIterator<E> locked(ListIterator<E> listIterator,
Lock lock)
ListIterator which uses a Lock to synchronize all its methods.
listIterator - lock -
public static <E> ListIterator<E> lockedByReentrantLock(ListIterator<E> listIterator)
ListIterator which uses a ReentrantLock to synchronize all its methods.
listIterator -
public static <E> E removeLast(List<E> list)
List instance. If the List reference is null or the List is empty
nothing will be done to the List.
list -
public static <E> E removeFirst(List<E> list)
List instance. If the List reference is null or the List is
empty nothing will be done to the List.
list -
public static <E> List<E> removeFirstToNewList(List<? extends E> list)
valueOf(Iterable) and removeFirst(List) applied to the new List List is kept unaffected by this operation.
list -
List instance
public static <E> E remove(List<E> list,
int index)
List instance. If the List reference is null or
the List is empty nothing will be done to the List.
list -
public static <E> E firstElement(List<E> list)
List. Returns null if the List reference is null or the
List.isEmpty().
list - lastElement(List),
elementAt(List, int)public static <E> E lastElement(List<E> list)
List. Returns null if the List reference is null or the
List.isEmpty().
list - firstElement(List),
elementAt(List, int)
public static <E> E elementAtInverseIndex(List<E> list,
int inverseIndex)
List. If the List reference is null or
the List.size() is to small, null is returned.
list - inverseIndex - firstElement(List),
lastElement(List),
elementAt(List, int)
public static <E> E elementAt(List<E> list,
int index)
List. If the List reference is null or the
List.size() is to small, null is returned.
list - index - elementAtInverseIndex(List, int),
firstElement(List),
lastElement(List)
public static <E> List<E> max(List<E> list,
int maximumSize)
List with the maximum given size. There will always a new List instance be
returned, but empty. If the given List has less elements only these are returned and the returned List will
not be filled with additional null references.
list - maximumSize -
public static <E> List<E> reverse(Iterable<E> iterable)
List instance with the same elements of the given Iterable but in reversed order.
iterable -
Collections.reverse(List)public static <E extends Comparable<E>> List<E> sorted(Collection<E> collection)
sorted(Collection, Comparator) using the Comparable interface of the given elements
collection -
List instance, null if given Collection is null
public static <E> List<E> sorted(Collection<E> collection,
Comparator<E> comparator)
List instance which is based on the elements of the given Collection and which is sorted using
the given ComparatorComparator is null the natural order is used. Collection will kept unmodified, only the returned List will be sorted.
collection - comparator -
List instanceCollections.sort(List, Comparator)
public static <E> List<E> generateList(int numberOfElements,
Factory<E> valueFactory)
List using the given value Factory to create all the elements the given number of times.
numberOfElements - valueFactory -
public static <E> E[] asArray(List<? extends E> list,
Class<E> type)
List.toArray(Object[]), returns null if a null reference is given.
list - List
Array instance
public static <FROM,TO> List<TO> adapter(List<FROM> list,
ElementBidirectionalConverter<FROM,TO> elementBidirectionalConverter)
ListToListAdapter instance
list - ListelementBidirectionalConverter - ElementBidirectionalConverter
public static <E> E get(List<E> list,
int index)
List instance. List is null, null is returned.
list - Listindex -
elementAt(List, int)public static <E> List<E> emptyList()
ArrayList
public static boolean isListType(Class<?> type)
List
type - Class
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||