Class Clustered<T>

  • All Implemented Interfaces:
    java.lang.Iterable<java.lang.Iterable<T>>

    public final class Clustered<T>
    extends java.lang.Object
    implements java.lang.Iterable<java.lang.Iterable<T>>
    An Iterable decorator which clusters consecutive elements of another Iterable by the result of a Comparator. Consecutive elements which compare to 0 go into the same cluster. The original order of the elements remains the same.
    
     Clustered(Comparator.naturalOrder(), [5, 5, 5, 3, 3, 4, 4, 4, 5, 5, 2, 2]) ->
     [
       [5, 5, 5],
       [3, 3],
       [4, 4, 4],
       [5, 5],
       [2, 2]
     ]
     
    • Constructor Summary

      Constructors 
      Constructor Description
      Clustered​(java.util.Comparator<? super T> comparator, java.lang.Iterable<T> delegate)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.util.Iterator<java.lang.Iterable<T>> iterator()  
      • Methods inherited from class java.lang.Object

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

        forEach, spliterator
    • Constructor Detail

      • Clustered

        public Clustered​(java.util.Comparator<? super T> comparator,
                         java.lang.Iterable<T> delegate)
    • Method Detail

      • iterator

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