Interface SetIterable<T>

All Superinterfaces:
InternalIterable<T>, Iterable<T>, RichIterable<T>
All Known Subinterfaces:
FixedSizeSet<T>, ImmutableSet<T>, ImmutableSetIterable<T>, ImmutableSortedSet<T>, MultiReaderSet<T>, MutableSet<T>, MutableSetIterable<T>, MutableSortedSet<T>, SortedSetIterable<T>, UnsortedSetIterable<T>
All Known Implementing Classes:
AbstractImmutableSet, AbstractMutableSet, AbstractUnifiedSet, MultiReaderUnifiedSet, SetAdapter, SortedSetAdapter, SynchronizedMutableSet, SynchronizedSortedSet, TreeSortedSet, UnifiedSet, UnifiedSetWithHashingStrategy, UnmodifiableMutableSet, UnmodifiableSortedSet

public interface SetIterable<T>
extends RichIterable<T>
A Read-only Set api, with the minor exception inherited from java.lang.Iterable (iterable.iterator().remove()).
  • Method Details

    • union

      SetIterable<T> union​(SetIterable<? extends T> set)
      Returns the set of all objects that are a member of this or set or both. The union of [1, 2, 3] and [2, 3, 4] is the set [1, 2, 3, 4]. If equal elements appear in both sets, then the output will contain the copy from this.
    • unionInto

      <R extends Set<T>> R unionInto​(SetIterable<? extends T> set, R targetSet)
      Same as union(SetIterable) but adds all the objects to targetSet and returns it.
    • intersect

      SetIterable<T> intersect​(SetIterable<? extends T> set)
      Returns the set of all objects that are members of both this and set. The intersection of [1, 2, 3] and [2, 3, 4] is the set [2, 3]. The output will contain instances from this, not set.
    • intersectInto

      <R extends Set<T>> R intersectInto​(SetIterable<? extends T> set, R targetSet)
      Same as intersect(SetIterable) but adds all the objects to targetSet and returns it.
    • difference

      SetIterable<T> difference​(SetIterable<? extends T> subtrahendSet)
      Returns the set of all members of this that are not members of subtrahendSet. The difference of [1, 2, 3] and [2, 3, 4] is [1].
    • differenceInto

      <R extends Set<T>> R differenceInto​(SetIterable<? extends T> subtrahendSet, R targetSet)
      Same as difference(SetIterable) but adds all the objects to targetSet and returns it.
    • symmetricDifference

      SetIterable<T> symmetricDifference​(SetIterable<? extends T> setB)
      Returns the set of all objects that are a member of exactly one of this and setB (elements which are in one of the sets, but not in both). For instance, for the sets [1, 2, 3] and [2, 3, 4], the symmetric difference set is [1, 4] . It is the set difference of the union and the intersection.
    • symmetricDifferenceInto

      <R extends Set<T>> R symmetricDifferenceInto​(SetIterable<? extends T> set, R targetSet)
      Same as symmetricDifference(SetIterable) but adds all the objects to targetSet and returns it.
    • isSubsetOf

      boolean isSubsetOf​(SetIterable<? extends T> candidateSuperset)
      Returns true if all the members of this are also members of candidateSuperset. For example, [1, 2] is a subset of [1, 2, 3], but [1, 4] is not.
    • isProperSubsetOf

      boolean isProperSubsetOf​(SetIterable<? extends T> candidateSuperset)
      Returns true if all the members of this are also members of candidateSuperset and the two sets are not equal. For example, [1, 2] is a proper subset of [1, 2, 3], but [1, 2, 3] is not.
    • cartesianProduct

      <B> LazyIterable<Pair<T,​B>> cartesianProduct​(SetIterable<B> set)
      Returns the set whose members are all possible ordered pairs (a, b) where a is a member of this and b is a member of set.
    • tap

      SetIterable<T> tap​(Procedure<? super T> procedure)
      Description copied from interface: RichIterable
      Executes the Procedure for each element in the iterable and returns this.

      Example using a Java 8 lambda expression:

       RichIterable<Person> tapped =
           people.tap(person -> LOGGER.info(person.getName()));
       

      Example using an anonymous inner class:

       RichIterable<Person> tapped =
           people.tap(new Procedure<Person>()
           {
               public void value(Person person)
               {
                   LOGGER.info(person.getName());
               }
           });
       
      Specified by:
      tap in interface RichIterable<T>
      See Also:
      RichIterable.each(Procedure), RichIterable.forEach(Procedure)
    • select

      SetIterable<T> select​(Predicate<? super T> predicate)
      Description copied from interface: RichIterable
      Returns all elements of the source collection that return true when evaluating the predicate. This method is also commonly called filter.

      Example using a Java 8 lambda expression:

       RichIterable<Person> selected =
           people.select(person -> person.getAddress().getCity().equals("London"));
       

      Example using an anonymous inner class:

       RichIterable<Person> selected =
           people.select(new Predicate<Person>()
           {
               public boolean accept(Person person)
               {
                   return person.getAddress().getCity().equals("London");
               }
           });
       
      Specified by:
      select in interface RichIterable<T>
    • selectWith

      <P> SetIterable<T> selectWith​(Predicate2<? super T,​? super P> predicate, P parameter)
      Description copied from interface: RichIterable
      Similar to RichIterable.select(Predicate), except with an evaluation parameter for the second generic argument in Predicate2.

      E.g. return a Collection of Person elements where the person has an age greater than or equal to 18 years

      Example using a Java 8 lambda expression:

       RichIterable<Person> selected =
           people.selectWith((Person person, Integer age) -> person.getAge()>= age, Integer.valueOf(18));
       

      Example using an anonymous inner class:

       RichIterable<Person> selected =
           people.selectWith(new Predicate2<Person, Integer>()
           {
               public boolean accept(Person person, Integer age)
               {
                   return person.getAge()>= age;
               }
           }, Integer.valueOf(18));
       
      Specified by:
      selectWith in interface RichIterable<T>
      Parameters:
      predicate - a Predicate2 to use as the select criteria
      parameter - a parameter to pass in for evaluation of the second argument P in predicate
      See Also:
      RichIterable.select(Predicate)
    • reject

      SetIterable<T> reject​(Predicate<? super T> predicate)
      Description copied from interface: RichIterable
      Returns all elements of the source collection that return false when evaluating of the predicate. This method is also sometimes called filterNot and is the equivalent of calling iterable.select(Predicates.not(predicate)).

      Example using a Java 8 lambda expression:

       RichIterable<Person> rejected =
           people.reject(person -> person.person.getLastName().equals("Smith"));
       

      Example using an anonymous inner class:

       RichIterable<Person> rejected =
           people.reject(new Predicate<Person>()
           {
               public boolean accept(Person person)
               {
                   return person.person.getLastName().equals("Smith");
               }
           });
       
      Specified by:
      reject in interface RichIterable<T>
      Parameters:
      predicate - a Predicate to use as the reject criteria
      Returns:
      a RichIterable that contains elements that cause Predicate.accept(Object) method to evaluate to false
    • rejectWith

      <P> SetIterable<T> rejectWith​(Predicate2<? super T,​? super P> predicate, P parameter)
      Description copied from interface: RichIterable
      Similar to RichIterable.reject(Predicate), except with an evaluation parameter for the second generic argument in Predicate2.

      E.g. return a Collection of Person elements where the person has an age greater than or equal to 18 years

      Example using a Java 8 lambda expression:

       RichIterable<Person> rejected =
           people.rejectWith((Person person, Integer age) -> person.getAge() < age, Integer.valueOf(18));
       

      Example using an anonymous inner class:

       MutableList<Person> rejected =
           people.rejectWith(new Predicate2<Person, Integer>()
           {
               public boolean accept(Person person, Integer age)
               {
                   return person.getAge() < age;
               }
           }, Integer.valueOf(18));
       
      Specified by:
      rejectWith in interface RichIterable<T>
      Parameters:
      predicate - a Predicate2 to use as the select criteria
      parameter - a parameter to pass in for evaluation of the second argument P in predicate
      See Also:
      RichIterable.select(Predicate)
    • partition

      PartitionSet<T> partition​(Predicate<? super T> predicate)
      Description copied from interface: RichIterable
      Filters a collection into a PartitionedIterable based on the evaluation of the predicate.

      Example using a Java 8 lambda expression:

       PartitionIterable<Person> newYorkersAndNonNewYorkers =
           people.partition(person -> person.getAddress().getState().getName().equals("New York"));
       

      Example using an anonymous inner class:

       PartitionIterable<Person> newYorkersAndNonNewYorkers =
           people.partition(new Predicate<Person>()
           {
               public boolean accept(Person person)
               {
                   return person.getAddress().getState().getName().equals("New York");
               }
           });
       
      Specified by:
      partition in interface RichIterable<T>
    • partitionWith

      <P> PartitionSet<T> partitionWith​(Predicate2<? super T,​? super P> predicate, P parameter)
      Description copied from interface: RichIterable
      Filters a collection into a PartitionIterable based on the evaluation of the predicate.

      Example using a Java 8 lambda expression:

       PartitionIterable<Person> newYorkersAndNonNewYorkers =
           people.partitionWith((Person person, String state) -> person.getAddress().getState().getName().equals(state), "New York");
       

      Example using an anonymous inner class:

       PartitionIterable<Person> newYorkersAndNonNewYorkers =
           people.partitionWith(new Predicate2<Person, String>()
           {
               public boolean accept(Person person, String state)
               {
                   return person.getAddress().getState().getName().equals(state);
               }
           }, "New York");
       
      Specified by:
      partitionWith in interface RichIterable<T>
    • selectInstancesOf

      <S> SetIterable<S> selectInstancesOf​(Class<S> clazz)
      Description copied from interface: RichIterable
      Returns all elements of the source collection that are instances of the Class clazz.
       RichIterable<Integer> integers =
           List.mutable.with(new Integer(0), new Long(0L), new Double(0.0)).selectInstancesOf(Integer.class);
       
      Specified by:
      selectInstancesOf in interface RichIterable<T>
    • zipWithIndex

      @Deprecated SetIterable<Pair<T,​Integer>> zipWithIndex()
      Deprecated.
      in 6.0. Use OrderedIterable.zipWithIndex() instead.
      Description copied from interface: RichIterable
      Zips this RichIterable with its indices.
      Specified by:
      zipWithIndex in interface RichIterable<T>
      Returns:
      A new RichIterable containing pairs consisting of all elements of this RichIterable paired with their index. Indices start at 0.
      See Also:
      RichIterable.zip(Iterable)
    • asParallel

      ParallelSetIterable<T> asParallel​(ExecutorService executorService, int batchSize)
      Returns a parallel iterable of this SetIterable.
      Since:
      6.0
    • equals

      boolean equals​(Object o)
      Follows the same general contract as Set.equals(Object).
      Overrides:
      equals in class Object
    • hashCode

      int hashCode()
      Follows the same general contract as Set.hashCode().
      Overrides:
      hashCode in class Object
    • toImmutable

      ImmutableSetIterable<T> toImmutable()