MultidimensionalCounter implements Iterable<Integer> { public int getCount(int ... c) throws OutOfRangeException, DimensionMismatchException { if (c.length != dimension) { throw new DimensionMismatchException(c.length, dimension); } int count = 0; for (int i = 0; i < dimension; i++) { final int index = c[i]; if (index < 0 || index >= size[i]) { throw new OutOfRangeException(index, 0, size[i] - 1); } count += uniCounterOffset[i] * c[i]; } return count + c[last]; } MultidimensionalCounter(int ... size); Iterator iterator(); int getDimension(); int[] getCounts(int index); int getCount(int ... c); int getSize(); int[] getSizes(); @Override String toString();  }
@Test public void testMulti2UniConversion() { final MultidimensionalCounter c = new MultidimensionalCounter(2, 4, 5); Assert.assertEquals(c.getCount(1, 2, 3), 33); }