ContactCenters
V. 0.9.9.

umontreal.iro.lecuyer.xmlconfig
Class ArrayParam2D

java.lang.Object
  extended by umontreal.iro.lecuyer.xmlconfig.AbstractParam
      extended by umontreal.iro.lecuyer.xmlconfig.ParamWithSourceArray
          extended by umontreal.iro.lecuyer.xmlconfig.ArrayParam2D
All Implemented Interfaces:
Cloneable, Param, StorableParam

public class ArrayParam2D
extends ParamWithSourceArray
implements Cloneable, StorableParam

Represents a parameter object containing a 2D array or a matrix of parameters. When a creater method constructs such a parameter object, it needs to specify a component class for the elements in the 2D array. The component class can be any non-array primitive type or class supported by StringConvert. It is recommended to use this class as a temporary placeholder. A creater method constructs and returns an instance whereas an adder method receives the configured instance and extracts the array, without having to keep the parameter object.

In the XML file, two formats are allowed to represent this parameter. The 2D array can be specified as a list of arrays or one row element can be used for each row of the 2D array. As with ArrayParam, the row elements supports the repeat attribute.

For example,


    <matrix>
       {1, 2,3},
       {4, 5},
       {4, 5},
       {4, 5},
       {4, 5},
       {9, 11,13}
    </matrix>
is equivalent to

    <matrix>
       <row>1,2,3</row>
       <row repeat="4">4, 5</row>
       <row> 9 , 11, 13</row>
    </matrix>

Matrices can also be specified externally by using the CSV or DB sub-elements. See ParamWithSourceArray for more information.


Nested Class Summary
static class ArrayParam2D.MatrixRowParam
          For internal use only.
 
Constructor Summary
ArrayParam2D(Class<?> componentClass)
          Constructs a new 2D array parameter with components of class componentClass.
 
Method Summary
 ArrayParam2D clone()
           
 ArrayParam2D.MatrixRowParam createRow()
          For internal use only.
 boolean[][] getBooleanValues()
          Converts the objects returned by getValues() to boolean and returns the resulting 2D array.
 byte[][] getByteValues()
          Converts the objects returned by getValues() to byte and returns the resulting 2D array.
 char[][] getCharValues()
          Converts the objects returned by getValues() to char and returns the resulting 2D array.
 Class<?> getComponentClass()
          Returns the class of the components in this array parameter.
 double[][] getDoubleValues()
          Converts the objects returned by getValues() to double and returns the resulting 2D array.
 float[][] getFloatValues()
          Converts the objects returned by getValues() to float and returns the resulting 2D array.
 int[][] getIntValues()
          Converts the objects returned by getValues() to int and returns the resulting 2D array.
 long[][] getLongValues()
          Converts the objects returned by getValues() to long and returns the resulting 2D array.
 short[][] getShortValues()
          Converts the objects returned by getValues() to short and returns the resulting 2D array.
 Object[][] getValues()
          Returns the values in the 2D array represented by this parameter object.
 boolean isAttributeSupported(String a)
          For internal use only.
 void nestedText(ParamReader reader, String str)
          For internal use only.
 void setValues(Object[][] m)
          Sets the 2D array to m.
 Element toElement(ClassFinder finder, Node parent, String elementName, int spc)
          Converts this parameter object to a DOM element using the class finder finder for formatting class names, with parent node parent, element name elementName, and spc spaces for each indentation level.
 
Methods inherited from class umontreal.iro.lecuyer.xmlconfig.ParamWithSourceArray
addCSV, addDB, addExcel, disposeSourceArray, getDataMatrix, getNumColumn, getNumRows, getSourceSubset, getStartingColumn, getStartingRow, initSourceArray, isTransposed, setDataMatrix, setNumColumns, setNumRows, setStartingColumn, setStartingRow, setTransposed
 
Methods inherited from class umontreal.iro.lecuyer.xmlconfig.AbstractParam
check, createDocument, getId, getXref, setId, setXref, toString, write, write, write, write, write, write, write, write
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ArrayParam2D

