public class MultidimensionalCounter
extends java.lang.Object
implements java.lang.Iterable<java.lang.Integer>
Modifier and Type | Class and Description |
---|---|
class |
MultidimensionalCounter.Iterator
Perform iteration over the multidimensional counter.
|
Modifier and Type | Field and Description |
---|---|
private int |
dimension
Number of dimensions.
|
private int |
last
Index of last dimension.
|
private int[] |
size
Counter sizes.
|
private int |
totalSize
Total number of (one-dimensional) slots.
|
private int[] |
uniCounterOffset
Offset for each dimension.
|
Constructor and Description |
---|
MultidimensionalCounter(int... size)
Create a counter.
|
Modifier and Type | Method and Description |
---|---|
private int[] |
copyOf(int[] source,
int newLen)
Java 1.5 does not support Arrays.copyOf()
|
int |
getCount(int... c)
Convert to unidimensional counter.
|
int[] |
getCounts(int index)
Convert to multidimensional counter.
|
int |
getDimension()
Get the number of dimensions of the multidimensional counter.
|
int |
getSize()
Get the total number of elements.
|
int[] |
getSizes()
Get the number of multidimensional counter slots in each dimension.
|
MultidimensionalCounter.Iterator |
iterator()
Create an iterator over this counter.
|
java.lang.String |
toString() |
private final int dimension
private final int[] uniCounterOffset
private final int[] size
private final int totalSize
private final int last
public MultidimensionalCounter(int... size)
size
- Counter sizes (number of slots in each dimension).NotStrictlyPositiveException
- if one of the sizes is
negative or zero.public MultidimensionalCounter.Iterator iterator()
iterator
in interface java.lang.Iterable<java.lang.Integer>
public int getDimension()
public int[] getCounts(int index)
index
- Index in unidimensional counter.OutOfRangeException
- if index
is not between
0
and the value returned by getSize()
(excluded).public int getCount(int... c) throws OutOfRangeException
c
- Indices in multidimensional counter.DimensionMismatchException
- if the size of c
does not match the size of the array given in the constructor.OutOfRangeException
- if a value of c
is not in
the range of the corresponding dimension, as defined in the
constructor
.public int getSize()
public int[] getSizes()
public java.lang.String toString()
toString
in class java.lang.Object
private int[] copyOf(int[] source, int newLen)
source
- the array to be copiednewLen
- the length of the copy to be returnedCopyright (c) 2003-2014 Apache Software Foundation