Class LoopUtils


  • public final class LoopUtils
    extends java.lang.Object
    LoopUtils contains methods to simplify writing a loop over an image line or image interval.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private LoopUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.Runnable createIntervalLoop​(Positionable positionable, Dimensions dimensions, java.lang.Runnable action)
      Returns a Runnable containing a loop.
      static java.lang.Runnable createLineLoop​(Positionable positionable, long length, int dimension, java.lang.Runnable action)
      Returns a loop, that moves the given positonable along a line, and executes the given operation for each pixel of the line.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • LoopUtils

        private LoopUtils()
    • Method Detail

      • createLineLoop

        public static java.lang.Runnable createLineLoop​(Positionable positionable,
                                                        long length,
                                                        int dimension,
                                                        java.lang.Runnable action)

        Returns a loop, that moves the given positonable along a line, and executes the given operation for each pixel of the line. The method uses ClassCopyProvider, such that the returned loop can be optimised gracefully by the java just-in-time compiler. Aside from that, the result is functionally equivalent to:

         Runnable result = () -> {
             for (long i = 0; i < length; i++) {
                 operation.run();
                 positionable.fwd(dimension);
             }
             positionable.move(- length, dimension);
         }
         
         
        Parameters:
        positionable - Positionable that is moved (along a line). Defines the starting point of the line. After the loops execution the positionable is moved back to the starting point.
        length - Length of the line.
        dimension - Direction of the line.
        action - Operation that is executed for each pixel along the line.
        Returns:
        A Runnable that is functionally equivalent to:
      • createIntervalLoop

        public static java.lang.Runnable createIntervalLoop​(Positionable positionable,
                                                            Dimensions dimensions,
                                                            java.lang.Runnable action)
        Returns a Runnable containing a loop. The loop moves the given positionable over all the pixels of an interval. For each pixel of the interval the given operation is executed.
        Parameters:
        positionable - Positionable that is moved. Defines the minimum point of the interval. After the loops execution the positionable is moved back to the starting point.
        dimensions - Dimensions of the interval.
        action - Operation that is executed for each pixel of the interval.