ucar.ma2
Class ArrayChar

java.lang.Object
  extended by ucar.ma2.Array
      extended by ucar.ma2.ArrayChar
Direct Known Subclasses:
ArrayChar.D0, ArrayChar.D1, ArrayChar.D2, ArrayChar.D3, ArrayChar.D4, ArrayChar.D5, ArrayChar.D6, ArrayChar.D7

public class ArrayChar
extends Array

Concrete implementation of Array specialized for chars. Data storage is with 1D java array of chars.

issues: what should we do if a conversion loses accuracy? nothing ? Exception ?

Author:
caron
See Also:
Array

Nested Class Summary
static class ArrayChar.D0
          Concrete implementation of Array specialized for char, rank 0.
static class ArrayChar.D1
          Concrete implementation of Array specialized for char, rank 1.
static class ArrayChar.D2
          Concrete implementation of Array specialized for char, rank 2.
static class ArrayChar.D3
          Concrete implementation of Array specialized for char, rank 3.
static class ArrayChar.D4
          Concrete implementation of Array specialized for char, rank 4.
static class ArrayChar.D5
          Concrete implementation of Array specialized for char, rank 5.
static class ArrayChar.D6
          Concrete implementation of Array specialized for char, rank 6.
static class ArrayChar.D7
          Concrete implementation of Array specialized for char, rank 7.
 class ArrayChar.StringIterator
          rank must be > 0
 
Field Summary
protected  char[] storage
           
 
Fields inherited from class ucar.ma2.Array
indexCalc, rank, unsigned
 
Constructor Summary
ArrayChar(int[] dimensions)
          Create a new Array of type char and the given shape.
ArrayChar(String s)
           
 
Method Summary
 char get(Index i)
          get the value at the specified index.
 boolean getBoolean(Index i)
          not legal, throw ForbiddenConversionException
 boolean getBoolean(int index)
           
 byte getByte(Index i)
          Get the array element at the current element of ima, as a byte.
 byte getByte(int index)
           
 char getChar(Index i)
          Get the array element at the current element of ima, as a char.
 char getChar(int index)
           
 ByteBuffer getDataAsByteBuffer()
          Trasfer data to a ByteBuffer.
 double getDouble(Index i)
          Get the array element at the current element of ima, as a double.
 double getDouble(int index)
           
 Class getElementType()
          Return the element class type
 float getFloat(Index i)
          Get the array element at the current element of ima, as a float.
 float getFloat(int index)
           
 int getInt(Index i)
          Get the array element at the current element of ima, as a int.
 int getInt(int index)
           
 long getLong(Index i)
          Get the array element at the current element of ima, as a long.
 long getLong(int index)
           
 Object getObject(Index i)
          Get the array element at index as an Object.
 Object getObject(int index)
           
 short getShort(Index i)
          Get the array element at the current element of ima, as a short.
 short getShort(int index)
           
 Object getStorage()
          Get underlying primitive array storage.
 String getString()
          Create a String out of this rank one ArrayChar object.
 String getString(Index ima)
          Create a String out of this ArrayChar object.
 String getString(int index)
          Create a String out of this rank two ArrayChar object.
 ArrayChar.StringIterator getStringIterator()
          Treat this Variable as an array of Strings, and iterate over all the strings in the array.
 ArrayObject make1DStringArray()
          Make this into the equivilent 1D ArrayObject of Strings.
static ArrayChar makeFromString(String s, int max)
          Create an ArrayChar from a String
static ArrayChar makeFromStringArray(ArrayObject values)
          Create an ArrayChar from an ArrayObject of Strings.
