Package org.eclipse.xtext.xbase.lib
Class ListExtensions
- java.lang.Object
-
- org.eclipse.xtext.xbase.lib.ListExtensions
-
@GwtCompatible public class ListExtensions extends java.lang.Object
This is an extension library forlists
.
-
-
Constructor Summary
Constructors Constructor Description ListExtensions()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method 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 giventransformation
for each element oforiginal
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>>
java.util.List<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>>
java.util.List<T>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.
-
-
-
Method Detail
-
sortInplace
public static <T extends java.lang.Comparable<? super T>> java.util.List<T> sortInplace(java.util.List<T> list)
Sorts the specified list itself into ascending order, according to the natural ordering of its elements.- Parameters:
list
- the list to be sorted. May not benull
.- Returns:
- the sorted list itself.
- See Also:
Collections.sort(List)
-
sortInplace
public 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.- Parameters:
list
- the list to be sorted. May not benull
.comparator
- the comparator to be used. May benull
to indicate that the natural ordering of the elements should be used.- Returns:
- the sorted list itself.
- See Also:
Collections.sort(List, Comparator)
,sortInplace(List)
,sortInplaceBy(List, org.eclipse.xtext.xbase.lib.Functions.Function1)
-
sortInplaceBy
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)
Sorts the specified list itself according to the order induced by applying a key function to each element which yields a comparable criteria.- Parameters:
list
- the list to be sorted. May not benull
.key
- the key function to-be-used. May not benull
.- Returns:
- the sorted list itself.
- See Also:
Collections.sort(List)
-
reverseView
@Pure public 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. The list itself is not modified by calling this method.- Parameters:
list
- the list whose elements should be traversed in reverse. May not benull
.- Returns:
- a list with the same elements as the given list, in reverse
-
reverse
public static <T> java.util.List<T> reverse(java.util.List<T> list)
Reverses the order of the elements in the specified list. The list itself will be modified.- Parameters:
list
- the list whose elements are to be reversed.- Returns:
- the list itself
- Throws:
java.lang.UnsupportedOperationException
- if the specified list or its list-iterator does not support the set method.
-
map
@Pure public 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 giventransformation
for each element oforiginal
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 oforiginal
; changes tooriginal
will be reflected in the returned list and vice versa (e.g. invocations ofList.remove(int)
).- Parameters:
original
- the original list. May not benull
.transformation
- the transformation. May not benull
.- Returns:
- a list that effectively contains the results of the transformation. Never
null
.
-
-