Class FastCursorLoops

java.lang.Object
net.imglib2.loops.FastCursorLoops

public final class FastCursorLoops extends Object
A package-private utility class that's used by LoopBuilder.
See Also:
  • Field Details

  • Constructor Details

    • FastCursorLoops

      private FastCursorLoops()
  • Method Details

    • createLoop

      public static LongConsumer createLoop(Object action, List<? extends Cursor<?>> cursors)
      For example.: Given a BiConsumer and two Cursors:
      
      
      BiConsumer<A, B> biConsumer = ... ;
      Cursor<A> cursorA = ... ;
      Cursor<B> cursorB = ... ;
      
      
      This method createLoop(biConsumer, Arrays.asList(cursorA, cursorB)) will return a LongConsumer that is functionally equivalent to:
      
      
      LongConsumer loop = n -> {
          for ( long i = 0; i < n; i++ )
              biConsumer.accept( cursorA.next(), cursorB.next() );
      };
      
      
      The returned LongConsumer is created in a way, that it can be gracefully optimised by the Java just-in-time compiler.
      Parameters:
      action - This must be an instance of Consumer, BiConsumer, LoopBuilder.TriConsumer, LoopBuilder.FourConsumer, LoopBuilder.FiveConsumer or LoopBuilder.SixConsumer.
      cursors - A list of Cursor, the size of the list must fit given action.
      Throws:
      IllegalArgumentException - if the number of cursor does not fit the given consumer.