public class Lists extends Object
| Modifier and Type | Method and Description |
|---|---|
static <T> List<T> |
concat(List<? extends T> list0,
List<? extends T> list1)
Create a new list that is an unmodifiable view on the
concatenation of the given lists.
|
static <T> List<T> |
createIndexView(List<T> parent,
IntUnaryOperator indexLookup,
int size)
Create a view on the given list where each index will be
passed through the given lookup function in order to access the
corresponding element in the given parent list.
|
static <T> List<T> |
createIndexView(List<T> parent,
List<Integer> indices)
Create a view on the given list that contains only the elements
that are indicated by the given indices.
|
static <T> List<T> |
createView(int size,
IntFunction<? extends T> function)
Create a view on the given function, as a list with the
given size.
|
static <T> List<T> |
createView(int minIndexInclusive,
int maxIndexExclusive,
IntFunction<? extends T> f)
Returns a view on the given function, as a list that contains
the elements
f(minIndexInclusive) to
f(maxIndexExclusive-1) |
static <A,B,C> List<C> |
createView(List<? extends A> list0,
List<? extends B> list1,
BiFunction<? super A,? super B,? extends C> function)
Creates a list that is a view on the result of applying the
given function to the elements of the given lists.
|
static <T,U> List<U> |
createView(List<? extends T> list,
Function<? super T,? extends U> function)
Create a view on the given list that converts the values with
the given function.
|
static <A,B,C,D> List<D> |
createView(List<A> list0,
List<B> list1,
List<C> list2,
TriFunction<? super A,? super B,? super C,? extends D> function)
Creates a list that is a view on the result of applying the
given function to the elements of the given lists.
|
static List<Integer> |
fromArray(int... array)
Returns a list that is an unmodifiable view on the given array
|
static List<Integer> |
fromRange(int min,
int max)
Creates an unmodifiable list that contains consecutive integers
in the given range
|
static List<Long> |
fromRange(long min,
long max)
Creates an unmodifiable list that contains consecutive long values
in the given range
|
static <T> List<T> |
pad(List<? extends T> t,
int padLeft,
T padLeftValue,
int padRight,
T padRightValue)
Returns a new list that is a view on the given list, padded
with the specified number of elements.
|
static List<Double> |
steps(double offset,
double stepSize,
int size)
Returns an unmodifiable list with the given size that contains the
values
offset + i * stepSize |
static List<Integer> |
steps(int offset,
int stepSize,
int size)
Returns an unmodifiable list with the given size that contains the
values
offset + i * stepSize |
static List<Long> |
steps(long offset,
long stepSize,
int size)
Returns an unmodifiable list with the given size that contains the
values
offset + i * stepSize |
static <T> List<T> |
unmodifiableListWith(Collection<? extends T> input)
Utility method that returns an unmodifiable list with the given
contents
|
static void |
validateIndex(int index,
int size)
Make sure that the given index is valid for a list with the given
size, and throw an
IndexOutOfBoundsException if this
is not the case. |
static void |
validateSize(int size)
Make sure that the given size is not negative, and throw an
IllegalArgumentException otherwise |
static <T> List<T> |
withRandomAccess(List<T> list)
Returns a new list that wraps the given one, adding the
RandomAccess tagging interface. |
public static <T> List<T> unmodifiableListWith(Collection<? extends T> input)
T - The type of the elementsinput - The inputpublic static List<Integer> fromArray(int... array)
array - The arraypublic static <T,U> List<U> createView(List<? extends T> list, Function<? super T,? extends U> function)
RandomAccess
interface if the given list implements it.T - The input typeU - The result typelist - The listfunction - The functionpublic static <A,B,C> List<C> createView(List<? extends A> list0, List<? extends B> list1, BiFunction<? super A,? super B,? extends C> function)
RandomAccess
interface if the given lists implement it.A - The first element typeB - The second element typeC - The result typelist0 - The first listlist1 - The second listfunction - The function to combine the elementsIllegalArgumentException - If the given lists have different
sizespublic static <A,B,C,D> List<D> createView(List<A> list0, List<B> list1, List<C> list2, TriFunction<? super A,? super B,? super C,? extends D> function)
RandomAccess
interface if the given lists implement it.A - The first element typeB - The second element typeC - The third element typeD - The result typelist0 - The first listlist1 - The second listlist2 - The third listfunction - The function to combine the elementsIllegalArgumentException - If the given lists have different
sizespublic static <T> List<T> createView(int size, IntFunction<? extends T> function)
T - The element typesize - The sizefunction - The functionpublic static <T> List<T> createView(int minIndexInclusive, int maxIndexExclusive, IntFunction<? extends T> f)
f(minIndexInclusive) to
f(maxIndexExclusive-1)T - The element typeminIndexInclusive - The minimum index, inclusivemaxIndexExclusive - The maximum index, exclusivef - The functionIllegalArgumentException - If the given minimum index is larger
than the maximum indexpublic static <T> List<T> withRandomAccess(List<T> list)
RandomAccess tagging interface.T - The element typelist - The listpublic static List<Integer> steps(int offset, int stepSize, int size)
offset + i * stepSizeoffset - The offsetstepSize - The step sizesize - The sizeIllegalArgumentException - If the size is negativepublic static List<Long> steps(long offset, long stepSize, int size)
offset + i * stepSizeoffset - The offsetstepSize - The step sizesize - The sizeIllegalArgumentException - If the size is negativepublic static List<Double> steps(double offset, double stepSize, int size)
offset + i * stepSizeoffset - The offsetstepSize - The step sizesize - The sizeIllegalArgumentException - If the size is negativepublic static List<Integer> fromRange(int min, int max)
min - The minimum value, inclusivemax - The maximum value, exclusiveIllegalArgumentException - If the minimum is larger than the
maximumpublic static List<Long> fromRange(long min, long max)
min - The minimum value, inclusivemax - The maximum value, exclusiveIllegalArgumentException - If the minimum is larger than the
maximumpublic static <T> List<T> pad(List<? extends T> t, int padLeft, T padLeftValue, int padRight, T padRightValue)
RandomAccess
interface if the given list implements it.T - The element typet - The input listpadLeft - The number of padding elements at the leftpadLeftValue - The value for the left padding elementspadRight - The number of padding elements at the rightpadRightValue - The value for the right padding elementsIllegalArgumentException - If either of the given arguments
is negativepublic static <T> List<T> createIndexView(List<T> parent, List<Integer> indices)
T - The element type of the listparent - The parent listindices - The indicesNullPointerException - If any argument is nullpublic static <T> List<T> createIndexView(List<T> parent, IntUnaryOperator indexLookup, int size)
T - The element type of the listparent - The parent listindexLookup - The lookupsize - The size of the resulting listNullPointerException - If any argument is nullpublic static <T> List<T> concat(List<? extends T> list0, List<? extends T> list1)
T - The type of the elementslist0 - The first listlist1 - The second listpublic static void validateSize(int size)
IllegalArgumentException otherwisesize - The sizeIllegalArgumentException - If the size is negativepublic static void validateIndex(int index,
int size)
IndexOutOfBoundsException if this
is not the case.index - The indexsize - The sizeIndexOutOfBoundsException - If the index is negative or not
smaller than the sizeCopyright © 2020. All rights reserved.