Package ucar.ma2
Class ArrayChar
java.lang.Object
ucar.ma2.Array
ucar.ma2.ArrayChar
- Direct Known Subclasses:
ArrayChar.D0,ArrayChar.D1,ArrayChar.D2,ArrayChar.D3,ArrayChar.D4,ArrayChar.D5,ArrayChar.D6,ArrayChar.D7
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 ?
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classConcrete implementation of Array specialized for char, rank 0.static classConcrete implementation of Array specialized for char, rank 1.static classConcrete implementation of Array specialized for char, rank 2.static classConcrete implementation of Array specialized for char, rank 3.static classConcrete implementation of Array specialized for char, rank 4.static classConcrete implementation of Array specialized for char, rank 5.static classConcrete implementation of Array specialized for char, rank 6.static classConcrete implementation of Array specialized for char, rank 7.classrank must be > 0 -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncharget the value at the specified index.booleangetBoolean(int index) booleangetBoolean(Index i) not legal, throw ForbiddenConversionExceptionbytegetByte(int index) byteGet the array element at the current element of ima, as a byte.chargetChar(int index) charGet the array element at the current element of ima, as a char.Trasfer data to a ByteBuffer.doublegetDouble(int index) doubleGet the array element at the current element of ima, as a double.Return the element class typefloatgetFloat(int index) floatGet the array element at the current element of ima, as a float.intgetInt(int index) intGet the array element at the current element of ima, as a int.longgetLong(int index) longGet the array element at the current element of ima, as a long.getObject(int index) Get the array element at index as an Object.shortgetShort(int index) shortGet the array element at the current element of ima, as a short.Get underlying primitive array storage.Create a String out of this rank one ArrayChar object.getString(int index) Create a String out of this rank two ArrayChar object.Create a String out of this ArrayChar object.Treat this Variable as an array of Strings, and iterate over all the strings in the array.iterator()Make this into the equivilent 1D ArrayObject of Strings.static ArrayCharmakeFromString(String s, int max) Create an ArrayChar from a Stringstatic ArrayCharmakeFromStringArray(ArrayObject values) Create an ArrayChar from an ArrayObject of Strings.static ArrayCharmakeFromStringArray(ArrayObject values, int strlen) Create an ArrayChar from an ArrayObject of Strings.voidset the value at the sepcified index.voidsetBoolean(int index, boolean value) voidsetBoolean(Index i, boolean value) not legal, throw ForbiddenConversionExceptionvoidsetByte(int index, byte value) voidSet the array element at the current element of ima.voidsetChar(int index, char value) voidSet the array element at the current element of ima.voidsetDouble(int index, double value) voidSet the array element at the current element of ima.voidsetFloat(int index, float value) voidSet the array element at the current element of ima.voidsetInt(int index, int value) voidSet the array element at the current element of ima.voidsetLong(int index, long value) voidSet the array element at the current element of ima.voidvoidSet the array element at index to the specified value.voidsetShort(int index, short value) voidSet the array element at the current element of ima.voidSet the ArrayChar values from the characters in the String.voidSet the ArrayChar values from the characters in the String.voidSet the ArrayChar values from the characters in the String.toString()Methods inherited from class ucar.ma2.Array
arraycopy, copy, copyTo1DJavaArray, copyToNDJavaArray, factory, factory, factory, factory, factoryConstant, factoryCopy, flip, get1DJavaArray, get1DJavaArray, getDataAsByteBuffer, getDataAsByteBuffer, getDataType, getIndex, getIndexIterator, getRangeIterator, getRank, getShape, getSize, getSizeBytes, hasNext, isConstant, isUnsigned, isVlen, makeArray, makeArray, makeArray, makeArrayRankPlusOne, makeFromJavaArray, makeFromJavaArray, makeObjectArray, makeVlenArray, next, nextBoolean, nextByte, nextChar, nextDouble, nextFloat, nextInt, nextLong, nextShort, permute, reduce, reduce, resetLocalIterator, reshape, reshapeNoCopy, section, section, section, sectionNoReduce, sectionNoReduce, shapeToString, slice, transposeMethods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
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
-
-
Method Details
-
getStorage
Description copied from class:ArrayGet underlying primitive array storage. Exposed for efficiency, use at your own risk.- Specified by:
getStoragein classArray- Returns:
- underlying primitive array storage
-
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:
getDataAsByteBufferin classArray- Returns:
- data in a ByteBuffer
-
getElementType
Return the element class type- Specified by:
getElementTypein classArray- Returns:
- the class of the element
-
get
get the value at the specified index. -
set
set the value at the sepcified index. -
getDouble
Description copied from class:ArrayGet the array element at the current element of ima, as a double. -
setDouble
Description copied from class:ArraySet the array element at the current element of ima. -
getFloat
Description copied from class:ArrayGet the array element at the current element of ima, as a float. -
setFloat
Description copied from class:ArraySet the array element at the current element of ima. -
getLong
Description copied from class:ArrayGet the array element at the current element of ima, as a long. -
setLong
Description copied from class:ArraySet the array element at the current element of ima. -
getInt
Description copied from class:ArrayGet the array element at the current element of ima, as a int. -
setInt
Description copied from class:ArraySet the array element at the current element of ima. -
getShort
Description copied from class:ArrayGet the array element at the current element of ima, as a short. -
setShort
Description copied from class:ArraySet the array element at the current element of ima. -
getByte
Description copied from class:ArrayGet the array element at the current element of ima, as a byte. -
setByte
Description copied from class:ArraySet the array element at the current element of ima. -
getChar
Description copied from class:ArrayGet the array element at the current element of ima, as a char. -
setChar
Description copied from class:ArraySet the array element at the current element of ima. -
getBoolean
not legal, throw ForbiddenConversionException- Specified by:
getBooleanin classArray- Parameters:
i- Index with current element set- Returns:
- value at
indexcast to boolean if necessary.
-
setBoolean
not legal, throw ForbiddenConversionException- Specified by:
setBooleanin classArray- Parameters:
i- Index with current element setvalue- the new value; cast to underlying data type if necessary.
-
getObject
Description copied from class:ArrayGet the array element at index as an Object. The returned value is wrapped in an object, eg Double for double -
setObject
Description copied from class:ArraySet the array element at index to the specified value. the value must be passed wrapped in the appropriate Object (eg Double for double) -
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
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
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<ca.getShape()[0]; i++) String s = ca.getString(ima.set0(i));- Parameters:
ima- the Index of where in the Array to start.- Returns:
- String value of CharArray
- Throws:
IllegalArgumentException- if rank != 1
-
setString
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
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<n; i++) ca.setString(i, val[i]);- Parameters:
index- index into 1D String array, must be < getShape(0).val- set chars from this sString
-
setString
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<rank0; i++) for (int j=0; j<rank1; j++) { ima.set(i,j); ca.setString(ima, val[i][j]); }- Parameters:
ima- the Index of where in the Array to start.val- set to this value
-
getDouble
public double getDouble(int index) -
setDouble
public void setDouble(int index, double value) -
getFloat
public float getFloat(int index) -
setFloat
public void setFloat(int index, float value) -
getLong
public long getLong(int index) -
setLong
public void setLong(int index, long value) -
getInt
public int getInt(int index) -
setInt
public void setInt(int index, int value) -
getShort
public short getShort(int index) -
setShort
public void setShort(int index, short value) -
getByte
public byte getByte(int index) -
setByte
public void setByte(int index, byte value) -
getChar
public char getChar(int index) -
setChar
public void setChar(int index, char value) -
getBoolean
public boolean getBoolean(int index) - Specified by:
getBooleanin classArray
-
setBoolean
public void setBoolean(int index, boolean value) - Specified by:
setBooleanin classArray
-
getObject
-
setObject
-
toString
-
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.
-
iterator
-
make1DStringArray
Make this into the equivilent 1D ArrayObject of Strings.- Returns:
- 1D ArrayObject of Strings
-
makeFromString
Create an ArrayChar from a String- Parameters:
s- Stringmax- maximum length- Returns:
- equivilent ArrayChar
-
makeFromStringArray
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
Create an ArrayChar from an ArrayObject of Strings. Inverse of make1DStringArray. Copies the data.- Parameters:
values- ArrayObject of Stringstrlen- string length dimension size- Returns:
- equivilent ArrayChar. Unused are zero filled.
-