Package software.amazon.smithy.utils
Class SetUtils
- java.lang.Object
-
- software.amazon.smithy.utils.SetUtils
-
public final class SetUtils extends java.lang.Object
Immutable Set utilities to polyfill Java 9+ features.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.util.Set<java.lang.String>
caseInsensitiveCopyOf(java.util.Collection<? extends java.lang.String> values)
static <T> java.util.Set<T>
copyOf(java.util.Collection<? extends T> values)
Creates an immutable copy of the given set.static <T> java.util.Set<T>
of()
Returns an unmodifiable set containing zero entries.static <T> java.util.Set<T>
of(T value)
Returns an unmodifiable set containing a single entry.static <T> java.util.Set<T>
of(T... values)
Returns an unmodifiable set containing any number of entries.static <T> java.util.Set<T>
orderedCopyOf(java.util.Collection<? extends T> values)
Creates an ordered immutable copy of the given set.static <T> java.util.stream.Collector<T,?,java.util.Set<T>>
toUnmodifiableSet()
Creates a collector that collects into an unmodifiable set.
-
-
-
Method Detail
-
copyOf
public static <T> java.util.Set<T> copyOf(java.util.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> java.util.Set<T> orderedCopyOf(java.util.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 java.util.Set<java.lang.String> caseInsensitiveCopyOf(java.util.Collection<? extends java.lang.String> values)
-
of
public static <T> java.util.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> java.util.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:
java.lang.NullPointerException
- if the value isnull
.
-
of
@SafeVarargs public static <T> java.util.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:
java.lang.IllegalArgumentException
- if any of the values is a duplicate.java.lang.NullPointerException
- if any value isnull
.
-
toUnmodifiableSet
public static <T> java.util.stream.Collector<T,?,java.util.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.
-
-