public ArrayParam2D(Class<?> componentClass)
Constructs a new 2D array parameter with components of class componentClass.

Parameters:
componentClass - the component class.
Throws:
NullPointerException - if componentClass is null.
IllegalArgumentException - if componentClass is an array class.
Method Detail

getComponentClass

public Class<?> getComponentClass()
Returns the class of the components in this array parameter.

Returns:
the component class.

getValues

public Object[][] getValues()
Returns the values in the 2D array represented by this parameter object. The returned 2D array can safely be casted to a 2D array of the component class.

Returns:
the represented 2D array.
Throws:
ParamReadException - if no 2D array was specified.

getFloatValues

public float[][] getFloatValues()
Converts the objects returned by getValues() to float and returns the resulting 2D array.

Returns:
the 2D array of single-precision values.
Throws:
IllegalStateException - if the component class is incompatible.

getDoubleValues

public double[][] getDoubleValues()
Converts the objects returned by getValues() to double and returns the resulting 2D array.

Returns:
the 2D array of double-precision values.
Throws:
IllegalStateException - if the component class is incompatible.

getIntValues

public int[][] getIntValues()
Converts the objects returned by getValues() to int and returns the resulting 2D array.

Returns:
the 2D array of integers.
Throws:
IllegalStateException - if the component class is incompatible.

getShortValues

public short[][] getShortValues()
Converts the objects returned by getValues() to short and returns the resulting 2D array.

Returns:
the 2D array of integers.
Throws:
IllegalStateException - if the component class is incompatible.

getLongValues

public long[][] getLongValues()
Converts the objects returned by getValues() to long and returns the resulting 2D array.

Returns:
the 2D array of integers.
Throws:
IllegalStateException - if the component class is incompatible.

getByteValues

public byte[][] getByteValues()
Converts the objects returned by getValues() to byte and returns the resulting 2D array.

Returns:
the 2D array of integers.
Throws:
IllegalStateException - if the component class is incompatible.

getCharValues

public char[][] getCharValues()
Converts the objects returned by getValues() to char and returns the resulting 2D array.

Returns:
the 2D array of characters.
Throws:
IllegalStateException - if the component class is incompatible.

getBooleanValues

public boolean[][] getBooleanValues()
Converts the objects returned by getValues() to boolean and returns the resulting 2D array.

Returns:
the 2D array of booleans.
Throws:
IllegalStateException - if the component class is incompatible.

setValues

public void setValues(Object[][] m)
Sets the 2D array to m. If the component type of m is not assignable to the component class, this method throws an IllegalArgumentException.

Parameters:
m - the new 2D array.
Throws:
NullPointerException - if m is null.
IllegalArgumentException - if the component class is incompatible with m.

isAttributeSupported

public boolean isAttributeSupported(String a)
For internal use only.


createRow

public ArrayParam2D.MatrixRowParam createRow()
For internal use only.


nestedText

public void nestedText(ParamReader reader,
                       String str)
For internal use only.


toElement

public Element toElement(ClassFinder finder,
                         Node parent,
                         String elementName,
                         int spc)
Description copied from interface: StorableParam
Converts this parameter object to a DOM element using the class finder finder for formatting class names, with parent node parent, element name elementName, and spc spaces for each indentation level. The method must create an Element instance with name elementName and add it to the node parent of the DOM tree. It is recommended to use DOMUtils helper methods for this. After the element is created, attributes can be set and nested contents can be added. The configured DOM element is then returned.

Specified by:
toElement in interface StorableParam
Overrides:
toElement in class ParamWithSourceArray
Parameters:
finder - the class finder used to format class names.
parent - the parent of the new element.
elementName - the name of the constructed element.
spc - the number of spaces for each indentation level.
Returns:
the newly-constructed element.

clone

public ArrayParam2D clone()
Overrides:
clone in class ParamWithSourceArray

ContactCenters
V. 0.9.9.

To submit a bug or ask questions, send an e-mail to Richard Simard.