ucar.ma2
Class Index

java.lang.Object
  extended by ucar.ma2.Index
All Implemented Interfaces:
java.lang.Cloneable
Direct Known Subclasses:
Index0D, Index1D, Index2D, Index3D, Index4D, Index5D, Index6D, Index7D, IndexConstant

public class Index
extends java.lang.Object
implements java.lang.Cloneable

Indexes for Multidimensional arrays. This refers to a particular element of an array. This is a generalization of index as int []. Its main function is to do the index arithmetic to translate an n-dim index into a 1-dim index. The user obtains this by calling getIndex() on a Array. The set() and seti() routines are convenience routines for 1-7 dim arrays.

Version:
$Revision:51 $ $Date:2006-07-12 17:13:13Z $
Author:
caron
See Also:
Array

Method Summary
 java.lang.Object clone()
           
static long computeSize(int[] shape)
          Compute total number of elements in the array.
 int currentElement()
          Get the current element's index into the 1D backing array.
static Index factory(int[] shape)
          Generate a subclass of Index optimized for this array's rank
 int[] getCurrentCounter()
           
 java.lang.String getIndexName(int dim)
          Get the name of one of the indices.
 int getRank()
          Get the number of dimensions in the array.
 int[] getShape()
          Get the shape: length of array in each dimension.
 long getSize()
          Get the total number of elements in the array.
 Index set(int v0)
          set current element at dimension 0 to v0
 Index set(int[] index)
          Set the current element's index.
 Index set(int v0, int v1)
          set current element at dimension 0,1 to v0,v1
 Index set(int v0, int v1, int v2)
          set current element at dimension 0,1,2 to v0,v1,v2
 Index set(int v0, int v1, int v2, int v3)
          set current element at dimension 0,1,2,3 to v0,v1,v2,v3
 Index set(int v0, int v1, int v2, int v3, int v4)
          set current element at dimension 0,1,2,3,4 to v0,v1,v2,v3,v4
 Index set(int v0, int v1, int v2, int v3, int v4, int v5)
          set current element at dimension 0,1,2,3,4,5 to v0,v1,v2,v3,v4,v5
 Index set(int v0, int v1, int v2, int v3, int v4, int v5, int v6)
          set current element at dimension 0,1,2,3,4,5,6 to v0,v1,v2,v3,v4,v5,v6
 Index set0(int v)
          set current element at dimension 0 to v
 Index set1(int v)
          set current element at dimension 1 to v
 Index set2(int v)
          set current element at dimension 2 to v
 Index set3(int v)
          set current element at dimension 3 to v
 Index set4(int v)
          set current element at dimension 4 to v
 Index set5(int v)
          set current element at dimension 5 to v
 Index set6(int v)
          set current element at dimension 6 to v
 void setDim(int dim, int value)
          set current element at dimension dim to v
 void setIndexName(int dim, java.lang.String indexName)
          Set the name of one of the indices.
 java.lang.String toString()
           
 java.lang.String toStringDebug()
          String representation
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

getRank

public int getRank()
Get the number of dimensions in the array.


getShape

public int[] getShape()
Get the shape: length of array in each dimension.


getSize

public long getSize()
Get the total number of elements in the array.


currentElement

public int currentElement()
Get the current element's index into the 1D backing array.


set

public Index set(int[] index)
Set the current element's index. General-rank case.

Returns:
this, so you can use A.get(i.set(i))
Throws:
java.lang.ArrayIndexOutOfBoundsException - if index.length != rank.

setDim

public void setDim(int dim,
                   int value)
set current element at dimension dim to v


set0

public Index set0(int v)
set current element at dimension 0 to v

Returns:
this, so you can use A.get(i.set(i))

set1

public Index set1(int v)
set current element at dimension 1 to v

Returns:
this, so you can use A.get(i.set(i))

set2

public Index set2(int v)
set current element at dimension 2 to v

Returns:
this, so you can use A.get(i.set(i))

set3

public Index set3(int v)
set current element at dimension 3 to v

Returns:
this, so you can use A.get(i.set(i))

set4

public Index set4(int v)
set current element at dimension 4 to v

Returns:
this, so you can use A.get(i.set(i))

set5

public Index set5(int v)
set current element at dimension 5 to v

Returns:
this, so you can use A.get(i.set(i))

set6

public Index set6(int v)
set current element at dimension 6 to v

Returns:
this, so you can use A.get(i.set(i))

set

public Index set(int v0)
set current element at dimension 0 to v0

Returns:
this, so you can use A.get(i.set(i))

set

public Index set(int v0,
                 int v1)
set current element at dimension 0,1 to v0,v1

Returns:
this, so you can use A.get(i.set(i,j))

set

public Index set(int v0,
                 int v1,
                 int v2)
set current element at dimension 0,1,2 to v0,v1,v2

Returns:
this, so you can use A.get(i.set(i,j,k))

set

public Index set(int v0,
                 int v1,
                 int v2,
                 int v3)
set current element at dimension 0,1,2,3 to v0,v1,v2,v3

Returns:
this, so you can use A.get(i.set(i,j,k,l))

set

public Index set(int v0,
                 int v1,
                 int v2,
                 int v3,
                 int v4)
set current element at dimension 0,1,2,3,4 to v0,v1,v2,v3,v4

Returns:
this, so you can use A.get(i.set(i,j,k,l,m))

set

public Index set(int v0,
                 int v1,
                 int v2,
                 int v3,
                 int v4,
                 int v5)
set current element at dimension 0,1,2,3,4,5 to v0,v1,v2,v3,v4,v5

Returns:
this, so you can use A.get(i.set(i,j,k,l,m,n))

set

public Index set(int v0,
                 int v1,
                 int v2,
                 int v3,
                 int v4,
                 int v5,
                 int v6)
set current element at dimension 0,1,2,3,4,5,6 to v0,v1,v2,v3,v4,v5,v6

Returns:
this, so you can use A.get(i.set(i,j,k,l,m,n,p))

toStringDebug

public java.lang.String toStringDebug()
String representation


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

getCurrentCounter

public int[] getCurrentCounter()

clone

public java.lang.Object clone()
Overrides:
clone in class java.lang.Object

setIndexName

public void setIndexName(int dim,
                         java.lang.String indexName)
Set the name of one of the indices.

Parameters:
dim - which index?
indexName - name of index

getIndexName

public java.lang.String getIndexName(int dim)
Get the name of one of the indices.

Parameters:
dim - which index?
Returns:
name of index, or null if none.

factory

public static Index factory(int[] shape)
Generate a subclass of Index optimized for this array's rank


computeSize

public static long computeSize(int[] shape)
Compute total number of elements in the array.

Parameters:
shape - length of array in each dimension.