Class LazyMatchingTypeIterator<T>

  • Type Parameters:
    T - Type of iterated element
    All Implemented Interfaces:
    java.util.Iterator<T>

    public class LazyMatchingTypeIterator<T>
    extends java.lang.Object
    implements java.util.Iterator<T>
    An Iterator that selects only objects of a certain type from the underlying available ones. The "lazy" denomination is due to the fact that selection occurs only when hasNext() is called
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected boolean finished  
      protected T nextValue  
      private java.lang.Class<T> type  
      private java.util.Iterator<?> values  
    • Constructor Summary

      Constructors 
      Constructor Description
      LazyMatchingTypeIterator​(java.util.Iterator<?> values, java.lang.Class<T> type)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.Class<T> getType()  
      java.util.Iterator<?> getValues()  
      boolean hasNext()  
      static <T> java.util.Iterator<T> lazySelectMatchingTypes​(java.util.Iterator<?> values, java.lang.Class<T> type)  
      T next()  
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

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

        forEachRemaining, remove
    • Field Detail

      • finished

        protected boolean finished
      • nextValue

        protected T nextValue
      • values

        private final java.util.Iterator<?> values
      • type

        private final java.lang.Class<T> type
    • Constructor Detail

      • LazyMatchingTypeIterator

        public LazyMatchingTypeIterator​(java.util.Iterator<?> values,
                                        java.lang.Class<T> type)
    • Method Detail

      • getValues

        public java.util.Iterator<?> getValues()
      • getType

        public java.lang.Class<T> getType()
      • hasNext

        public boolean hasNext()
        Specified by:
        hasNext in interface java.util.Iterator<T>
      • next

        public T next()
        Specified by:
        next in interface java.util.Iterator<T>
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • lazySelectMatchingTypes

        public static <T> java.util.Iterator<T> lazySelectMatchingTypes​(java.util.Iterator<?> values,
                                                                        java.lang.Class<T> type)
        Type Parameters:
        T - Type if iterated element
        Parameters:
        values - The source values - ignored if null
        type - The (never @code null) type of values to select - any value whose type is assignable to this type will be selected by the iterator.
        Returns:
        An Iterator whose next() call selects only values matching the specific type. Note: the matching values are not pre-calculated (hence the "lazy" denomination) - i.e., the match is performed only when Iterator.hasNext() is called.