loci.formats.cache

## Class CacheStrategy

- java.lang.Object
- - loci.formats.cache.CacheStrategy

- All Implemented Interfaces:
    java.util.Comparator, CacheReporter, ICacheStrategy
  Direct Known Subclasses:
    CrosshairStrategy, RectangleStrategy

      public abstract class CacheStrategy
      extends java.lang.Object
      implements CacheReporter, java.util.Comparator, ICacheStrategy

  Superclass of cache strategies.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static int` | `DEFAULT_RANGE` Default cache range.
    `private boolean` | `dirty` Whether load order array needs to be recomputed before building the next load list.
    `protected int[]` | `lengths` Length of each dimensional axis.
    `protected java.util.Vector` | `listeners` List of cache event listeners.
    `protected int[]` | `order` The order in which planes should be loaded along each axis.
    `private int[][]` | `positions` The list of dimensional positions to consider caching, in order of preference based on strategy, axis priority and planar ordering.
    `protected int[]` | `priorities` Priority for caching each axis.
    `protected int[]` | `range` Number of planes to cache along each axis.

    - ### Fields inherited from interface loci.formats.cache.ICacheStrategy

      `BACKWARD_ORDER, CENTERED_ORDER, FORWARD_ORDER, HIGH_PRIORITY, LOW_PRIORITY, MAX_PRIORITY, MIN_PRIORITY, NORMAL_PRIORITY`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `CacheStrategy(int[] lengths)` Constructs a cache strategy.

  - ### Method Summary

    All Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addCacheListener(CacheListener l)` Adds a listener for status update events.
    `int` | `compare(java.lang.Object o1, java.lang.Object o2)` Default comparator orders dimensional positions based on distance from the current position, taking into account axis priorities and planar ordering.
    `int` | `distance(int axis, int value)` Computes the distance from the given axis value to the axis center, taking into account the axis ordering scheme.
    `CacheListener[]` | `getCacheListeners()` Gets a list of all registered status update listeners.
    `int[]` | `getLengths()` Gets the lengths of all the axes.
    `int[][]` | `getLoadList(int[] pos)` Gets the indices of the objects to cache, surrounding the object at the given position.
    `int[]` | `getOrder()` Retrieves the order in which objects should be loaded along each axis.
    `protected abstract int[][]` | `getPossiblePositions()` Gets positions to consider for possible inclusion in the cache, assuming a current position at the origin (0).
    `int[]` | `getPriorities()` Retrieves the priority for caching each axis.
    `int[]` | `getRange()` Retrieves the number of objects to cache along each axis.
    `protected int` | `length()` Shortcut for computing total number of positions.
    `protected void` | `notifyListeners(CacheEvent e)` Informs listeners of a cache update.
    `protected int[]` | `pos(int raster)` Shortcut for converting rasterized position to N-D position.
    `protected int[]` | `pos(int raster, int[] pos)` Shortcut for converting rasterized position to N-D position, using the given array instead of allocating a new one.
    `protected int` | `raster(int[] pos)` Shortcut for converting N-D position to rasterized position.
    `void` | `removeCacheListener(CacheListener l)` Removes a listener for status update events.
    `void` | `setOrder(int order, int axis)` Sets the order in which objects should be loaded along each axis.
    `void` | `setPriority(int priority, int axis)` Sets the priority for caching the given axis.
    `void` | `setRange(int num, int axis)` Sets the number of objects to cache along the given axis.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

    - ### Methods inherited from interface java.util.Comparator

      `comparing, comparing, comparingDouble, comparingInt, comparingLong, equals, naturalOrder, nullsFirst, nullsLast, reversed, reverseOrder, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong`

