Package org.hipparchus.util
Class MultidimensionalCounter
- java.lang.Object
-
- org.hipparchus.util.MultidimensionalCounter
-
public class MultidimensionalCounter extends Object implements Iterable<Integer>
Converter between unidimensional storage structure and multidimensional conceptual structure. This utility will convert from indices in a multidimensional structure to the corresponding index in a one-dimensional array. For example, assuming that the ranges (in 3 dimensions) of indices are 2, 4 and 3, the following correspondences, between 3-tuples indices and unidimensional indices, will hold:- (0, 0, 0) corresponds to 0
- (0, 0, 1) corresponds to 1
- (0, 0, 2) corresponds to 2
- (0, 1, 0) corresponds to 3
- ...
- (1, 0, 0) corresponds to 12
- ...
- (1, 3, 2) corresponds to 23
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classMultidimensionalCounter.IteratorPerform iteration over the multidimensional counter.
-
Constructor Summary
Constructors Constructor Description MultidimensionalCounter(int... size)Create a counter.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intgetCount(int... c)Convert to unidimensional counter.int[]getCounts(int index)Convert to multidimensional counter.intgetDimension()Get the number of dimensions of the multidimensional counter.intgetSize()Get the total number of elements.int[]getSizes()Get the number of multidimensional counter slots in each dimension.MultidimensionalCounter.Iteratoriterator()Create an iterator over this counter.StringtoString()-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Constructor Detail
-
MultidimensionalCounter
public MultidimensionalCounter(int... size) throws MathIllegalArgumentExceptionCreate a counter.- Parameters:
size- Counter sizes (number of slots in each dimension).- Throws:
MathIllegalArgumentException- if one of the sizes is negative or zero.
-
-
Method Detail
-
iterator
public MultidimensionalCounter.Iterator iterator()
Create an iterator over this counter.
-
getDimension
public int getDimension()
Get the number of dimensions of the multidimensional counter.- Returns:
- the number of dimensions.
-
getCounts
public int[] getCounts(int index) throws MathIllegalArgumentExceptionConvert to multidimensional counter.- Parameters:
index- Index in unidimensional counter.- Returns:
- the multidimensional counts.
- Throws:
MathIllegalArgumentException- ifindexis not between0and the value returned bygetSize()(excluded).
-
getCount
public int getCount(int... c) throws MathIllegalArgumentExceptionConvert to unidimensional counter.- Parameters:
c- Indices in multidimensional counter.- Returns:
- the index within the unidimensionl counter.
- Throws:
MathIllegalArgumentException- if the size ofcdoes not match the size of the array given in the constructor.MathIllegalArgumentException- if a value ofcis not in the range of the corresponding dimension, as defined in theconstructor.
-
getSize
public int getSize()
Get the total number of elements.- Returns:
- the total size of the unidimensional counter.
-
getSizes
public int[] getSizes()
Get the number of multidimensional counter slots in each dimension.- Returns:
- the sizes of the multidimensional counter in each dimension.
-
-