Example usage for org.apache.commons.math3 Field getRuntimeClass

List of usage examples for org.apache.commons.math3 Field getRuntimeClass

Introduction

In this page you can find the example usage for org.apache.commons.math3 Field getRuntimeClass.

Prototype

Class<? extends FieldElement<T>> getRuntimeClass();

Source Link

Document

Returns the runtime class of the FieldElement.

Usage

From source file:org.gitools.analysis.groupcomparison.format.math33Preview.MathArrays.java

/**
 * Build an array of elements.// ww w.j  av  a 2  s  .c  o m
 * <p/>
 * Arrays are filled with field.getZero()
 *
 * @param <T>    the type of the field elements
 * @param field  field to which array elements belong
 * @param length of the array
 * @return a new array
 * @since 3.2
 */
public static <T> T[] buildArray(final Field<T> field, final int length) {
    @SuppressWarnings("unchecked") // OK because field must be correct class
    T[] array = (T[]) Array.newInstance(field.getRuntimeClass(), length);
    Arrays.fill(array, field.getZero());
    return array;
}

From source file:org.gitools.analysis.groupcomparison.format.math33Preview.MathArrays.java

/**
 * Build a double dimension  array of elements.
 * <p/>//from   www  . j  a v  a  2 s  .c o m
 * Arrays are filled with field.getZero()
 *
 * @param <T>     the type of the field elements
 * @param field   field to which array elements belong
 * @param rows    number of rows in the array
 * @param columns number of columns (may be negative to build partial
 *                arrays in the same way <code>new Field[rows][]</code> works)
 * @return a new array
 * @since 3.2
 */
@SuppressWarnings("unchecked")
public static <T> T[][] buildArray(final Field<T> field, final int rows, final int columns) {
    final T[][] array;
    if (columns < 0) {
        T[] dummyRow = buildArray(field, 0);
        array = (T[][]) Array.newInstance(dummyRow.getClass(), rows);
    } else {
        array = (T[][]) Array.newInstance(field.getRuntimeClass(), new int[] { rows, columns });
        for (int i = 0; i < rows; ++i) {
            Arrays.fill(array[i], field.getZero());
        }
    }
    return array;
}