@GwtCompatible
public class ListExtensions
extends java.lang.Object
lists
.Constructor and Description |
---|
ListExtensions() |
Modifier and Type | Method and Description |
---|---|
static <T,R> java.util.List<R> |
map(java.util.List<T> original,
Functions.Function1<? super T,? extends R> transformation)
Returns a list that performs the given
transformation for each element of original when
requested. |
static <T> java.util.List<T> |
reverse(java.util.List<T> list)
Reverses the order of the elements in the specified list.
|
static <T> java.util.List<T> |
reverseView(java.util.List<T> list)
Provides a reverse view on the given list which is especially useful to traverse a list backwards in a for-each
loop.
|
static <T extends java.lang.Comparable<? super T>> |
sortInplace(java.util.List<T> list)
Sorts the specified list itself into ascending order, according to the natural ordering of its elements.
|
static <T> java.util.List<T> |
sortInplace(java.util.List<T> list,
java.util.Comparator<? super T> comparator)
Sorts the specified list itself according to the order induced by the specified comparator.
|
static <T,C extends java.lang.Comparable<? super C>> |
sortInplaceBy(java.util.List<T> list,
Functions.Function1<? super T,C> key)
Sorts the specified list itself according to the order induced by applying a key function to each element which
yields a comparable criteria.
|
public static <T extends java.lang.Comparable<? super T>> java.util.List<T> sortInplace(java.util.List<T> list)
list
- the list to be sorted. May not be null
.Collections.sort(List)
public static <T> java.util.List<T> sortInplace(java.util.List<T> list, java.util.Comparator<? super T> comparator)
list
- the list to be sorted. May not be null
.comparator
- the comparator to be used. May be null
to indicate that the natural ordering of the
elements should be used.Collections.sort(List, Comparator)
,
sortInplace(List)
,
#sortInplaceBy(List, Function1)
public static <T,C extends java.lang.Comparable<? super C>> java.util.List<T> sortInplaceBy(java.util.List<T> list, Functions.Function1<? super T,C> key)
list
- the list to be sorted. May not be null
.key
- the key function to-be-used. May not be null
.Collections.sort(List)
@Pure public static <T> java.util.List<T> reverseView(java.util.List<T> list)
list
- the list whose elements should be traversed in reverse. May not be null
.public static <T> java.util.List<T> reverse(java.util.List<T> list)
list
- the list whose elements are to be reversed.java.lang.UnsupportedOperationException
- if the specified list or its list-iterator does not support the set method.@Pure public static <T,R> java.util.List<R> map(java.util.List<T> original, Functions.Function1<? super T,? extends R> transformation)
transformation
for each element of original
when
requested. The mapping is done lazily. That is, subsequent iterations of the elements in the list will
repeatedly apply the transformation. The returned list is a transformed view of original
; changes to
original
will be reflected in the returned list and vice versa (e.g. invocations of List.remove(int)
).original
- the original list. May not be null
.transformation
- the transformation. May not be null
.null
.