Package software.amazon.smithy.utils
Class ListUtils
java.lang.Object
software.amazon.smithy.utils.ListUtils
Immutable List utilities to polyfill Java 9+ features.
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> List<T>copyOf(Collection<? extends T> values) Creates an immutable copy of the given list.static <T> List<T>of()Returns an unmodifiable list containing zero entries.static <T> List<T>of(T value) Returns an unmodifiable list containing a single entry.static <T> List<T>of(T... values) Returns an unmodifiable list containing any number of entries.static <T> List<T>of(T value1, T value2) Returns an unmodifiable list containing two entries.Creates a collector that collects into an unmodifiable list.
-
Method Details
-
copyOf
Creates an immutable copy of the given list.- Type Parameters:
T- the List's value type.- Parameters:
values- The collection to make an immutable list of.- Returns:
- An immutable List copy.
-
of
Returns an unmodifiable list containing zero entries.- Type Parameters:
T- the List's value type.- Returns:
- an empty List.
-
of
Returns an unmodifiable list containing a single entry.- Type Parameters:
T- the List's value type.- Parameters:
value- the List's value.- Returns:
- a List containing the specified value.
- Throws:
NullPointerException- if the value isnull.
-
of
Returns an unmodifiable list containing two entries.- Type Parameters:
T- the List's value type.- Parameters:
value1- The first value.value2- The second value.- Returns:
- a List containing the specified values.
-
of
Returns an unmodifiable list containing any number of entries.- Type Parameters:
T- the List's value type.- Parameters:
values- the List's values.- Returns:
- a List containing the specified values.
- Throws:
NullPointerException- if any value isnull.
-
toUnmodifiableList
Creates a collector that collects into an unmodifiable list.This is a polyfill equivalent of Java 10's
Collectors#toUnmodifiableList.- Type Parameters:
T- Type of value to expect.- Returns:
- a Collector that accumulates the entries into an unmodifiable List.
-