Package software.amazon.smithy.utils
Class SetUtils
java.lang.Object
software.amazon.smithy.utils.SetUtils
Immutable Set utilities to polyfill Java 9+ features.
-
Method Summary
Modifier and TypeMethodDescriptioncaseInsensitiveCopyOf(Collection<? extends String> values) static <T> Set<T>copyOf(Collection<? extends T> values) Creates an immutable copy of the given set.static <T> Set<T>of()Returns an unmodifiable set containing zero entries.static <T> Set<T>of(T value) Returns an unmodifiable set containing a single entry.static <T> Set<T>of(T... values) Returns an unmodifiable set containing any number of entries.static <T> Set<T>orderedCopyOf(Collection<? extends T> values) Creates an ordered immutable copy of the given set.Creates a collector that collects into an unmodifiable set.
-
Method Details
-
copyOf
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
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
-
of
Returns an unmodifiable set containing zero entries.- Type Parameters:
T- the Set's value type.- Returns:
- an empty Set.
-
of
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 isnull.
-
of
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 isnull.
-
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.
-