public class MWStructArray extends MWArray implements java.io.Serializable
MWStructArray
class manages a native MATLAB struct array.
This class does not depend on MATLAB Runtime and should only be used in a Java RMI based
application where the client machine does not have MATLAB Runtime installed.Constructor and Description |
---|
MWStructArray()
Creates an empty struct array.
|
MWStructArray(int[] inDims,
java.lang.String[] fNames)
Constructs a new struct array with the specified dimensions and field names.
|
MWStructArray(int rows,
int cols,
java.lang.String[] fNames)
Constructs a new struct matrix with the specified number of rows and columns and field names.
|
Modifier and Type | Method and Description |
---|---|
boolean |
equals(java.lang.Object obj)
Returns true if the input Object is of type MWStructArray and has same field names.
|
int |
fieldIndex(java.lang.String fieldName)
Returns the 0-based index for a field name
|
java.lang.String[] |
fieldNames()
Returns the field names in this array.
|
static MWStructArray |
fromBean(java.lang.Object bean)
Convert a Java bean into MWStructArray
|
static MWStructArray |
fromMap(java.util.Map<java.lang.String,java.lang.Object> map)
Convert java.util.Map to MWStructArray
|
static MWStructArray |
fromProperties(java.util.Properties props)
Convert a java.util.Properties into MWStructArray
|
java.lang.Object |
get(int[] index)
Returns the element at the specified 1-based index-array in this array.
|
java.lang.Object |
get(java.lang.String fName,
int index)
Returns the element at the specified 1-based offset and field name in this array.
|
java.lang.Object |
get(java.lang.String fName,
int[] idxArr)
Returns the element at the specified 1-based index-array and field name in this array.
|
int |
hashCode()
This method returns a hash of the object.
|
int |
numberOfFields() |
void |
set(int[] index,
java.lang.Object val)
Replaces the element at the specified 1-based index-array in this array with the specified element.
|
void |
set(java.lang.String fName,
int[] idxArr,
java.lang.Object val)
Replaces the element at the specified 1-based index-array and field name in this array with the specified element.
|
void |
set(java.lang.String fName,
int index,
java.lang.Object val)
Replaces the element at the specified 1-based offset and field name in this array with the specified element.
|
java.lang.String |
toString()
This method returns a string representation of the array.
|
get, getData, getDimensions, getDimsStr, getMaxValidIndex, getOneBasedIndexForArray, initNativeArray, isEmpty, numberOfDimensions, numberOfElements, set, setMaxValidIndex
public MWStructArray()
This example creates a 0-by-0 MWStructArray object:
MWStructArray S = new MWStructArray(); System.out.println("Structure array S: " + S);When run, the example displays this output:
Structure array S: []
public MWStructArray(int rows, int cols, java.lang.String[] fNames)
rows
- Number of rows. Number of rows must be non-negative.cols
- Number of columns. Number of columns must be non-negative.fNames
- Array of field names.java.lang.NegativeArraySizeException
- A negative row or column size is supplied.
This example creates a 1-by-2 MWStructArray object with fields f1, f2, and f3:
int rows = 1, cols = 2; String[] sfields = {"f1", "f2", "f3"}; MWStructArray S = new MWStructArray(rows, cols, sfields); System.out.println("Structure array S: " + S);When run, the example displays this output:
Structure array S: 1x2 struct array with fields: f1 f2 f3
public MWStructArray(int[] inDims, java.lang.String[] fNames)
inDims
- Array of dimension sizes. Each dimension size must be non-negative.fNames
- Array of field names.java.lang.NegativeArraySizeException
- A negative dimension size is supplied.
This example creates a 1-by-2 MWStructArray object with fields f1, f2, and f3:
String[] sfields = {"f1", "f2", "f3"}; int[] dims = new int[]{1,2}; MWStructArray S = new MWStructArray(dims, sfields); System.out.println("Structure array S: " + S);When run, the example displays this output:
Structure array S: 1x2 struct array with fields: f1 f2 f3
public int fieldIndex(java.lang.String fieldName)
fieldName
- the name of the field to look uppublic int numberOfFields()
Create an MWStructArray object with three fields and display the number of fields:
int[] sdims = {1, 2}; String[] sfields = {"f1", "f2", "f3"}; MWStructArray S = new MWStructArray(sdims, sfields); String[] str = S.fieldNames(); System.out.println("There are " + S.numberOfFields() + " fields in this structure.");When run, the example displays this output:
There are 3 fields in this structure.
public java.lang.String[] fieldNames()
Create an MWStructArray object with three fields and display the field names:
int[] sdims = {1, 2}; String[] sfields = {"f1", "f2", "f3"}; MWStructArray S = new MWStructArray(sdims, sfields); String[] str = S.fieldNames(); System.out.print("The structure has the fields: "); for (int i=0; i < S.numberOfFields(); i++) System.out.print(" " + str[i]);When run, the example displays this output:
The structure has the fields: f1 f2 f3
public java.lang.Object get(int[] index)
get
in class MWArray
index
- Array of indices specifying the location of requested element.
The length of the index array must be exactly MWArray.numberOfDimensions()
+ 1.
The first element of the index array is the 1-based field number with valid range 1 <= index[0] <= numberOfFields()
.
The remaining entries have valid ranges: 1 <= index[i] <= N[i], where N[i] = the size of the ith dimension.java.lang.IndexOutOfBoundsException
- An invalid index has been supplied.public java.lang.Object get(java.lang.String fName, int index)
fName
- The field name of the requested element.index
- of the requested element.java.lang.IndexOutOfBoundsException
- An invalid index has been supplied.public java.lang.Object get(java.lang.String fName, int[] idxArr)
fName
- The field name of the requested element.idxArr
- Array of indices specifying the location of the requested element.
The length of the index array must be exactly MWArray.numberOfDimensions()
.
The entries of the index array have valid ranges: 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 val)
set
in class MWArray
index
- Array of indices specifying the location of the element to replace.
The length of the index array must be exactly MWArray.numberOfDimensions()
+ 1.
The first element of the index array is the 1-based field number with valid range 1 <= index[0] <= numberOfFields()
.
The remaining entries have valid ranges: 1 <= index[i] <= N[i], where N[i] = the size of the ith dimension.val
- New element to replace at index. If element is of type MWArray
, the cell
at index set to a shared copy of the underlying MATLAB array. Otherwise, a new MATLAB array is created
from element using default conversion rules and assigned to the cell at index.java.lang.IndexOutOfBoundsException
- An invalid index has been supplied.public void set(java.lang.String fName, int index, java.lang.Object val)
fName
- The field name of the element to replace.index
- The index of the element to replace. Valid range: 1 <= index <= N, where N = MWArray.numberOfElements()
val
- New element to replace at index. If element is of type MWArray
, the cell
at index set to a shared copy of the underlying MATLAB array. Otherwise, a new MATLAB array is created
from element using default conversion rules and assigned to the cell at index.java.lang.IndexOutOfBoundsException
- An invalid index has been supplied.public void set(java.lang.String fName, int[] idxArr, java.lang.Object val)
fName
- The field name of the element to replace.idxArr
- Array of indices specifying the location of the element to replace.
The length of the index array must be exactly MWArray.numberOfDimensions()
.
The entries of the index array have valid ranges: 1 <= index[i] <= N[i], where N[i] = the size of the ith dimension.val
- New element to replace at index. If element is of type MWArray
, the cell
at index set to a shared copy of the underlying MATLAB array. Otherwise, a new MATLAB array is created
from element using default conversion rules and assigned to the cell at index.java.lang.IndexOutOfBoundsException
- An invalid index has been supplied.public java.lang.String toString()
public static MWStructArray fromMap(java.util.Map<java.lang.String,java.lang.Object> map) throws MWException
map
- An instance of java.util.MapMWException
- exceptionpublic static MWStructArray fromBean(java.lang.Object bean) throws java.beans.IntrospectionException, MWException
bean
- Java beanjava.beans.IntrospectionException
- exception relating to introspectionMWException
- exceptionpublic static MWStructArray fromProperties(java.util.Properties props)
props
- propertiespublic boolean equals(java.lang.Object obj)
© 1994-2017 The MathWorks, Inc. Patents Trademarks