## ucar.multiarray
Class IndexIterator

    java.lang.Object
      ucar.multiarray.IndexIterator

Direct Known Subclasses:
  OffsetDualIndexIterator, OffsetIndexIterator

public class IndexIterator
extends Object

An IndexIterator is a helper class used for stepping through the index values of a MultiArray.

This is like an odometer. The number of columns or rings on the odometer is the length of the constructor argument. The number of values on each ring of the odometer is specified in the limits argument of the constructor.

Currently no synchronized methods.

See Also:
  `MultiArray`

Field Summary
`protected int[]` `counter` The counter value.
`protected int[]` `limits` (Reference to) the constructor argument which determines counter value variation.
`protected int` `ncycles` A "carry" indicator, the number of times the counter value has rolled over.

Constructor Summary
`IndexIterator(int[] theLimits)` Creates a new IndexIterator whose variation is bounded by the component values of the argument.
`IndexIterator(int[] initCounter, int[] theLimits)` Creates a new IndexIterator with initial counter value, whose variation is bounded by the component values of the `limits` argument.

Method Summary
`void` `advance(int nsteps)` Increment the counter value
`static boolean` `equals(int[] lhs, int[] rhs)` Return `true` iff the arguments have same values.
`void` `incr()` Increment the counter value
`static boolean` `isZero(int[] iv)` Return `true` iff the argument is the zero index.
`static void` `main(String[] args)` Test
`boolean` `notDone()` If the IndexIterator has not yet "rolled over", return `true`.
`String` `toString()`
`int[]` `value()` Return the current counter value.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Field Detail

### counter

    protected final int[] counter

  The counter value. Initialized to zero. The length is the same as limits.length.

### limits

    protected final int[] limits

  (Reference to) the constructor argument which determines counter value variation. `for 0 <= ii < limits.length, counter[ii] < limits[ii]`

### ncycles

    protected int ncycles

  A "carry" indicator, the number of times the counter value has rolled over.

Constructor Detail

### IndexIterator

    public IndexIterator(int[] theLimits)

  Creates a new IndexIterator whose variation is bounded by the component values of the argument.

Parameters:
  `theLimits` - typically `ma.getLengths()` for some MultiArray `ma`

### IndexIterator

    public IndexIterator(int[] initCounter,
                         int[] theLimits)

  Creates a new IndexIterator with initial counter value, whose variation is bounded by the component values of the `limits` argument.

Parameters:
  `initCounter` - the initial value.
  `theLimits` - typically `ma.getLengths()` for some MultiArray `ma`

Method Detail

### isZero

    public static boolean isZero(int[] iv)

  Return `true` iff the argument is the zero index.

### equals

    public static boolean equals(int[] lhs,
                                 int[] rhs)

  Return `true` iff the arguments have same values.

### notDone

    public boolean notDone()

  If the IndexIterator has not yet "rolled over", return `true`. Useful for loop end detection.

### value

    public int[] value()

  Return the current counter value. N.B. Not a copy!

### incr

    public void incr()

  Increment the counter value

### advance

    public void advance(int nsteps)

  Increment the counter value

  Parameters:
    `nsteps` - the number of times to increment the value.

### toString

    public String toString()

### main

    public static void main(String[] args)

  Test