Class Sets

  • All Implemented Interfaces:
    Utils

    public abstract class Sets
    extends java.lang.Object
    implements Utils
    The utility class for Set for Modern JDK(9+), which supports the feedback if Java Runtime is below JDK 9.
    Since:
    1.0.0
    Author:
    Mercy
    See Also:
    SetUtils
    • 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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • ofSet

        @Nonnull
        @Immutable
        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 via Collections.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
        @Immutable
        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 using Collections.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 is null
        See Also:
        java.util.Set#of(Object), Collections.singleton(Object)
      • ofSet

        @Nonnull
        @Immutable
        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 method SetUtils.of(Object...).

        Example Usage

        
         Set<String> pairSet = Sets.ofSet("apple", "banana");
         
        Type Parameters:
        E - the element type
        Parameters:
        e1 - the first element
        e2 - the second element
        Returns:
        a Set containing the specified elements
        Throws:
        java.lang.NullPointerException - if any element is null
        See Also:
        java.util.Set#of(Object, Object)
      • ofSet

        @Nonnull
        @Immutable
        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 method SetUtils.of(Object...).

        Example Usage

        
         Set<String> trioSet = Sets.ofSet("apple", "banana", "cherry");
         
        Type Parameters:
        E - the element type
        Parameters:
        e1 - the first element
        e2 - the second element
        e3 - the third element
        Returns:
        a Set containing the specified elements
        Throws:
        java.lang.NullPointerException - if any element is null
        See Also:
        java.util.Set#of(Object, Object, Object)
      • ofSet

        @Nonnull
        @Immutable
        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 method SetUtils.of(Object...).

        Example Usage

        
         Set<String> quadSet = Sets.ofSet("apple", "banana", "cherry", "date");
         
        Type Parameters:
        E - the element type
        Parameters:
        e1 - the first element
        e2 - the second element
        e3 - the third element
        e4 - the fourth element
        Returns:
        a Set containing the specified elements
        Throws:
        java.lang.NullPointerException - if any element is null
        See Also:
        java.util.Set#of(Object, Object, Object, Object)
      • ofSet

        @Nonnull
        @Immutable
        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 - the Set's element type
        Parameters:
        e1 - the first element
        e2 - the second element
        e3 - the third element
        e4 - the fourth element
        e5 - the fifth element
        Returns:
        a Set containing the specified elements
        Throws:
        java.lang.NullPointerException - if an element is null
      • ofSet

        @Nonnull
        @Immutable
        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 method SetUtils.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 element
        e2 - the second element
        e3 - the third element
        e4 - the fourth element
        e5 - the fifth element
        e6 - the sixth element
        Returns:
        a Set containing the specified elements
        Throws:
        java.lang.NullPointerException - if any element is null
        See Also:
        java.util.Set#of(Object, Object, Object, Object, Object, Object)
      • ofSet

        @Nonnull
        @Immutable
        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 method SetUtils.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 element
        e2 - the second element
        e3 - the third element
        e4 - the fourth element
        e5 - the fifth element
        e6 - the sixth element
        e7 - the seventh element
        Returns:
        a Set containing the specified elements
        Throws:
        java.lang.NullPointerException - if any element is null
        See Also:
        java.util.Set#of(Object, Object, Object, Object, Object, Object, Object)
      • ofSet

        @Nonnull
        @Immutable
        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 method SetUtils.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 element
        e2 - the second element
        e3 - the third element
        e4 - the fourth element
        e5 - the fifth element
        e6 - the sixth element
        e7 - the seventh element
        e8 - the eighth element
        Returns:
        a Set containing the specified elements
        Throws:
        java.lang.NullPointerException - if any element is null
        See Also:
        java.util.Set#of(Object, Object, Object, Object, Object, Object, Object, Object)
      • ofSet

        @Nonnull
        @Immutable
        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 method SetUtils.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 element
        e2 - the second element
        e3 - the third element
        e4 - the fourth element
        e5 - the fifth element
        e6 - the sixth element
        e7 - the seventh element
        e8 - the eighth element
        e9 - the ninth element
        Returns:
        a Set containing the specified elements
        Throws:
        java.lang.NullPointerException - if any element is null
        See Also:
        java.util.Set#of(Object, Object, Object, Object, Object, Object, Object, Object, Object)
      • ofSet

        @Nonnull
        @Immutable
        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 method SetUtils.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 element
        e2 - the second element
        e3 - the third element
        e4 - the fourth element
        e5 - the fifth element
        e6 - the sixth element
        e7 - the seventh element
        e8 - the eighth element
        e9 - the ninth element
        e10 - the tenth element
        Returns:
        a Set containing the specified elements
        Throws:
        java.lang.NullPointerException - if any element is null
        See Also:
        java.util.Set#of(Object, Object, Object, Object, Object, Object, Object, Object, Object, Object)
      • ofSet

        @Nonnull
        @Immutable
        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 method SetUtils.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 is null
        See Also:
        java.util.Set#of(Object...)