Class FastCursorLoops

    • Field Detail

      • factories

        private static final java.util.List<ClassCopyProvider<java.util.function.LongConsumer>> factories
    • Constructor Detail

      • FastCursorLoops

        private FastCursorLoops()
    • Method Detail

      • createLoop

        public static java.util.function.LongConsumer createLoop​(java.lang.Object action,
                                                                 java.util.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:
        java.lang.IllegalArgumentException - if the number of cursor does not fit the given consumer.