public class MWCharArray extends MWArray
MWCharArray class manages a native MATLAB char array.EMPTY_ARRAY| Constructor and Description |
|---|
MWCharArray()
Creates an Empty char array.
|
MWCharArray(char val)
Constructs a new char array that represents the primitive char argument.
|
MWCharArray(java.lang.Object val)
Constructs a char array that represents the Object argument.
|
| Modifier and Type | Method and Description |
|---|---|
<T> T |
applyVisitor(AbstractMWArrayVisitor<T> v) |
MWClassID |
classID()
Returns the MATLAB type of this array.
|
java.lang.Object |
clone()
Creates and returns a deep copy of this array.
|
int[] |
columnIndex()
Returns an array containing the column index of each element in the underlying MATLAB array.
|
int |
compareTo(java.lang.Object obj)
Compares this array with the specified array for order.
|
static MWArray |
deserialize(byte[] data)
Create a new MWArray from serialized data.
|
void |
dispose()
Frees the native MATLAB array contained by this array.
|
boolean |
equals(java.lang.Object obj)
Indicates whether some other array is equal to this one.
|
java.lang.Object |
get(int index)
Returns the element at the specified 1-based offset in this array.
|
java.lang.Object |
get(int[] index)
Returns the element at the specified 1-based index-array in this array.
|
char |
getChar(int index)
Returns the character at the specified 1-based offset.
|
char |
getChar(int[] index)
Returns the character at the specified 1-based index-array.
|
java.lang.Object |
getData()
Returns a 1-D array containing a copy of the data in the underlying MATLAB array.
|
int[] |
getDimensions()
Returns an array containing the size of each dimension of this array.
|
int |
hashCode()
Returns a hash code value for this array.
|
boolean |
isEmpty()
Tests if this array has no elements.
|
boolean |
isSparse()
Tests if this array is sparse.
|
int |
maximumNonZeros()
Returns the allocated capacity of a sparse array.
|
static MWCharArray |
newInstance(int[] dims)
Constructs a char array with the specified dimensions.
|
static MWCharArray |
newInstance(int[] dims,
java.lang.Object data)
Constructs a char array with the specified dimensions and initializes the array with the supplied data.
|
int |
numberOfDimensions()
Returns the number of dimensions of this array.
|
int |
numberOfElements()
Returns the total number of elements in this array.
|
int |
numberOfNonZeros()
Returns the number of non-zero elements in a sparse array.
|
protected java.lang.Object |
readResolve()
Called by serialization mechanism when loading a new array from a byte stream.
|
int[] |
rowIndex()
Returns an array containing the row index of each element in the underlying MATLAB array.
|
byte[] |
serialize()
Serialize the MATLAB array to a byte array.
|
void |
set(int[] index,
char element)
Replaces the character at the specified 1-based index-array in this array with the specified char value.
|
void |
set(int[] index,
java.lang.Object element)
Replaces the element at the specified 1-based index-array in this array with the specified element.
|
void |
set(int index,
char element)
Replaces the character at the specified 1-based offset in this array with the specified char value.
|
void |
set(int index,
java.lang.Object element)
Replaces the element at the specified 1-based offset in this array with the specified element.
|
void |
setData(java.lang.Object data) |
java.lang.Object |
sharedCopy()
Creates and returns a shared copy of this array.
|
java.lang.Object[] |
toArray()
Returns an array containing a copy of the data in the underlying MATLAB array.
|
java.lang.String |
toString()
Returns a string representation of this array.
|
protected void |
validate()
Validates the internal array handle.
|
disposeArraypublic MWCharArray()
public MWCharArray(char val)
val - The value to initialize the array with.
char[] chArray1 = {'H', 'e', 'l', 'l', 'o'};
char[] chArray2 = {'W', 'o', 'r', 'l', 'd'};
MWCharArray A = new MWCharArray(chArray1);
System.out.println("The string in MWCharArray1 is \"" + A + "\"");
When run, the example displays this output:
The string in MWCharArray1 is "Hello"
public MWCharArray(java.lang.Object val)
val - The value to initialize the array with.java.lang.ArrayStoreException - A non-character or non-String array type was specified.
String str = new String(chArray2);
MWCharArray A2 = new MWCharArray(str);
System.out.println("The string in MWCharArray2 is \"" +
A2 + "\"");
When run, the example displays this output:
The string in MWCharArray2 is "World"
public java.lang.Object clone()
throws java.lang.CloneNotSupportedException
MWCharArray instance representing a deep copy of the
underlying MATLAB array.
Create a clone of MWCharArray object A as follows:char[] chArray = {'H', 'e', 'l', 'l', 'o'}; MWCharArray A = new MWCharArray(chArray); Object C = A.clone(); System.out.println("Clone of matrix A is:"); System.out.println(C.toString());When run, the example displays this output:Clone of matrix A is: Hello
java.lang.CloneNotSupportedException - - The object's class does not implement the Cloneable interface.public java.lang.Object sharedCopy()
MWCharArray instance representing a shared copy of the
underlying MATLAB array.
char[] chArray = {'H', 'e', 'l', 'l', 'o'};
MWCharArray A = new MWCharArray(chArray);
Object S = A.sharedCopy();
System.out.print("Shared copy of matrix A is \"" +
S.toString() + "\"");
When run, the example displays this output:
Shared copy of matrix A is "Hello"
public void set(int index,
char element)
index - The index of the element to replace. Valid range: 1 <= index <= N, where N = total number of elements in the array.element - New value to replace at index.java.lang.IndexOutOfBoundsException - An invalid index has been supplied.public void set(int[] index,
char element)
index - Array of indices specifying the location of the element to replace.
The length of the index array must be exactly the number of dimensions of this array.
Each element of the index array has the valid range: 1 <= index[i] <= N[i], where N[i] = the size of the ith dimension.element - New value to replace at index.java.lang.IndexOutOfBoundsException - An invalid index has been supplied.
char[] chArray = {'G', 'a', 'r', 'y'};
MWCharArray A = new MWCharArray(chArray);
System.out.println(" I think " + A + " lives here." + "\n");
System.out.println("Changing the first character to M ...\n");
int[] index = {1, 1};
A.set(index, 'M');
System.out.println(" I think " + A + " lives here." + "\n");
When run, the example above displays this output:
I think Gary lives here.
Changing the first character to M yields the following output:
I think Mary lives here.
public char getChar(int index)
index - The index of the requested element. Valid range: 1 <= index <= N, where N = total number of elements in the array.java.lang.IndexOutOfBoundsException - An invalid index has been supplied.public char getChar(int[] index)
index - Array of indices specifying the location of the requested element.
The length of the index array must be exactly the number of dimensions of this array.
Each element of the index array has the valid range: 1 <= index[i] <= N[i], where N[i] = the size of the ith dimension.java.lang.IndexOutOfBoundsException - An invalid index has been supplied.
char[] chArray = {'H', 'e', 'l', 'l', 'o'};
MWCharArray A = new MWCharArray(chArray);
for (int i = 1; i <= 5; i++)
System.out.print(A.getChar(i));
When run, the example displays this output:
Hello
public MWClassID classID()
MWClassID.CHAR for MWCharArray.
char[] chArray1 = {'H', 'e', 'l', 'l', 'o'};
MWCharArray A = new MWCharArray(chArray1);
System.out.println("The class of A is " + A.classID());
When run, the example displays this output:
The class of A is char
public <T> T applyVisitor(AbstractMWArrayVisitor<T> v)
protected void validate()
public static MWCharArray newInstance(int[] dims)
dims - Array of dimension sizes. Each dimension size must be non-negative.MWCharArray with the specified dimensions.java.lang.NegativeArraySizeException - A negative dimension size is supplied.
int[] dims = {1, 5};
char[] chArray = {'H', 'e', 'l', 'l', 'o'};
String str = new String(chArray);
MWCharArray A =
MWCharArray.newInstance(dims, str);
System.out.println("The array string is \"" + A + "\"");
When run, the example displays this output:
The array string is "Hello"
public static MWCharArray newInstance(int[] dims, java.lang.Object data)
dims - Array of dimension sizes. Each dimension size must be non-negative.data - Data to initialize the array with.MWCharArray with the specified dimensions and initialized with the supplied data.java.lang.NegativeArraySizeException - A negative dimension size is supplied.java.lang.ArrayStoreException - Non-character data has been supplied.public byte[] serialize()
public static MWArray deserialize(byte[] data)
data - serialized array returned from MWArray.serializepublic int numberOfDimensions()
numberOfDimensions in class MWArraypublic int[] getDimensions()
getDimensions in class MWArraypublic boolean isEmpty()
public boolean isSparse()
public boolean equals(java.lang.Object obj)
public int compareTo(java.lang.Object obj)
public int hashCode()
public java.lang.String toString()
public int numberOfElements()
numberOfElements in class MWArraypublic int numberOfNonZeros()
numberOfElements().numberOfNonZeros in class MWArraypublic int maximumNonZeros()
numberOfElements().maximumNonZeros in class MWArraypublic void dispose()
dispose in interface Disposabledispose in class MWArraypublic java.lang.Object get(int index)
public java.lang.Object get(int[] index)
get in class MWArrayindex - Array of indices specifying the location of the requested element.
The length of the index array must be exactly the number of dimensions of this array.
Each element of the index array has the valid range: 1 <= index[i] <= N[i], where N[i] = the size of the ith dimension.java.lang.IndexOutOfBoundsException - An invalid index has been supplied.public void set(int index,
java.lang.Object element)
public void set(int[] index,
java.lang.Object element)
set in class MWArrayindex - Array of indices specifying the location of the element to replace.
The length of the index array must be exactly the number of dimensions of this array.
Each element of the index array has the valid range: 1 <= index[i] <= N[i], where N[i] = the size of the ith dimension.element - New element to replace at index.java.lang.IndexOutOfBoundsException - An invalid index has been supplied.public java.lang.Object[] toArray()
toArray
returns the real part. If the underlying array is sparse, a full representation of
the array is returned. Care should be taken when calling toArray on a
sparse array with large row and column dimensions, as this action may exhaust system
memory. If the underlying array is a cell or struct array, toArray is
recursively called on each cell.public java.lang.Object getData()
getData returns
the real part. If the underlying array is a cell or struct array, toArray is
recursively called on each cell.getData in class MWArraynumberOfElements() for a non-sparse array, and numberOfNonZeros()
for a sparse array.public int[] rowIndex()
public int[] columnIndex()
columnIndex in class MWArrayprotected java.lang.Object readResolve()
throws java.io.ObjectStreamException
java.io.InvalidObjectException - Attempt to load an invalid array handle.java.io.ObjectStreamException© 1994-2008 The MathWorks, Inc. Terms of Use Patents Trademarks