- - ### Field Detail

    - #### DEFAULT_RANGE

          public static final int DEFAULT_RANGE

      Default cache range.
      See Also:
        Constant Field Values

    - #### lengths

          protected int[] lengths

      Length of each dimensional axis.

    - #### order

          protected int[] order

      The order in which planes should be loaded along each axis.

    - #### range

          protected int[] range

      Number of planes to cache along each axis.

    - #### priorities

          protected int[] priorities

      Priority for caching each axis. Controls axis caching order.

    - #### positions

          private int[][] positions

      The list of dimensional positions to consider caching, in order of preference based on strategy, axis priority and planar ordering.

    - #### dirty

          private boolean dirty

      Whether load order array needs to be recomputed before building the next load list.

    - #### listeners

          protected java.util.Vector listeners

      List of cache event listeners.

  - ### Constructor Detail

    - #### CacheStrategy

          public CacheStrategy(int[] lengths)

      Constructs a cache strategy.

  - ### Method Detail

    - #### getPossiblePositions

          protected abstract int[][] getPossiblePositions()

      Gets positions to consider for possible inclusion in the cache, assuming a current position at the origin (0).

    - #### distance

          public int distance(int axis,
                              int value)

      Computes the distance from the given axis value to the axis center, taking into account the axis ordering scheme.

    - #### raster

          protected int raster(int[] pos)

      Shortcut for converting N-D position to rasterized position.

    - #### pos

          protected int[] pos(int raster)

      Shortcut for converting rasterized position to N-D position.

    - #### pos

          protected int[] pos(int raster,
                              int[] pos)

      Shortcut for converting rasterized position to N-D position, using the given array instead of allocating a new one.

    - #### length

          protected int length()

      Shortcut for computing total number of positions.

    - #### addCacheListener

          public void addCacheListener(CacheListener l)

      Description copied from interface: `CacheReporter`
      Adds a listener for status update events.
      Specified by:
        `addCacheListener` in interface `CacheReporter`

    - #### removeCacheListener

          public void removeCacheListener(CacheListener l)

      Description copied from interface: `CacheReporter`
      Removes a listener for status update events.
      Specified by:
        `removeCacheListener` in interface `CacheReporter`

    - #### getCacheListeners

          public CacheListener[] getCacheListeners()

      Description copied from interface: `CacheReporter`
      Gets a list of all registered status update listeners.
      Specified by:
        `getCacheListeners` in interface `CacheReporter`

    - #### compare

          public int compare(java.lang.Object o1,
                             java.lang.Object o2)

      Default comparator orders dimensional positions based on distance from the current position, taking into account axis priorities and planar ordering.
      Specified by:
        `compare` in interface `java.util.Comparator`

    - #### getLoadList

          public int[][] getLoadList(int[] pos)
                              throws CacheException

      Description copied from interface: `ICacheStrategy`
      Gets the indices of the objects to cache, surrounding the object at the given position.
      Specified by:
        `getLoadList` in interface `ICacheStrategy`
      Throws:
        `CacheException`

    - #### getPriorities

          public int[] getPriorities()

      Description copied from interface: `ICacheStrategy`
      Retrieves the priority for caching each axis.
      Specified by:
        `getPriorities` in interface `ICacheStrategy`

    - #### setPriority

          public void setPriority(int priority,
                                  int axis)

      Description copied from interface: `ICacheStrategy`
      Sets the priority for caching the given axis.
      Specified by:
        `setPriority` in interface `ICacheStrategy`

    - #### getOrder

          public int[] getOrder()

      Description copied from interface: `ICacheStrategy`
      Retrieves the order in which objects should be loaded along each axis.
      Specified by:
        `getOrder` in interface `ICacheStrategy`
      Returns:
        An array whose constituents are each one of:
        - CENTERED_ORDER
        - FORWARD_ORDER
        - BACKWARD_ORDER

    - #### setOrder

          public void setOrder(int order,
                               int axis)

      Description copied from interface: `ICacheStrategy`
      Sets the order in which objects should be loaded along each axis.
      Specified by:
        `setOrder` in interface `ICacheStrategy`
      Parameters:
        `order` - One of:
        - CENTERED_ORDER
        - FORWARD_ORDER
        - BACKWARD_ORDER
        `axis` - The axis for which to set the order.

    - #### getRange

          public int[] getRange()

      Description copied from interface: `ICacheStrategy`
      Retrieves the number of objects to cache along each axis.
      Specified by:
        `getRange` in interface `ICacheStrategy`

    - #### setRange

          public void setRange(int num,
                               int axis)

      Description copied from interface: `ICacheStrategy`
      Sets the number of objects to cache along the given axis.
      Specified by:
        `setRange` in interface `ICacheStrategy`

    - #### getLengths

          public int[] getLengths()

      Description copied from interface: `ICacheStrategy`
      Gets the lengths of all the axes.
      Specified by:
        `getLengths` in interface `ICacheStrategy`

    - #### notifyListeners

          protected void notifyListeners(CacheEvent e)

      Informs listeners of a cache update.

Copyright © 2026 Open Microscopy Environment