Class ListUtils

java.lang.Object
software.amazon.smithy.utils.ListUtils

public final class ListUtils extends Object
Immutable List utilities to polyfill Java 9+ features.
  • Method Details

    • copyOf

      public static <T> List<T> copyOf(Collection<? extends T> values)
      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

      public static <T> List<T> of()
      Returns an unmodifiable list containing zero entries.
      Type Parameters:
      T - the List's value type.
      Returns:
      an empty List.
    • of

      public static <T> List<T> of(T value)
      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 is null.
    • of

      @SafeVarargs public static <T> List<T> of(T... values)
      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 is null.
    • toUnmodifiableList

      public static <T> Collector<T,?,List<T>> 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.