Class Sets


  • public final class Sets
    extends Object
    Set algebra operations are available in this class as static utility.

    Most operations are non-destructive, i.e. no input sets are modified during execution. The exception is operations ending in "Into." These accept the target collection of the final calculation as the first parameter.

    Some effort is made to return a SortedSet if any input set is sorted, but this is not guaranteed (e.g., this will not be the case for collections proxied by Hibernate). When in doubt, specify the target collection explicitly with the "Into" version. This class should be used to create instances of MutableSet, ImmutableSet and FixedSizeSet

    Mutable Examples:

     MutableSet<String> emptySet = Sets.mutable.empty();
     MutableSet<String> setWith = Sets.mutable.with("a", "b", "c");
     MutableSet<String> setOf = Sets.mutable.of("a", "b", "c");
     
    Immutable Examples:
     ImmutableSet<String> emptySet = Sets.immutable.empty();
     ImmutableSet<String> setWith = Sets.immutable.with("a", "b", "c");
     ImmutableSet<String> setOf = Sets.immutable.of("a", "b", "c");
     
    FixedSize Examples:
     FixedSizeSet<String> emptySet = Sets.fixedSize.empty();
     FixedSizeSet<String> setWith = Sets.fixedSize.with("a", "b", "c");
     FixedSizeSet<String> setOf = Sets.fixedSize.of("a", "b", "c");
     
    • Method Detail

      • adapt

        public static <T> MutableSet<T> adapt​(Set<T> set)
        Since:
        9.0.
      • union

        public static <E> MutableSet<E> union​(Set<? extends E> setA,
                                              Set<? extends E> setB)
      • unionInto

        public static <E,​R extends Set<E>> R unionInto​(R targetSet,
                                                             Set<? extends E> setA,
                                                             Set<? extends E> setB)
      • unionAll

        public static <E> MutableSet<E> unionAll​(Set<? extends E>... sets)
      • unionAllInto

        public static <E,​R extends Set<E>> R unionAllInto​(R targetSet,
                                                                Set<? extends E>... sets)
      • intersect

        public static <E> MutableSet<E> intersect​(Set<? extends E> setA,
                                                  Set<? extends E> setB)
      • intersectInto

        public static <E,​R extends Set<E>> R intersectInto​(R targetSet,
                                                                 Set<? extends E> setA,
                                                                 Set<? extends E> setB)
      • intersectAll

        public static <E> MutableSet<E> intersectAll​(Set<? extends E>... sets)
      • intersectAllInto

        public static <E,​R extends Set<E>> R intersectAllInto​(R targetSet,
                                                                    Set<? extends E>... sets)
      • difference

        public static <E> MutableSet<E> difference​(Set<? extends E> minuendSet,
                                                   Set<? extends E> subtrahendSet)
      • differenceInto

        public static <E,​R extends Set<E>> R differenceInto​(R targetSet,
                                                                  Set<? extends E> minuendSet,
                                                                  Set<? extends E> subtrahendSet)
      • differenceAll

        public static <E> MutableSet<E> differenceAll​(Set<? extends E>... sets)
      • differenceAllInto

        public static <E,​R extends Set<E>> R differenceAllInto​(R targetSet,
                                                                     Set<? extends E>... sets)
      • symmetricDifference

        public static <E> MutableSet<E> symmetricDifference​(Set<? extends E> setA,
                                                            Set<? extends E> setB)
      • symmetricDifferenceInto

        public static <E,​R extends Set<E>> R symmetricDifferenceInto​(R targetSet,
                                                                           Set<? extends E> setA,
                                                                           Set<? extends E> setB)
      • isSubsetOf

        public static <E> boolean isSubsetOf​(Set<? extends E> candidateSubset,
                                             Set<? extends E> candidateSuperset)
      • isProperSubsetOf

        public static <E> boolean isProperSubsetOf​(Set<? extends E> candidateSubset,
                                                   Set<? extends E> candidateSuperset)
      • cartesianProduct

        public static <A,​B> LazyIterable<Pair<A,​B>> cartesianProduct​(Set<A> set1,
                                                                                 Set<B> set2)
      • cartesianProduct

        public static <A,​B,​C> LazyIterable<C> cartesianProduct​(Set<A> set1,
                                                                           Set<B> set2,
                                                                           Function2<? super A,​? super B,​? extends C> function)