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 Summary

    Modifier and Type
    Method
    Description
    static <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.
    static <T> Collector<T,?,List<T>>
    Creates a collector that collects into an unmodifiable list.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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

      public static <T> List<T> of(T value1, T value2)
      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

      @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.