Package org.eclipse.xtext.xbase.lib
Class ListExtensions
java.lang.Object
org.eclipse.xtext.xbase.lib.ListExtensions
This is an extension library for
lists
.- Author:
- Sebastian Zarnekow - Initial contribution and API
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T,
R> List<R> map
(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> List<T>
Reverses the order of the elements in the specified list.static <T> List<T>
reverseView
(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 Comparable<? super T>>
List<T>sortInplace
(List<T> list) Sorts the specified list itself into ascending order, according to the natural ordering of its elements.static <T> List<T>
sortInplace
(List<T> list, Comparator<? super T> comparator) Sorts the specified list itself according to the order induced by the specified comparator.static <T,
C extends Comparable<? super C>>
List<T>sortInplaceBy
(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.
-
Constructor Details
-
ListExtensions
public ListExtensions()
-
-
Method Details
-
sortInplace
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:
-
sortInplace
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:
-
sortInplaceBy
public static <T,C extends Comparable<? super C>> List<T> sortInplaceBy(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:
-
reverseView
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
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:
UnsupportedOperationException
- if the specified list or its list-iterator does not support the set method.
-
map
@Pure public static <T,R> List<R> map(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
.
-