ContactCenters
V. 0.9.9.

umontreal.iro.lecuyer.xmlbind
Class ArrayConverter

java.lang.Object
  extended by umontreal.iro.lecuyer.xmlbind.ArrayConverter

public class ArrayConverter
extends Object

Provides helper methods to convert 2D arrays read by JAXB to the Java's more natural representation of 2D arrays, namely arrays of arrays. For example, DoubleArray can be used to read a 2D array in an XML file. It defines a DoubleArray.getRows() method returning a list of DoubleArray.Row instances representing rows. Each row is defined by a list of values, and a repeat count. This class defines the unmarshalArray(DoubleArray) method converting such an array object to a more natural double[][] 2D array. It also provides the marshalArray(double[][]) which does the inverse operation. Other similar methods are provided for arrays of integers, and arrays of durations.


Nested Class Summary
protected static interface ArrayConverter.RowFactory<T>
          Represents a factory object for creating rows when marshalling a 2D array to JAXB object.
 
Constructor Summary
ArrayConverter()
           
 
Method Summary
protected static
<T> List<?>
marshalArray(ArrayConverter.RowFactory<T> factory, T[][] array)
          Uses the given row factory to convert the specified Java 2D array into a list intended to be associated with the JAXB representation of a 2D array.
static BooleanArray marshalArray(boolean[][] array)
          Marshals a Java 2D array of boolean values into an object that can be serialized to XML by JAXB.
static List<Double> marshalArray(double[] array)
          Converts an array of double-precision values to a list containing values wrapped into objects of class Double.
static DoubleArray marshalArray(double[][] array)
          Marshals a Java 2D array of double-precision values into an object that can be serialized to XML by JAXB.
static DurationArray marshalArray(Duration[][] array)
          Marshals a Java 2D array of durations into an object that can be serialized to XML by JAXB.
static IntArray marshalArray(int[][] array)
          Marshals a Java 2D array of integers into an object that can be serialized to XML by JAXB.
static NonNegativeDurationArray marshalArrayNonNegative(Duration[][] array)
          Similar to marshalArray(Duration[][]), for non-negative durations only.
static boolean[][] unmarshalArray(BooleanArray array)
          Unmarshals a 2D array JAXB object into a Java 2D array of boolean values.
protected static
<T> T[][]
unmarshalArray(Class<T> componentClass, List<?> rows)
          Converts the list of arrays rows into a Java 2D array.
static double[][] unmarshalArray(DoubleArray array)
          Unmarshals a 2D array JAXB object into a Java 2D array of double-precision values.
static Duration[][] unmarshalArray(DurationArray array)
          Unmarshals a 2D array JAXB object into a Java 2D array of time durations.
static int[][] unmarshalArray(IntArray array)
          Unmarshals a 2D array JAXB object into a Java 2D array of integers.
static double[] unmarshalArray(List<Double> list)
          Converts a list containing double-precision values wrapped into objects of class Double to an array of double-precision values.
static Duration[][] unmarshalArray(NonNegativeDurationArray array)
          Similar to unmarshalArray(DurationArray) for non-negative durations.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ArrayConverter

public ArrayConverter()
Method Detail

unmarshalArray

protected static <T> T[][] unmarshalArray(Class<T> componentClass,
                                          List<?> rows)
Converts the list of arrays rows into a Java 2D array. JAXB objects representing 2D arrays provide a method returning a list of elements, each element being an object of an element-dependent class with no common base class. This method accepts a list of such objects, and uses Reflection as follows to get a more natural 2D array. For each element of the given list, it looks for getRepeat and getValue methods to obtain the number of times the inner array must be repeated in the 2D array, and the values composing the inner array, respectively. This method verifies that getRepeat returns an int or an Integer, and that getValue returns a List. It is assumed that the list returned by getValue contains instances of the class represented by componentClass. This method is intended to be called by front-end methods public such as unmarshalArray(DoubleArray).

