Top Description Inners Fields Constructors Methods
org.apache.commons.math3.util

public Class MultidimensionalCounter

extends Object
implements Iterable<Integer>
Class Inheritance
All Implemented Interfaces
java.lang.Iterable
Imports
java.util.NoSuchElementException, org.apache.commons.math3.exception.DimensionMismatchException, .NotStrictlyPositiveException, .OutOfRangeException

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:
Since
2.2

Nested and Inner Type Summary

Modifier and TypeClass and Description
public class
MultidimensionalCounter.Iterator

Perform iteration over the multidimensional counter.

Field Summary

Modifier and TypeField and Description
private final int
dimension

Number of dimensions.

private final int
last

Index of last dimension.

private final int[]
size

Counter sizes.

private final int
totalSize

Total number of (one-dimensional) slots.

private final int[]
uniCounterOffset

Offset for each dimension.

Constructor Summary

AccessConstructor and Description
public
MultidimensionalCounter(int...
Counter sizes (number of slots in each dimension).
size
)

Create a counter.

Method Summary

Modifier and TypeMethod and Description
public int

Returns:

the index within the unidimensionl counter.
getCount
(int...
Indices in multidimensional counter.
c
)

Convert to unidimensional counter.

public int[]

Returns:

the multidimensional counts.
getCounts
(int
Index in unidimensional counter.
index
)

Convert to multidimensional counter.

public int

Returns:

the number of dimensions.
getDimension
()

Get the number of dimensions of the multidimensional counter.

public int

Returns:

the total size of the unidimensional counter.
getSize
()

Get the total number of elements.

public int[]

Returns:

the sizes of the multidimensional counter in each dimension.
getSizes
()

Get the number of multidimensional counter slots in each dimension.

public MultidimensionalCounter.Iterator

Returns:

the iterator.
iterator
()

Implements java.lang.Iterable.iterator.

Create an iterator over this counter.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

dimensionback to summary
private final int dimension

Number of dimensions.

lastback to summary
private final int last

Index of last dimension.

sizeback to summary
private final int[] size

Counter sizes.

totalSizeback to summary
private final int totalSize

Total number of (one-dimensional) slots.

uniCounterOffsetback to summary
private final int[] uniCounterOffset

Offset for each dimension.

Constructor Detail

MultidimensionalCounterback to summary
public MultidimensionalCounter(int... size) throws NotStrictlyPositiveException

Create a counter.

Parameters
size:int[]

Counter sizes (number of slots in each dimension).

Exceptions
NotStrictlyPositiveException:
if one of the sizes is negative or zero.

Method Detail

getCountback to summary
public int getCount(int... c) throws OutOfRangeException, DimensionMismatchException

Convert to unidimensional counter.

Parameters
c:int[]

Indices in multidimensional counter.

Returns:int

the index within the unidimensionl counter.

Exceptions
OutOfRangeException:
if a value of c is not in the range of the corresponding dimension, as defined in the constructor.
DimensionMismatchException:
if the size of c does not match the size of the array given in the constructor.
getCountsback to summary
public int[] getCounts(int index) throws OutOfRangeException

Convert to multidimensional counter.

Parameters
index:int

Index in unidimensional counter.

Returns:int[]

the multidimensional counts.

Exceptions
OutOfRangeException:
if index is not between 0 and the value returned by getSize() (excluded).
getDimensionback to summary
public int getDimension()

Get the number of dimensions of the multidimensional counter.

Returns:int

the number of dimensions.

getSizeback to summary
public int getSize()

Get the total number of elements.

Returns:int

the total size of the unidimensional counter.

getSizesback to summary
public int[] getSizes()

Get the number of multidimensional counter slots in each dimension.

Returns:int[]

the sizes of the multidimensional counter in each dimension.

iteratorback to summary
public MultidimensionalCounter.Iterator iterator()

Implements java.lang.Iterable.iterator.

Create an iterator over this counter.

Returns:MultidimensionalCounter.Iterator

the iterator.

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override
org.apache.commons.math3.util back to summary

public Class MultidimensionalCounter.Iterator

extends Object
implements Iterator<Integer>
Class Inheritance
  • java.lang.Object
  • org.apache.commons.math3.util.MultidimensionalCounter.Iterator
All Implemented Interfaces
java.util.Iterator

Perform iteration over the multidimensional counter.

Field Summary

Modifier and TypeField and Description
private int
count

Unidimensional counter.

private final int[]
counter

Multidimensional counter.

private final int
maxCount

Maximum value for count.

Constructor Summary

AccessConstructor and Description
pack-priv
Iterator()

Create an iterator

Method Summary

Modifier and TypeMethod and Description
public int

Returns:

the index within the unidimensionl counter.
getCount
()

Get the current unidimensional counter slot.

public int

Returns:

the count at the corresponding index for the current state of the iterator.
getCount
(int
Dimension index.
dim
)

Get the current count in the selected dimension.

public int[]

Returns:

the indices within the multidimensional counter.
getCounts
()

Get the current multidimensional counter slots.

public boolean
hasNext()

Implements java.util.Iterator.hasNext.

Returns true if the iteration has more elements.

public Integer

Returns:

the unidimensional count after the counter has been incremented by 1.
next
()

Implements java.util.Iterator.next.

Returns the next element in the iteration.

public void
remove()

Overrides default java.util.Iterator.remove.

Removes from the underlying collection the last element returned by this iterator (optional operation).

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

countback to summary
private int count

Unidimensional counter.

counterback to summary
private final int[] counter

Multidimensional counter.

maxCountback to summary
private final int maxCount

Maximum value for count.

Constructor Detail

Iteratorback to summary
pack-priv Iterator()

Create an iterator

See Also
iterator()

Method Detail

getCountback to summary
public int getCount()

Get the current unidimensional counter slot.

Returns:int

the index within the unidimensionl counter.

getCountback to summary
public int getCount(int dim)

Get the current count in the selected dimension.

Parameters
dim:int

Dimension index.

Returns:int

the count at the corresponding index for the current state of the iterator.

Exceptions
IndexOutOfBoundsException:
if index is not in the correct interval (as defined by the length of the argument in the constructor of the enclosing class).
getCountsback to summary
public int[] getCounts()

Get the current multidimensional counter slots.

Returns:int[]

the indices within the multidimensional counter.

hasNextback to summary
public boolean hasNext()

Implements java.util.Iterator.hasNext.

Doc from java.util.Iterator.hasNext.

Returns true if the iteration has more elements. (In other words, returns true if next would return an element rather than throwing an exception.)

Returns:boolean

true if the iteration has more elements

nextback to summary
public Integer next()

Implements java.util.Iterator.next.

Doc from java.util.Iterator.next.

Returns the next element in the iteration.

Returns:Integer

the unidimensional count after the counter has been incremented by 1.

Exceptions
NoSuchElementException:
if hasNext() would have returned false.
removeback to summary
public void remove()

Overrides default java.util.Iterator.remove.

Doc from java.util.Iterator.remove.

Removes from the underlying collection the last element returned by this iterator (optional operation). This method can be called only once per call to next.

The behavior of an iterator is unspecified if the underlying collection is modified while the iteration is in progress in any way other than by calling this method, unless an overriding class has specified a concurrent modification policy.

The behavior of an iterator is unspecified if this method is called after a call to the forEachRemaining method.

Exceptions
UnsupportedOperationException:
if the remove operation is not supported by this iterator