Class Sets
- java.lang.Object
-
- io.microsphere.collection.Sets
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <E> java.util.Set<E>
ofSet()
Returns an empty unmodifiable set.static <E> java.util.Set<E>
ofSet(E e1)
Returns an unmodifiable set containing one element.static <E> java.util.Set<E>
ofSet(E... elements)
Returns an unmodifiable set containing the provided elements.static <E> java.util.Set<E>
ofSet(E e1, E e2)
Returns an unmodifiable set containing two elements.static <E> java.util.Set<E>
ofSet(E e1, E e2, E e3)
Returns an unmodifiable set containing three elements.static <E> java.util.Set<E>
ofSet(E e1, E e2, E e3, E e4)
Returns an unmodifiable set containing four elements.static <E> java.util.Set<E>
ofSet(E e1, E e2, E e3, E e4, E e5)
Returns an unmodifiable set containing five elements.static <E> java.util.Set<E>
ofSet(E e1, E e2, E e3, E e4, E e5, E e6)
Returns an unmodifiable set containing six elements.static <E> java.util.Set<E>
ofSet(E e1, E e2, E e3, E e4, E e5, E e6, E e7)
Returns an unmodifiable set containing seven elements.static <E> java.util.Set<E>
ofSet(E e1, E e2, E e3, E e4, E e5, E e6, E e7, E e8)
Returns an unmodifiable set containing eight elements.static <E> java.util.Set<E>
ofSet(E e1, E e2, E e3, E e4, E e5, E e6, E e7, E e8, E e9)
Returns an unmodifiable set containing nine elements.static <E> java.util.Set<E>
ofSet(E e1, E e2, E e3, E e4, E e5, E e6, E e7, E e8, E e9, E e10)
Returns an unmodifiable set containing ten elements.
-
-
-
Method Detail
-
ofSet
@Nonnull public static <E> java.util.Set<E> ofSet()
Returns an empty unmodifiable set.Unlike the
java.util.Set#of()
method introduced in JDK 9, this method provides a fallback behavior when running on older Java versions. If MethodHandle lookup for Set.of() fails, it gracefully degrades to returning an empty set viaCollections.emptySet()
.Example Usage
Set<String> emptySet = Sets.ofSet();
- Type Parameters:
E
- the element type- Returns:
- an empty unmodifiable set
- See Also:
java.util.Set#of()
,Collections.emptySet()
-
ofSet
@Nonnull public static <E> java.util.Set<E> ofSet(E e1)
Returns an unmodifiable set containing one element.Unlike the
java.util.Set#of(Object)
method introduced in JDK 9, this method provides a fallback behavior when running on older Java versions. If MethodHandle lookup for Set.of() fails, it gracefully degrades to usingCollections.singleton(Object)
.Example Usage
Set<String> singleElementSet = Sets.ofSet("apple");
- Type Parameters:
E
- the element type- Parameters:
e1
- the single element- Returns:
- a
Set
containing the specified element - Throws:
java.lang.NullPointerException
- if the element isnull
- See Also:
java.util.Set#of(Object)
,Collections.singleton(Object)
-
ofSet
@Nonnull public static <E> java.util.Set<E> ofSet(E e1, E e2)
Returns an unmodifiable set containing two elements.Unlike the
java.util.Set#of(Object, Object)
method introduced in JDK 9, this method provides a fallback behavior when running on older Java versions. If MethodHandle lookup for Set.of() fails, it gracefully degrades to using the internal utility methodSetUtils.of(Object...)
.Example Usage
Set<String> pairSet = Sets.ofSet("apple", "banana");
- Type Parameters:
E
- the element type- Parameters:
e1
- the first elemente2
- the second element- Returns:
- a
Set
containing the specified elements - Throws:
java.lang.NullPointerException
- if any element isnull
- See Also:
java.util.Set#of(Object, Object)
-
ofSet
@Nonnull public static <E> java.util.Set<E> ofSet(E e1, E e2, E e3)
Returns an unmodifiable set containing three elements.Unlike the
java.util.Set#of(Object, Object, Object)
method introduced in JDK 9, this method provides a fallback behavior when running on older Java versions. If MethodHandle lookup for Set.of() fails, it gracefully degrades to using the internal utility methodSetUtils.of(Object...)
.Example Usage
Set<String> trioSet = Sets.ofSet("apple", "banana", "cherry");
- Type Parameters:
E
- the element type- Parameters:
e1
- the first elemente2
- the second elemente3
- the third element- Returns:
- a
Set
containing the specified elements - Throws:
java.lang.NullPointerException
- if any element isnull
- See Also:
java.util.Set#of(Object, Object, Object)
-
ofSet
public static <E> java.util.Set<E> ofSet(E e1, E e2, E e3, E e4)
Returns an unmodifiable set containing four elements.Unlike the
java.util.Set#of(Object, Object, Object, Object)
method introduced in JDK 9, this method provides a fallback behavior when running on older Java versions. If MethodHandle lookup for Set.of() fails, it gracefully degrades to using the internal utility methodSetUtils.of(Object...)
.Example Usage
Set<String> quadSet = Sets.ofSet("apple", "banana", "cherry", "date");
- Type Parameters:
E
- the element type- Parameters:
e1
- the first elemente2
- the second elemente3
- the third elemente4
- the fourth element- Returns:
- a
Set
containing the specified elements - Throws:
java.lang.NullPointerException
- if any element isnull
- See Also:
java.util.Set#of(Object, Object, Object, Object)
-
ofSet
@Nonnull public static <E> java.util.Set<E> ofSet(E e1, E e2, E e3, E e4, E e5)
Returns an unmodifiable set containing five elements.- Type Parameters:
E
- theSet
's element type- Parameters:
e1
- the first elemente2
- the second elemente3
- the third elemente4
- the fourth elemente5
- the fifth element- Returns:
- a
Set
containing the specified elements - Throws:
java.lang.NullPointerException
- if an element isnull
-
ofSet
@Nonnull public static <E> java.util.Set<E> ofSet(E e1, E e2, E e3, E e4, E e5, E e6)
Returns an unmodifiable set containing six elements.Unlike the
java.util.Set#of(Object, Object, Object, Object, Object, Object)
method introduced in JDK 9, this method provides a fallback behavior when running on older Java versions. If MethodHandle lookup for Set.of() fails, it gracefully degrades to using the internal utility methodSetUtils.of(Object...)
.Example Usage
Set<String> hexSet = Sets.ofSet("apple", "banana", "cherry", "date", "elderberry", "fig");
- Type Parameters:
E
- the element type- Parameters:
e1
- the first elemente2
- the second elemente3
- the third elemente4
- the fourth elemente5
- the fifth elemente6
- the sixth element- Returns:
- a
Set
containing the specified elements - Throws:
java.lang.NullPointerException
- if any element isnull
- See Also:
java.util.Set#of(Object, Object, Object, Object, Object, Object)
-
ofSet
@Nonnull public static <E> java.util.Set<E> ofSet(E e1, E e2, E e3, E e4, E e5, E e6, E e7)
Returns an unmodifiable set containing seven elements.Unlike the
java.util.Set#of(Object, Object, Object, Object, Object, Object, Object)
method introduced in JDK 9, this method provides a fallback behavior when running on older Java versions. If MethodHandle lookup for Set.of() fails, it gracefully degrades to using the internal utility methodSetUtils.of(Object...)
.Example Usage
Set<String> heptadSet = Sets.ofSet("a", "b", "c", "d", "e", "f", "g");
- Type Parameters:
E
- the element type- Parameters:
e1
- the first elemente2
- the second elemente3
- the third elemente4
- the fourth elemente5
- the fifth elemente6
- the sixth elemente7
- the seventh element- Returns:
- a
Set
containing the specified elements - Throws:
java.lang.NullPointerException
- if any element isnull
- See Also:
java.util.Set#of(Object, Object, Object, Object, Object, Object, Object)
-
ofSet
@Nonnull public static <E> java.util.Set<E> ofSet(E e1, E e2, E e3, E e4, E e5, E e6, E e7, E e8)
Returns an unmodifiable set containing eight elements.Unlike the
java.util.Set#of(Object, Object, Object, Object, Object, Object, Object, Object)
method introduced in JDK 9, this method provides a fallback behavior when running on older Java versions. If MethodHandle lookup for Set.of() fails, it gracefully degrades to using the internal utility methodSetUtils.ofSet(Object...)
Example Usage
Set<String> octetSet = Sets.ofSet("a", "b", "c", "d", "e", "f", "g", "h");
- Type Parameters:
E
- the element type- Parameters:
e1
- the first elemente2
- the second elemente3
- the third elemente4
- the fourth elemente5
- the fifth elemente6
- the sixth elemente7
- the seventh elemente8
- the eighth element- Returns:
- a
Set
containing the specified elements - Throws:
java.lang.NullPointerException
- if any element isnull
- See Also:
java.util.Set#of(Object, Object, Object, Object, Object, Object, Object, Object)
-
ofSet
@Nonnull public static <E> java.util.Set<E> ofSet(E e1, E e2, E e3, E e4, E e5, E e6, E e7, E e8, E e9)
Returns an unmodifiable set containing nine elements.Unlike the
java.util.Set#of(Object, Object, Object, Object, Object, Object, Object, Object, Object)
method introduced in JDK 9, this method provides a fallback behavior when running on older Java versions. If MethodHandle lookup for Set.of() fails, it gracefully degrades to using the internal utility methodSetUtils.of(Object...)
.Example Usage
Set<String> nonadSet = Sets.ofSet("a", "b", "c", "d", "e", "f", "g", "h", "i");
- Type Parameters:
E
- the element type- Parameters:
e1
- the first elemente2
- the second elemente3
- the third elemente4
- the fourth elemente5
- the fifth elemente6
- the sixth elemente7
- the seventh elemente8
- the eighth elemente9
- the ninth element- Returns:
- a
Set
containing the specified elements - Throws:
java.lang.NullPointerException
- if any element isnull
- See Also:
java.util.Set#of(Object, Object, Object, Object, Object, Object, Object, Object, Object)
-
ofSet
@Nonnull public static <E> java.util.Set<E> ofSet(E e1, E e2, E e3, E e4, E e5, E e6, E e7, E e8, E e9, E e10)
Returns an unmodifiable set containing ten elements.Unlike the
java.util.Set#of(Object, Object, Object, Object, Object, Object, Object, Object, Object, Object)
method introduced in JDK 9, this method provides a fallback behavior when running on older Java versions. If MethodHandle lookup for Set.of() fails, it gracefully degrades to using the internal utility methodSetUtils.of(Object...)
.Example Usage
Set<String> decadSet = Sets.ofSet("a", "b", "c", "d", "e", "f", "g", "h", "i", "j");
- Type Parameters:
E
- the element type- Parameters:
e1
- the first elemente2
- the second elemente3
- the third elemente4
- the fourth elemente5
- the fifth elemente6
- the sixth elemente7
- the seventh elemente8
- the eighth elemente9
- the ninth elemente10
- the tenth element- Returns:
- a
Set
containing the specified elements - Throws:
java.lang.NullPointerException
- if any element isnull
- See Also:
java.util.Set#of(Object, Object, Object, Object, Object, Object, Object, Object, Object, Object)
-
ofSet
@Nonnull public static <E> java.util.Set<E> ofSet(E... elements)
Returns an unmodifiable set containing the provided elements.Unlike the
java.util.Set#of(Object...)
method introduced in JDK 9, this method provides a fallback behavior when running on older Java versions. If MethodHandle lookup for Set.of() fails, it gracefully degrades to using the internal utility methodSetUtils.of(Object...)
.Example Usage
Set<String> varArgsSet = Sets.ofSet("apple", "banana", "cherry");
- Type Parameters:
E
- the element type- Parameters:
elements
- the elements to include in the set- Returns:
- a
Set
containing the specified elements - Throws:
java.lang.NullPointerException
- if any element isnull
- See Also:
java.util.Set#of(Object...)
-
-