public class MWStringArray extends MWArray
MWStringArray
class manages a native MATLAB string array.EMPTY_ARRAY
Constructor and Description |
---|
MWStringArray()
Creates an empty string array.
|
MWStringArray(int[] dims)
Creates an n-dimentional string array with all elements in default value.
|
MWStringArray(java.lang.String val)
Creates a one-element string array that represents the java string argument.
|
MWStringArray(java.lang.String[] vals)
Creates a string array that represents the java String[] 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 string at the specified 1-based offset.
|
java.lang.Object |
get(int[] indices)
Returns the string at the specified indices .
|
java.lang.Object |
getData()
Returns a 1-D string 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 |
IsMissingElement(int index)
Checks if the element at the specified 1-based offset of this array has the value "missing".
|
boolean |
IsMissingElement(int[] indices)
Checks if the element at the specified indices of this array has the value "missing".
|
boolean |
isSparse()
Tests if this array is sparse.
|
int |
maximumNonZeros()
Returns the allocated capacity of a array.
|
static MWStringArray |
newInstance(int[] dims)
Constructs a string array with the specified dimensions.
|
int |
numberOfDimensions()
Returns the number of dimensions of this array.
|
int |
numberOfElements()
Returns the number of elements of this array.
|
int |
numberOfNonZeros()
Returns the number of non-zero elements in a 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[] indices,
java.lang.Object element)
Replaces the string at the specified indices in this array with the specified string value.
|
void |
set(int index,
java.lang.Object element)
Replaces the string at the specified 1-based offset in this array with the specified string value.
|
void |
setData(java.lang.Object data)
Sets the elements of this array in column-major order until the input strings are
all consumed or all elements of this array are updated, whichever comes first.
|
java.lang.Object |
sharedCopy()
Creates and returns a shared copy of this array.
|
java.lang.Object[] |
toArray()
Returns a 1-D string 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.
|
disposeArray
public MWStringArray()
java.lang.RuntimeException
public MWStringArray(int[] dims)
dims
- Array of dimension sizes. Each dimension size must be greater than zero.java.lang.RuntimeException
public MWStringArray(java.lang.String val)
val
- The value to initialize the array element.java.lang.RuntimeException
public MWStringArray(java.lang.String[] vals)
vals
- The values to initialize the array elements.java.lang.RuntimeException
public java.lang.Object clone() throws java.lang.CloneNotSupportedException
MWStringArray
instance representing a deep copy of the
underlying MATLAB array.
Example: Cloning a String Array Object
Create a clone of MWStringArray object A as follows:MWStringArray A = new MWStringArray("Hello"); MWStringArray C = (MWStringArray)A.clone(); System.out.println("Clone of matrix A is:"); System.out.println(C.get(1));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()
MWStringArray
instance representing a shared copy of the
underlying MATLAB array.
Example: Making a Shared Copy of a String Array Object
Create a shared copy of MWStringArray object A as follows:MWStringArray A = new MWStringArray("Hello"); MWStringArray S = (MWStringArray)A.sharedCopy(); System.out.print("Shared copy of matrix A is \"" + S.get(1) + "\"");When run, the example displays this output:
Shared copy of matrix A is "Hello"
public void set(int index, java.lang.Object element)
index
- The offset 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. Pass null to unset the element.java.lang.RuntimeException
public void set(int[] indices, java.lang.Object element)
indices
- The indices of the element to replace.element
- New value to replace at index. Pass null to unset the element.java.lang.NullPointerException
java.lang.RuntimeException
public java.lang.Object get(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.RuntimeException
public java.lang.Object get(int[] indices)
indices
- The indices of the requested element.java.lang.NullPointerException
java.lang.RuntimeException
public MWClassID classID()
MWClassID.CHAR
for MWStringArray
.
Example: Getting the Class ID of a String Array
Create an MWStringArray object and then display the class ID:MWStringArray A = new MWStringArray("Hello"); System.out.println("The class of A is " + A.classID());When run, the example displays this output:
The class of A is string
public <T> T applyVisitor(AbstractMWArrayVisitor<T> v)
protected void validate()
public static MWStringArray newInstance(int[] dims)
dims
- Array of dimension sizes. Each dimension size must be non-negative.MWStringArray
with the specified dimensions.java.lang.RuntimeException
public int numberOfElements()
java.lang.RuntimeException
public int numberOfDimensions()
java.lang.RuntimeException
public int[] getDimensions()
java.lang.RuntimeException
public int numberOfNonZeros()
numberOfElements()
.public int maximumNonZeros()
numberOfElements()
.public boolean IsMissingElement(int index)
index
- The offset of the requested element in the array.java.lang.RuntimeException
public boolean IsMissingElement(int[] indices)
indices
- The indices of the requested element.java.lang.RuntimeException
public void setData(java.lang.Object data)
data
- A String or String[]. Pass null to unset all the elements.java.lang.IllegalArgumentException
java.lang.RuntimeException
public java.lang.Object getData()
numberOfElements()
.public java.lang.String toString()
public java.lang.Object[] toArray()
numberOfElements()
.public byte[] serialize() throws java.io.IOException
java.io.IOException
- if the array cannot be serialized. For
example, executable content (function handles, class instances) cannot
be serialized.public static MWArray deserialize(byte[] data)
data
- serialized array returned from MWArray.serializepublic boolean isEmpty()
public boolean isSparse()
public boolean equals(java.lang.Object obj)
public int compareTo(java.lang.Object obj)
public int hashCode()
public void dispose()
dispose
in interface Disposable
dispose
in class MWArray
public int[] rowIndex()
public int[] columnIndex()
columnIndex
in class MWArray
protected java.lang.Object readResolve() throws java.io.ObjectStreamException
java.io.InvalidObjectException
- Attempt to load an invalid array handle.java.io.ObjectStreamException
© 1994-2017 The MathWorks, Inc. Patents Trademarks