Class IntersectIteration<E,X extends Exception>

All Implemented Interfaces:
AutoCloseable, CloseableIteration<E,X>, Iteration<E,X>

public class IntersectIteration<E,X extends Exception> extends FilterIteration<E,X>
An Iteration that returns the intersection of the results of two Iterations. Optionally, the Iteration can be configured to filter duplicates from the returned elements.

Note that duplicates can also be filtered by wrapping this Iteration in a DistinctIteration, but that has a bit more overhead as it adds a second hash table lookup.

  • Field Details

  • Constructor Details

    • IntersectIteration

      public IntersectIteration(Iteration<? extends E,? extends X> arg1, Iteration<? extends E,? extends X> arg2)
      Creates a new IntersectIteration that returns the intersection of the results of two Iterations. By default, duplicates are not filtered from the results.
      Parameters:
      arg1 - An Iteration containing the first set of elements.
      arg2 - An Iteration containing the second set of elements.
    • IntersectIteration

      public IntersectIteration(Iteration<? extends E,? extends X> arg1, Iteration<? extends E,? extends X> arg2, Supplier<Set<E>> setMaker)
    • IntersectIteration

      public IntersectIteration(Iteration<? extends E,? extends X> arg1, Iteration<? extends E,? extends X> arg2, boolean distinct)
      Creates a new IntersectIteration that returns the intersection of the results of two Iterations.
      Parameters:
      arg1 - An Iteration containing the first set of elements.
      arg2 - An Iteration containing the second set of elements.
      distinct - Flag indicating whether duplicate elements should be filtered from the result.
    • IntersectIteration

      public IntersectIteration(Iteration<? extends E,? extends X> arg1, Iteration<? extends E,? extends X> arg2, boolean distinct, Supplier<Set<E>> setMaker)
      Creates a new IntersectIteration that returns the intersection of the results of two Iterations.
      Parameters:
      arg1 - An Iteration containing the first set of elements.
      arg2 - An Iteration containing the second set of elements.
      distinct - Flag indicating whether duplicate elements should be filtered from the result.
  • Method Details

    • accept

      protected boolean accept(E object) throws X
      Returns true if the object is in the set of elements of the second argument.
      Specified by:
      accept in class FilterIteration<E,X extends Exception>
      Parameters:
      object - The object to be tested.
      Returns:
      true if the object should be returned, false otherwise.
      Throws:
      X
    • addSecondSet

      public Set<E> addSecondSet(Iteration<? extends E,? extends X> arg2, Set<E> set) throws X
      Throws:
      X extends Exception
    • removeFromIncludeSet

      protected boolean removeFromIncludeSet(E object)
    • inIncludeSet

      protected boolean inIncludeSet(E object)
    • makeSet

      protected Set<E> makeSet()
    • handleClose

      protected void handleClose() throws X
      Description copied from class: IterationWrapper
      Closes this Iteration and also closes the wrapped Iteration if it is a CloseableIteration.
      Overrides:
      handleClose in class FilterIteration<E,X extends Exception>
      Throws:
      X
    • clearIncludeSet

      protected long clearIncludeSet()