static ArrayChar makeFromStringArray(ArrayObject values, int strlen)
          Create an ArrayChar from an ArrayObject of Strings.
 void set(Index i, char value)
          set the value at the sepcified index.
 void setBoolean(Index i, boolean value)
          not legal, throw ForbiddenConversionException
 void setBoolean(int index, boolean value)
           
 void setByte(Index i, byte value)
          Set the array element at the current element of ima.
 void setByte(int index, byte value)
           
 void setChar(Index i, char value)
          Set the array element at the current element of ima.
 void setChar(int index, char value)
           
 void setDouble(Index i, double value)
          Set the array element at the current element of ima.
 void setDouble(int index, double value)
           
 void setFloat(Index i, float value)
          Set the array element at the current element of ima.
 void setFloat(int index, float value)
           
 void setInt(Index i, int value)
          Set the array element at the current element of ima.
 void setInt(int index, int value)
           
 void setLong(Index i, long value)
          Set the array element at the current element of ima.
 void setLong(int index, long value)
           
 void setObject(Index i, Object value)
          Set the array element at index to the specified value.
 void setObject(int index, Object value)
           
 void setShort(Index i, short value)
          Set the array element at the current element of ima.
 void setShort(int index, short value)
           
 void setString(Index ima, String val)
          Set the ArrayChar values from the characters in the String.
 void setString(int index, String val)
          Set the ArrayChar values from the characters in the String.
 void setString(String val)
          Set the ArrayChar values from the characters in the String.
 String toString()
           
 
Methods inherited from class ucar.ma2.Array
arraycopy, copy, copyTo1DJavaArray, copyToNDJavaArray, factory, factory, factory, factory, factory, factory, factoryConstant, flip, get1DJavaArray, getIndex, getIndexIterator, getIndexIteratorFast, getIndexPrivate, getRangeIterator, getRank, getShape, getSize, getSizeBytes, hasNext, isConstant, isUnsigned, makeArray, makeArray, makeArray, next, nextBoolean, nextByte, nextChar, nextDouble, nextFloat, nextInt, nextLong, nextShort, permute, reduce, reduce, resetLocalIterator, reshape, reshapeNoCopy, section, section, section, sectionNoReduce, sectionNoReduce, setUnsigned, shapeToString, slice, transpose
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

storage

protected char[] storage
Constructor Detail

ArrayChar

public ArrayChar(int[] dimensions)
Create a new Array of type char and the given shape. dimensions.length determines the rank of the new Array.

Parameters:
dimensions - the shape of the Array.

ArrayChar

public ArrayChar(String s)
Method Detail

getStorage

public Object getStorage()
Description copied from class: Array
Get underlying primitive array storage. Exposed for efficiency, use at your own risk.

Specified by:
getStorage in class Array
Returns:
underlying primitive array storage

getDataAsByteBuffer

public ByteBuffer getDataAsByteBuffer()
Trasfer data to a ByteBuffer. Note we cast char to byte, discarding top byte, if any. This is because CDM char is really a byte, not a java char.

Overrides:
getDataAsByteBuffer in class Array
Returns:
data in a ByteBuffer

getElementType

public Class getElementType()
Return the element class type

Specified by:
getElementType in class Array
Returns:
the class of the element

get

public char get(Index i)
get the value at the specified index.


set

public void set(Index i,
                char value)
set the value at the sepcified index.


getDouble

public double getDouble(Index i)
Description copied from class: Array
Get the array element at the current element of ima, as a double.

Specified by:
getDouble in class Array
Parameters:
i - Index with current element set
Returns:
value at index cast to double if necessary.

setDouble

public void setDouble(Index i,
                      double value)
Description copied from class: Array
Set the array element at the current element of ima.

Specified by:
setDouble in class Array
Parameters:
i - Index with current element set
value - the new value; cast to underlying data type if necessary.

getFloat

public float getFloat(Index i)
Description copied from class: Array
Get the array element at the current element of ima, as a float.

Specified by:
getFloat in class Array
Parameters:
i - Index with current element set
Returns:
value at index cast to float if necessary.

setFloat

public void setFloat(Index i,
                     float value)
Description copied from class: Array
Set the array element at the current element of ima.

Specified by:
setFloat in class Array
Parameters:
i - Index with current element set
value - the new value; cast to underlying data type if necessary.

getLong

public long getLong(Index i)
Description copied from class: Array
Get the array element at the current element of ima, as a long.

Specified by:
getLong in class Array
Parameters:
i - Index with current element set
Returns:
value at index cast to long if necessary.

setLong

public void setLong(Index i,
                    long value)
Description copied from class: Array
Set the array element at the current element of ima.

Specified by:
setLong in class Array
Parameters:
i - Index with current element set
value - the new value; cast to underlying data type if necessary.

