java.lang.Object
imagingbook.common.util.LinearContainer<T>
- Type Parameters:
T
- the container's element type
- All Implemented Interfaces:
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 Summary
ConstructorsConstructorDescriptionLinearContainer
(int n) Creates a LinearContainer with the index range [0, n - 1], like an ordinary array.LinearContainer
(int botIndex, int topIndex) Creates a LinearContainer with the index range [botIndex, topIndex]. -
Method Summary
Modifier and TypeMethodDescriptionint
Returns the bottom index of this container.getElement
(int k) Returns the k-th element of this container.int
Returns the top index of this container.iterator()
void
setElement
(int k, T elem) Sets (replaces) the k-th element of this container.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
LinearContainer
Creates a LinearContainer with the index range [0, n - 1], like an ordinary array.- Parameters:
n
- size of the container.
-
LinearContainer
Creates a LinearContainer with the index range [botIndex, topIndex].- Parameters:
botIndex
- bottom (smallest) index.topIndex
- top (largest) index.
-
-
Method Details
-
getElement
Returns the k-th element of this container.- Parameters:
k
- the element index- Returns:
- the k-th element
-
setElement
Sets (replaces) the k-th element of this container.- Parameters:
k
- the element indexelem
- the new element
-
getBotIndex
Returns the bottom index of this container.- Returns:
- the bottom index
-
getTopIndex
Returns the top index of this container.- Returns:
- the top index
-
iterator
-