ContactCenters
V. 0.9.9.

umontreal.iro.lecuyer.xmlconfig
Class ArrayParam

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

public class ArrayParam
extends ParamWithSourceArray
implements Cloneable, StorableParam

Represents a parameter object containing an array of parameters. When a creater method constructs this parameter object, it needs to indicate the class of the components in the 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 supported for the array parameter. A list of comma-separated strings that will be converted to objects of the component class can be used as contents. Alternatively, the array can be encoded using a row nested element for each element. The row element supports the repeat attribute allowing the specification of the number of times an element must be repeated in the array.

Fo rexample,


    <doublearray>2.3, 3.2, 3.2, 5.1</doublearray>
is equivalent to

    <doublearray>
       <row>2.3</row>
       <row repeat="2">3.2</row>
       <row>5.1</row>
    </doublearray>
and can be converted into an array containing 2.3, 3.2, 3.2, and 5.1.

Arrays can also be specified externally by using the CSV or DB sub-elements. See ParamWithSourceArray for more information. The constructed source subset is read row by row to obtain an array of objects.

This class provides methods to get the extracted array as well as methods for the primitive types.


Nested Class Summary
static class ArrayParam.RowParam
          For internal use only.
 
Constructor Summary
ArrayParam(Class<?> componentClass)
           
ArrayParam(Class<?> componentClass, String elementName)
          Constructs a new array parameter with components of class componentClass.
 
Method Summary
 ArrayParam clone()
           
 void defaultNestedElement(ParamReader reader, Element cel)
          For internal use only.
 boolean[] getBooleanValues()
          Converts the objects returned by getValues() to boolean and returns the resulting array.
 byte[] getByteValues()
          Converts the objects returned by getValues() to byte and returns the resulting array.
 char[] getCharValues()
          Converts the objects returned by getValues() to char and returns the resulting 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 array.
 float[] getFloatValues()
          Converts the objects returned by getValues() to float and returns the resulting array.
 int[] getIntValues()
          Converts the objects returned by getValues() to int and returns the resulting array.
 long[] getLongValues()
          Converts the objects returned by getValues() to long and returns the resulting array.
 short[] getShortValues()
          Converts the objects returned by getValues() to short and returns the resulting array.
 Object[] getValues()
          Returns the associated array of objects.
 boolean isAttributeSupported(String a)
          For internal use only.
protected  Param makeRow()
           
 void nestedText(ParamReader reader, String str)
          For internal use only.
 void setValues(Object[] v)
          Sets the array elements to v.
 Element toElement(ClassFinder finder, Node parent, String elementName1, 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

ArrayParam

public ArrayParam(Class<?> componentClass)

ArrayParam

public ArrayParam(Class<?> componentClass,
                  String elementName)
Constructs a new 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 associated array of objects. The returned array can safely be casted to an array of the component class.

Returns:
the associated array of objects.

getFloatValues

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

Returns:
the 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 array.

Returns:
the 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 array.

Returns:
the 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 array.

Returns:
the 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 array.

Returns:
the 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 array.

Returns:
the 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 array.

Returns:
the 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 array.

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

setValues

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

Parameters:
v - the values.
Throws:
NullPointerException - if v is null.
IllegalArgumentException - if the component class is incompatible with v.

isAttributeSupported

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


nestedText

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


defaultNestedElement

public void defaultNestedElement(ParamReader reader,
                                 Element cel)
For internal use only.


makeRow

protected Param makeRow()

toElement

public Element toElement(ClassFinder finder,
                         Node parent,
                         String elementName1,
                         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.
elementName1 - the name of the constructed element.
spc - the number of spaces for each indentation level.
Returns:
the newly-constructed element.

clone

public ArrayParam 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.