getInt

public int getInt(Index i)
Description copied from class: Array
Get the array element at the current element of ima, as a int.

Specified by:
getInt in class Array
Parameters:
i - Index with current element set
Returns:
value at index cast to int if necessary.

setInt

public void setInt(Index i,
                   int value)
Description copied from class: Array
Set the array element at the current element of ima.

Specified by:
setInt in class Array
Parameters:
i - Index with current element set
value - the new value; cast to underlying data type if necessary.

getShort

public short getShort(Index i)
Description copied from class: Array
Get the array element at the current element of ima, as a short.

Specified by:
getShort in class Array
Parameters:
i - Index with current element set
Returns:
value at index cast to short if necessary.

setShort

public void setShort(Index i,
                     short value)
Description copied from class: Array
Set the array element at the current element of ima.

Specified by:
setShort in class Array
Parameters:
i - Index with current element set
value - the new value; cast to underlying data type if necessary.

getByte

public byte getByte(Index i)
Description copied from class: Array
Get the array element at the current element of ima, as a byte.

Specified by:
getByte in class Array
Parameters:
i - Index with current element set
Returns:
value at index cast to float if necessary.

setByte

public void setByte(Index i,
                    byte value)
Description copied from class: Array
Set the array element at the current element of ima.

Specified by:
setByte in class Array
Parameters:
i - Index with current element set
value - the new value; cast to underlying data type if necessary.

getChar

public char getChar(Index i)
Description copied from class: Array
Get the array element at the current element of ima, as a char.

Specified by:
getChar in class Array
Parameters:
i - Index with current element set
Returns:
value at index cast to char if necessary.

setChar

public void setChar(Index i,
                    char value)
Description copied from class: Array
Set the array element at the current element of ima.

Specified by:
setChar in class Array
Parameters:
i - Index with current element set
value - the new value; cast to underlying data type if necessary.

getBoolean

public boolean getBoolean(Index i)
not legal, throw ForbiddenConversionException

Specified by:
getBoolean in class Array
Parameters:
i - Index with current element set
Returns:
value at index cast to boolean if necessary.

setBoolean

public void setBoolean(Index i,
                       boolean value)
not legal, throw ForbiddenConversionException

Specified by:
setBoolean in class Array
Parameters:
i - Index with current element set
value - the new value; cast to underlying data type if necessary.

getObject

public Object getObject(Index i)
Description copied from class: Array
Get the array element at index as an Object. The returned value is wrapped in an object, eg Double for double

Specified by:
getObject in class Array
Parameters:
i - element Index
Returns:
Object value at index

setObject

public void setObject(Index i,
                      Object value)
Description copied from class: Array
Set the array element at index to the specified value. the value must be passed wrapped in the appropriate Object (eg Double for double)

Specified by:
setObject in class Array
Parameters:
i - Index with current element set
value - the new value.

getString

public String getString()
Create a String out of this rank one ArrayChar object. If there is a null (0) value in the ArrayChar array, the String will end there. The null is not returned as part of the String.

Returns:
String value of CharArray
Throws:
IllegalArgumentException - if rank != 1

getString

public String getString(int index)
Create a String out of this rank two ArrayChar object. This treats the ArrayChar as a 1D array of Strings. If there is a null (0) value in the ArrayChar array, the String will end there. The null is not returned as part of the String.

Parameters:
index - index into 1D String array, must be < getShape(0).
Returns:
String value
Throws:
IllegalArgumentException - if rank != 2

getString

public String getString(Index ima)
Create a String out of this ArrayChar object. The rank must be 1 or greater. If there is a null (0) value in the ArrayChar array, the String will end there. The null is not returned as part of the String.

If rank=1, then this will make a string out of the entire CharArray, ignoring ima. If rank is greater than 1, then make a String out of the characters of the last dimension, indexed by ima. This method treats the CharArray like an array of Strings, and allows you to iterate over them, eg for a 2D ArrayChar:

