25package umontreal.ssj.util.io;
27import java.lang.reflect.Array;
36 protected String label;
37 protected Object data;
38 protected int effectiveLength;
47 this(label, data, -1);
58 public DataField(String label, Object data,
int effectiveLength) {
61 this.effectiveLength = effectiveLength;
79 return data.getClass();
93 return data.getClass().isArray();
100 return isArray() && Array.get(data, 0).getClass().isArray();
110 if (effectiveLength < 0)
111 return Array.getLength(data);
112 return effectiveLength;
119 return (data instanceof String);
126 return (data instanceof Integer);
133 return (data instanceof Float);
140 return (data instanceof Double);
156 return (data instanceof String) ? (String) data :
null;
163 return (data instanceof Integer) ? ((Integer) data).intValue() : 0;
171 return (data instanceof Float) ? ((Float) data).floatValue() : 0;
179 return (data instanceof Double) ? ((Double) data).doubleValue() : 0;
195 return (data instanceof String[]) ? (String[]) data :
null;
203 return (data instanceof
int[]) ? (
int[]) data :
null;
211 return (data instanceof
float[]) ? (
float[]) data :
null;
219 return (data instanceof
double[]) ? (
double[]) data :
null;
235 return (data instanceof String[][]) ? (String[][]) data :
null;
243 return (data instanceof
int[][]) ? (
int[][]) data :
null;
251 return (data instanceof
float[][]) ? (
float[][]) data :
null;
259 return (data instanceof
double[][]) ? (
double[][]) data :
null;
Class getType()
Returns the type of the field.
String getLabel()
Returns the field label (or name).
double[][] asDoubleArray2D()
Returns the value as two-dimensional double array or null if it is not of type double[][].
int[] asIntArray()
Returns the value as one-dimensional int array or null if it is not of type int[].
double asDouble()
Returns the value as double or 0 if it is not of type double See isDouble.
String asString()
Returns the value as String, or null if it is not of type String.
boolean isAtomic()
Returns true if the field value is atomic data.
boolean isFloat()
Returns true if the field value is an atomic float.
double[] asDoubleArray()
Returns the value as one-dimensional double array or null if it is not of type double[].
float asFloat()
Returns the value as float or 0 if it is not of type float See isFloat.
DataField(String label, Object data, int effectiveLength)
Constructor.
String[] asStringArray()
Returns the value as one-dimensional String array or null if it is not of type String[].
float[][] asFloatArray2D()
Returns the value as two-dimensional float array or null if it is not of type float[][].
boolean isString()
Returns true if the field value is an atomic String.
int getArrayLength()
Returns the length of the array contained by the field, or -1 if it is not an array.
boolean isArray2D()
Returns true if the field contains a two-dimensional array.
boolean isArray()
Returns true if the field contains an array.
boolean isDouble()
Returns true if the field value is an atomic double.
int[][] asIntArray2D()
Returns the value as two-dimensional int array or null if it is not of type int[][].
int asInt()
Returns the value as int or 0 if it is not of type int See isInt.
DataField(String label, Object data)
Constructor.
String[][] asStringArray2D()
Returns the value as two-dimensional String array or null if it is not of type String[][].
float[] asFloatArray()
Returns the value as one-dimensional float array or null if it is not of type float[].
Object asObject()
Returns the value of the field as an Object.
boolean isInt()
Returns true if the field value is an atomic int.