Class SetUtils

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

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

    • copyOf

      public static <T> Set<T> copyOf(Collection<? extends T> values)
      Creates an immutable copy of the given set.
      Type Parameters:
      T - the Set's value type.
      Parameters:
      values - The collection to make an immutable set of.
      Returns:
      An immutable Set copy.
    • orderedCopyOf

      public static <T> Set<T> orderedCopyOf(Collection<? extends T> values)
      Creates an ordered immutable copy of the given set.
      Type Parameters:
      T - the Set's value type.
      Parameters:
      values - The collection to make an immutable set of.
      Returns:
      An ordered immutable Set copy that maintains the order of the original.
    • caseInsensitiveCopyOf

      public static Set<String> caseInsensitiveCopyOf(Collection<? extends String> values)
    • of

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

      public static <T> Set<T> of(T value)
      Returns an unmodifiable set containing a single entry.
      Type Parameters:
      T - the Set's value type.
      Parameters:
      value - the Set's value.
      Returns:
      a Set containing the specified value.
      Throws:
      NullPointerException - if the value is null.
    • of

      @SafeVarargs public static <T> Set<T> of(T... values)
      Returns an unmodifiable set containing any number of entries.
      Type Parameters:
      T - the Set's value type.
      Parameters:
      values - the Set's values.
      Returns:
      a Set containing the specified values.
      Throws:
      IllegalArgumentException - if any of the values is a duplicate.
      NullPointerException - if any value is null.
    • toUnmodifiableSet

      public static <T> Collector<T,?,Set<T>> toUnmodifiableSet()
      Creates a collector that collects into an unmodifiable set.

      This is a polyfill equivalent of Java 10's Collectors#toUnmodifiableSet.

      Type Parameters:
      T - the Set's value type.
      Returns:
      a Collector that accumulates the entries into an unmodifiable Set.