ArrayChar ca; Index ima = ca.getIndex(); for (int i=0; i

Parameters:
ima - the Index of where in the Array to start.
Returns:
String value of CharArray
Throws:
IllegalArgumentException - if rank != 1

setString

public void setString(String val)
Set the ArrayChar values from the characters in the String. Rank must be 1. If String longer than ArrayChar, ignore extra chars; if shorter, fill with 0.

Parameters:
val - set characters from this String
Throws:
IllegalArgumentException - if rank != 2

setString

public void setString(int index,
                      String val)
Set the ArrayChar values from the characters in the String. Rank must be 2. This treats the ArrayChar as a 1D array of Strings. If String val longer than ArrayChar, ignore extra chars; if shorter, fill with 0.

String[] val = new String[n]; ArrayChar ca; Index ima = ca.getIndex(); for (int i=0; i

Parameters:
index - index into 1D String array, must be < getShape(0).
val - set chars from this sString

setString

public void setString(Index ima,
                      String val)
Set the ArrayChar values from the characters in the String. Rank must be 1 or greater. If String longer than ArrayChar, ignore extra chars; if shorter, fill with 0. If rank 1, set entire ArrayChar, ignoring ima. If rank > 1, treat the ArrayChar like an array of Strings of rank-1, and set the row indexed by ima. For example, rank 3:

String[][] val; ArrayChar ca; Index ima = ca.getIndex(); int rank0 = ca.getShape()[0]; int rank1 = ca.getShape()[1];

for (int i=0; i

Parameters:
ima - the Index of where in the Array to start.
val - set to this value

getDouble

public double getDouble(int index)
Specified by:
getDouble in class Array

setDouble

public void setDouble(int index,
                      double value)
Specified by:
setDouble in class Array

getFloat

public float getFloat(int index)
Specified by:
getFloat in class Array

setFloat

public void setFloat(int index,
                     float value)
Specified by:
setFloat in class Array

getLong

public long getLong(int index)
Specified by:
getLong in class Array

setLong

public void setLong(int index,
                    long value)
Specified by:
setLong in class Array

getInt

public int getInt(int index)
Specified by:
getInt in class Array

setInt

public void setInt(int index,
                   int value)
Specified by:
setInt in class Array

getShort

public short getShort(int index)
Specified by:
getShort in class Array

setShort

public void setShort(int index,
                     short value)
Specified by:
setShort in class Array

getByte

public byte getByte(int index)
Specified by:
getByte in class Array

setByte

public void setByte(int index,
                    byte value)
Specified by:
setByte in class Array

getChar

public char getChar(int index)
Specified by:
getChar in class Array

setChar

public void setChar(int index,
                    char value)
Specified by:
setChar in class Array

getBoolean

public boolean getBoolean(int index)
Specified by:
getBoolean in class Array

setBoolean

public void setBoolean(int index,
                       boolean value)
Specified by:
setBoolean in class Array

getObject

public Object getObject(int index)
Specified by:
getObject in class Array

setObject

public void setObject(int index,
                      Object value)
Specified by:
setObject in class Array

toString

public String toString()
Overrides:
toString in class Array

getStringIterator

public ArrayChar.StringIterator getStringIterator()
Treat this Variable as an array of Strings, and iterate over all the strings in the array. If rank == 0, will make single String of length 1.

Returns:
Iterator over Strings.

make1DStringArray

public ArrayObject make1DStringArray()
Make this into the equivilent 1D ArrayObject of Strings.

Returns:
1D ArrayObject of Strings

makeFromString

public static ArrayChar makeFromString(String s,
                                       int max)
Create an ArrayChar from a String

Parameters:
s - String
max - maximum length
Returns:
equivilent ArrayChar

makeFromStringArray

public static ArrayChar makeFromStringArray(ArrayObject values)
Create an ArrayChar from an ArrayObject of Strings.

Parameters:
values - ArrayObject of String
Returns:
equivilent ArrayChar, using maximum length of String. Unused are zero filled.

makeFromStringArray

public static ArrayChar makeFromStringArray(ArrayObject values,
                                            int strlen)
Create an ArrayChar from an ArrayObject of Strings. Inverse of make1DStringArray. Copies the data.

Parameters:
values - ArrayObject of String
strlen - string length dimension size
Returns:
equivilent ArrayChar. Unused are zero filled.


Copyright © 1999-2011 UCAR/Unidata. All Rights Reserved.