Class CacheStrategy

java.lang.Object
loci.formats.cache.CacheStrategy
All Implemented Interfaces:
Comparator, CacheReporter, ICacheStrategy
Direct Known Subclasses:
CrosshairStrategy, RectangleStrategy

public abstract class CacheStrategy extends Object implements CacheReporter, Comparator, ICacheStrategy
Superclass of cache strategies.
  • Field Summary

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

    Constructors
    Constructor
    Description
    CacheStrategy(int[] lengths)
    Constructs a cache strategy.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Adds a listener for status update events.
    int
    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.
    Gets a list of all registered status update listeners.
    int[]
    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[]
    Retrieves the order in which objects should be loaded along each axis.
    protected abstract int[][]
    Gets positions to consider for possible inclusion in the cache, assuming a current position at the origin (0).
    int[]
    Retrieves the priority for caching each axis.
    int[]
    Retrieves the number of objects to cache along each axis.
    protected int
    Shortcut for computing total number of positions.
    protected void
    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
    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
  • Field Details

    • DEFAULT_RANGE

      public static final int DEFAULT_RANGE
      Default cache range.
      See Also:
    • 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 Vector listeners
      List of cache event listeners.
  • Constructor Details

    • CacheStrategy

      public CacheStrategy(int[] lengths)
      Constructs a cache strategy.
  • Method Details

    • 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(Object o1, 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 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.