Class BindActionToSamplers


  • final class BindActionToSamplers
    extends java.lang.Object
    Package-private utility class that's used by LoopBuilder.
    • Field Detail

      • factories

        private static final java.util.List<ClassCopyProvider<java.lang.Runnable>> factories
    • Constructor Detail

      • BindActionToSamplers

        BindActionToSamplers()
    • Method Detail

      • bindActionToSamplers

        public static java.lang.Runnable bindActionToSamplers​(java.lang.Object action,
                                                              java.util.List<? extends Sampler<?>> samplers)
        For example.: Given a BiConsumer and two Samplers:
         
        
         BiConsumer<A, B> biConsumer = ... ;
         Sampler<A> samplerA = ... ;
         Sampler<B> samplerB = ... ;
         
         
        This method bindConsumerToSamplers(biConsumer, Arrays.asList(samplerA, samplerB)) will return a Runnable that is functionally equivalent to:
         
        
         Runnable result = () -> {
             biConsumer.accept( sampleA.get(), samplerB.get() );
         };
         
         
        It does it in such manner, that the returned Runnable can be gracefully optimised by the Java just-in-time compiler.
        Parameters:
        action - This must be an instance of Consumer, BiConsumer of LoopBuilder.TriConsumer. LoopBuilder.FourConsumer, LoopBuilder.FourConsumer, or LoopBuilder.SixConsumer.
        samplers - A list of Sampler, the size of the list must fit the consumer given by {@param operation}.
        Throws:
        java.lang.IllegalArgumentException - if the number of sampler does not fit the given consumer.