Class FilterSpliterator<T>

  • All Implemented Interfaces:
    java.lang.AutoCloseable, java.util.Spliterator<T>, CloseableSpliterator<T>

    public class FilterSpliterator<T>
    extends java.lang.Object
    implements CloseableSpliterator<T>
    Spliterator that only returns entries that pass the given predicate. This spliterator will inherit all of the characteristics of the underlying spliterator, except that it won't return Spliterator.SIZED or Spliterator.SUBSIZED.

    The forEachRemaining(Consumer) method should provide better performance than calling tryAdvance(Consumer) until it returns false. This is due to having to capture the argument before testing it and finally invoking the provided Consumer.

    Since:
    9.3
    Author:
    wburns
    • Nested Class Summary

      • Nested classes/interfaces inherited from interface java.util.Spliterator

        java.util.Spliterator.OfDouble, java.util.Spliterator.OfInt, java.util.Spliterator.OfLong, java.util.Spliterator.OfPrimitive<T extends java.lang.Object,​T_CONS extends java.lang.Object,​T_SPLITR extends java.util.Spliterator.OfPrimitive<T,​T_CONS,​T_SPLITR>>
    • Field Summary

      • Fields inherited from interface java.util.Spliterator

        CONCURRENT, DISTINCT, IMMUTABLE, NONNULL, ORDERED, SIZED, SORTED, SUBSIZED
    • Constructor Summary

      Constructors 
      Constructor Description
      FilterSpliterator​(java.util.Spliterator<T> spliterator, java.util.function.Predicate<? super T> predicate)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int characteristics()  
      void close()  
      long estimateSize()  
      void forEachRemaining​(java.util.function.Consumer<? super T> action)  
      boolean tryAdvance​(java.util.function.Consumer<? super T> action)  
      java.util.Spliterator<T> trySplit()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.util.Spliterator

        getComparator, getExactSizeIfKnown, hasCharacteristics
    • Constructor Detail

      • FilterSpliterator

        public FilterSpliterator​(java.util.Spliterator<T> spliterator,
                                 java.util.function.Predicate<? super T> predicate)
    • Method Detail

      • close

        public void close()
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface CloseableSpliterator<T>
      • tryAdvance

        public boolean tryAdvance​(java.util.function.Consumer<? super T> action)
        Specified by:
        tryAdvance in interface java.util.Spliterator<T>
      • forEachRemaining

        public void forEachRemaining​(java.util.function.Consumer<? super T> action)
        Specified by:
        forEachRemaining in interface java.util.Spliterator<T>
      • trySplit

        public java.util.Spliterator<T> trySplit()
        Specified by:
        trySplit in interface java.util.Spliterator<T>
      • estimateSize

        public long estimateSize()
        Specified by:
        estimateSize in interface java.util.Spliterator<T>
      • characteristics

        public int characteristics()
        Specified by:
        characteristics in interface java.util.Spliterator<T>