Class LazyMatchingTypeIterable<T>

  • Type Parameters:
    T - Type of element being selected
    All Implemented Interfaces:
    java.lang.Iterable<T>

    public class LazyMatchingTypeIterable<T>
    extends java.lang.Object
    implements java.lang.Iterable<T>
    Provides a selective Iterable over values that match a specific type out of all available. The "lazy" denomination is due to the fact that the next matching value is calculated on-the-fly every time Iterator.hasNext() is called
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.lang.Class<T> type  
      private java.lang.Iterable<?> values  
    • Constructor Summary

      Constructors 
      Constructor Description
      LazyMatchingTypeIterable​(java.lang.Iterable<?> 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.lang.Iterable<?> getValues()  
      java.util.Iterator<T> iterator()  
      static <T> java.lang.Iterable<T> lazySelectMatchingTypes​(java.lang.Iterable<?> values, java.lang.Class<T> type)  
      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.lang.Iterable

        forEach, spliterator
    • Field Detail

      • values

        private final java.lang.Iterable<?> values
      • type

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

      • LazyMatchingTypeIterable

        public LazyMatchingTypeIterable​(java.lang.Iterable<?> values,
                                        java.lang.Class<T> type)
    • Method Detail

      • getValues

        public java.lang.Iterable<?> getValues()
      • getType

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

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

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

        public static <T> java.lang.Iterable<T> lazySelectMatchingTypes​(java.lang.Iterable<?> 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:
        Iterable whose Iterator 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.