Type Parameters:
T - the type of components in the 2D array.
Parameters:
componentClass - the component class of the 2D array.
rows - the list of row elements.
Returns:
the resulting 2D array.

unmarshalArray

public static double[][] unmarshalArray(DoubleArray array)
Unmarshals a 2D array JAXB object into a Java 2D array of double-precision values.

Parameters:
array - the 2D array represented as a JAXB object.
Returns:
the Java 2D array.

unmarshalArray

public static boolean[][] unmarshalArray(BooleanArray array)
Unmarshals a 2D array JAXB object into a Java 2D array of boolean values.

Parameters:
array - the 2D array represented as a JAXB object.
Returns:
the Java 2D array.

unmarshalArray

public static int[][] unmarshalArray(IntArray array)
Unmarshals a 2D array JAXB object into a Java 2D array of integers.

Parameters:
array - the 2D array represented as a JAXB object.
Returns:
the Java 2D array.

unmarshalArray

public static Duration[][] unmarshalArray(DurationArray array)
Unmarshals a 2D array JAXB object into a Java 2D array of time durations. Note that time durations can be converted to times in milliseconds using Duration.getTimeInMillis(java.util.Date).

Parameters:
array - the 2D array represented as a JAXB object.
Returns:
the Java 2D array.

unmarshalArray

public static Duration[][] unmarshalArray(NonNegativeDurationArray array)
Similar to unmarshalArray(DurationArray) for non-negative durations.

Parameters:
array - the 2D array represented as a JAXB object.
Returns:
the Java 2D array.

marshalArray

protected static <T> List<?> marshalArray(ArrayConverter.RowFactory<T> factory,
                                          T[][] array)
Uses the given row factory to convert the specified Java 2D array into a list intended to be associated with the JAXB representation of a 2D array. For each array in array, this method creates a list and passes it to the row factory factory. The row objects corresponding to the inner arrays are then regrouped into a list which is returned. This method is intended to be used by marshalArray(double[][]).

Type Parameters:
T - the class of the components in the array.
Parameters:
factory - the row factory.
array - the Java 2D array.
Returns:
the list to be used in the JAXB representation of the array.

marshalArray

public static BooleanArray marshalArray(boolean[][] array)
Marshals a Java 2D array of boolean values into an object that can be serialized to XML by JAXB.

Parameters:
array - the input Java 2D array.
Returns:
the output object for JAXB.

marshalArray

public static DoubleArray marshalArray(double[][] array)
Marshals a Java 2D array of double-precision values into an object that can be serialized to XML by JAXB.

Parameters:
array - the input Java 2D array.
Returns:
the output object for JAXB.

marshalArray

public static IntArray marshalArray(int[][] array)
Marshals a Java 2D array of integers into an object that can be serialized to XML by JAXB.

Parameters:
array - the input Java 2D array.
Returns:
the output object for JAXB.

marshalArray

public static DurationArray marshalArray(Duration[][] array)
Marshals a Java 2D array of durations into an object that can be serialized to XML by JAXB. Duration objects can be created using DatatypeFactory.

Parameters:
array - the input Java 2D array.
Returns:
the output object for JAXB.

marshalArrayNonNegative

public static NonNegativeDurationArray marshalArrayNonNegative(Duration[][] array)
Similar to marshalArray(Duration[][]), for non-negative durations only.

Parameters:
array - the input Java 2D array.
Returns:
the output object for JAXB.

unmarshalArray

public static double[] unmarshalArray(List<Double> list)
Converts a list containing double-precision values wrapped into objects of class Double to an array of double-precision values.

Parameters:
list - the list of wrapped values.
Returns:
the array of values.

marshalArray

public static List<Double> marshalArray(double[] array)
Converts an array of double-precision values to a list containing values wrapped into objects of class Double.

Parameters:
array - the array of values.
Returns:
the list of values.

ContactCenters
V. 0.9.9.

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