Class LinearContainer<T>

java.lang.Object
imagingbook.common.util.LinearContainer<T>
Type Parameters:
T - the container's element type
All Implemented Interfaces:
Iterable<T>

public class LinearContainer<T> extends Object implements Iterable<T>
This class implements a 1D map for arbitrary objects with flexible bottom and top index, similar to an array in Pascal. Containers are immutable (apart from element values).
  • Constructor Details

    • LinearContainer

      public LinearContainer(int n)
      Creates a LinearContainer with the index range [0, n - 1], like an ordinary array.
      Parameters:
      n - size of the container.
    • LinearContainer

      public LinearContainer(int botIndex, int topIndex)
      Creates a LinearContainer with the index range [botIndex, topIndex].
      Parameters:
      botIndex - bottom (smallest) index.
      topIndex - top (largest) index.
  • Method Details

    • getElement

      public T getElement(int k)
      Returns the k-th element of this container.
      Parameters:
      k - the element index
      Returns:
      the k-th element
    • setElement

      public void setElement(int k, T elem)
      Sets (replaces) the k-th element of this container.
      Parameters:
      k - the element index
      elem - the new element
    • getBotIndex

      public int getBotIndex()
      Returns the bottom index of this container.
      Returns:
      the bottom index
    • getTopIndex

      public int getTopIndex()
      Returns the top index of this container.
      Returns:
      the top index
    • iterator

      public Iterator<T> iterator()
      Specified by:
      iterator in interface Iterable<T>