Michael Thomas Flanagan's Java Scientific Library

DateType Class:      Identification of Data Type

     

Last update of this class: 11 April 2012
Main Page of Michael Thomas Flanagan's Java Scientific Library

This class contains methods for:
import directive: import flanagan.math.DataType;

SUMMARY OF METHODS

Constructor public DataType(Object obj)
Identify entered Object Get the Object name public String getTypeName() public static String getTypeName(Object obj)
Get the Object dimension public int getTypeDimension() public static int getTypeDimension(Object obj)
Get the Object code public int getTypeCode() public static int getTypeCode(Object obj)
Get all above data public Object[] getTypeData() public static Object[] getTypeData(Object obj)
Analysis of Object elements
if entered Object is
    ArrayList
    ArrayDeque
    LinkedList
    Object[]
    or
    Vector
Get the element names public String[] getArrayNames() public static String[] getArrayNames(Object obj)
Get the element dimensions public int[] getArrayDimensions() public static int[] getArrayDimensions(Object obj)
Get the element codes public int[] getArrayCodes() public static int[] getArrayCodes(Object obj)
Get all above array data public ArrayList<Object> getArrayData() public static ArrayList<Object> getArrayData(Object obj)
Highest precision name present public String highestPrecisionName() public static String highestPrecisionName(Object obj)
Highest precision code present public int highestPrecisionCode() public static int highestPrecisionCode(Object obj)
Convert to highest precision present public Object convert_to_highestPrecision() public static Object convert_to_highestPrecision(Object obj)
Convert to double public double[] convert_to_double() public static double[] convert_to_double(Object obj)
Convert to BigDecimal public BigDecimal[] convert_to_BigDecimal() public static BigDecimal[] convert_to_BigDecimal(Object obj)
Convert to String public String[] convert_to_String() public static String[] convert_to_String(Object obj)




CONSTRUCTOR

public DataType(Object obj)
Usage:                      DataType dt = new DataType(obj);
Creates an instance of dataType. The entered Object, obj, may be any Object.



IDENTIFICATION OF THE ENTERED Object

Get the Object name
public String getTypeName()
public static String getTypeName(Object obj)
Usage:                      name = dt.getTypeName();
Returns the name of the Object, entered via the constructor, as a String in which the type name appears first folowed by the dimensions indicated by the [] symbol, e.g. double[][] would be returned if the entered Object was a two dimensional array of doubles. No [] symbols are included if the array is not a dimensioned Object, e.g. ArrayList would be returned if the entered Object was a single ArrayList.

Usage:                      name = DataType.getTypeName(obj);
Returns the name of the entered object, obj, as a String in which the type name appears first followed by the dimensions indicated by the [] symbol, e.g. double[][] would be returned if the entered Object was a two dimensional array of doubles. No [] symbols are included if the array is not a dimensioned Object, e.g. ArrayList would be returned if the entered Object was a single ArrayList.

Get the Object dimension
public int getTypeDimension()
public static int getTypeDimension(Object obj)
Usage:                      dim = dt.getTypeDimension();
Returns the dimension of the Object, entered via the constructor, as an int, e.g. 3 would be returned if the entered Object was a three dimensional array, e.g. Float[][][]. 0 is returned if the entered Object is not a dimensioned Object e.g. a single ArrayList.

Usage:                      dim = DataType.getTypeDimension(obj);
Returns the dimension of the entered Object, obj, as an int, e.g. 3 would be returned if the entered Object was a three dimensional array, e.g. Float[][][]. 0 is returned if the entered Object is not a dimensioned Object e.g. a single ArrayList.

Get the Object code
public int getTypeCode()
public static int getTypeCode(Object obj)
Usage:                      code = dt.getTypeCode();
Returns the code of the Object, entered via the constructor, as an int. The code is a code defined by this class to facilitate the use of this library:

String   0BigDecimal   1BigInteger   2Double   3Float   4Long   5Integer   6Character   7
Short   8Byte   9Boolean   10Object   11ArrayList   12LinkedList   13ArrayDeque   14Vector   15
Complex   16Phasor   17ErrorProp   18ComplexErrorProp   19Matrix   20ComplexMatrix   21PhasorMatrix   22Polynomial   23
ComplexPoly   24ArrayMaths   25VectorMaths   26Point   27BlackBox   28OpenLoop   29ClosedLoop   30Prop   31
PropDeriv   32PropInt   33PropIntDeriv   34FirstOrder   35SecondOrder   36Compensator   37LowPassPassive   38HighPassPassive   39
DelayLine   40ZeroOrderHold   41Transducer   42AtoD   43DtoA   44         


If the entered Object is not one of those listed in the above table a code of -1 is returned.

Usage:                      code = DataType.getTypeCode(obj);
This method is the static equivalent of the above instance method, getTypeCode();.

Get all above data
public Object[] getTypeData()
public static Object[] getTypeData(Object obj)
Usage:                      data = DataType.getTypeData(obj);
This method returns all the data described in the above three methods as an Object array of three elements. In the above usage

Usage:                      code = DataType.getTypeData(obj);
This method is the static equivalent of the above instance method, getTypeData();.


ANALYSIS OF Object ELEMENTS

These methods may be called if the entered Object is an ArrayList, an ArrayDeque, a LinkedList, an Object[] or a Vector.
They return null if the entered Object is not one of the above.

Get the element names
public String[] getArrayNames()
public static String[] getArrayNames(Object obj)
Usage:                      names = dt.getArrayNames();
Returns the names of the elements of the Object, entered via the constructor, as the elements of a String array in which each element type name appears in the order of the Object elements. Each element is a String in which the element name is folowed by the dimensions indicated by the [] symbol, e.g. double[][] would be returned if the element was a two dimensional array of doubles. No [] symbols are included if the array is not a dimensioned Object, e.g. ArrayList would be returned if the element was a single ArrayList. The entered Object must be an ArrayList, an ArrayDeque, a LinkedList, an Object[] or a Vector. If the entered Object is not one of the these Objects null is returned.

Usage:                      names = DataType.getArrayNames(obj);
This method is the static equivalent of the above instance method, getArrayNames();.

Get the element dimensions
public int[] getArrayDimensions()
public static int[] getArrayDimensions(Object obj)
Usage:                      names = dt.getArrayDimensions();
Returns the dimensions of the elements of the Object, entered via the constructor, as the elements of an int array in which each element dimension appears in the order of the Object elements. Each element of the returned array is an int, e.g. would contain the integer 3 if the relevant element the entered Object was a three dimensional array, e.g. Float[][][]. 0 is returned if the element is not a dimensioned Object e.g. a single ArrayList. The entered Object must be an ArrayList, an ArrayDeque, a LinkedList, an Object[] or a Vector. If the entered Object is not one of the these Objects null is returned.

Usage:                      names = DataType.getArrayDimensions(obj);
This method is the static equivalent of the above instance method, getArrayDimensions();.

Get the element codes
public int[] getArrayCodes()
public static int[] getArrayCodes(Object obj)
Usage:                      names = dt.getArrayCodes();
Returns the codes of the elements of the Object, entered via the constructor, as the elements of an int array in which each element code appears in the order of the Object elements. The code is described
above under the method getArrayCodes(). The entered Object must be an ArrayList, an ArrayDeque, a LinkedList, an Object[] or a Vector. If the entered Object is not one of the these Objects null is returned.

Usage:                      names = DataType.getArrayCodes(obj);
This method is the static equivalent of the above instance method, getArrayCodes();.

Get all above array data
public ArrayList<Object> getArrayData()
public static ArrayList<Object> getArrayData(Object obj)
        data = DataType.getArrayData(obj);
This method returns all the data described in the above three methods as an ArrayList. In the above usage
The entered Object must be an ArrayList, an ArrayDeque, a LinkedList, an Object[] or a Vector. If the entered Object is not one of the these Objects the data elements will all be null.


Usage:                      code = DataType.getArrayData(obj);
This method is the static equivalent of the above instance method, getArrayData();.

Highest precision name present
public String highestPrecisionName()
public static String highestPrecisionName(Object obj)
Usage:                      hname = dt.highestPrecisionName();
This method returns the name of the highest precision element in the entered Object. The order of decreasing precision used is:
Before checking the precision
BigInteger is replaced by BigDecimal as the highest precision if BigInteger is found as the highest precision type but other elements are present as floating point numbers.
null is returned if elements of type other than those discussed immediately above are present. The entered Object must be an ArrayList, an ArrayDeque, a LinkedList, an Object[] or a Vector. If the entered Object is not one of the these Objects the data elements will all be null.

Usage:                      hname = DataType.highestPrecisionName(obj);
This method is the static equivalent of the above instance method, highestPrecisionName();.

Highest precision code present
public int highestPrecisionCode() public static int highestPrecisionCode(Object obj)
Usage:                      hcode = dt.highestPrecisionCode();
This method returns the name of the highest precision code in the entered Object. The order of precision is described
above under the method highestPrecisionName() and the code is described above under the method getTypeCode(). The entered Object must be an ArrayList, an ArrayDeque, a LinkedList, an Object[] or a Vector. If the entered Object is not one of the these Objects the data elements will all be null.

Usage:                      hcode = DataType.highestPrecisionCode(obj);
This method is the static equivalent of the above instance method, highestPrecisionCode();.

Convert to highest precision type present
public Object convert_to_highestPrecision()
public static Object convert_to_highestPrecision(Object obj)
Usage:                      hparray = dt.convert_to_highestPrecision();
This method returns as an Object an array of the elements of the entered Object, in the order of its elements, converted to the type corresponding to the highest precision present in the original elements, e.g. if the highest precision was Double the returned Object will be an array of Double, Double[], cast as Object. The order of precision is described
above under the method highestPrecisionName(). Each elements must be of a type listed above and the entered Object must be an ArrayList, an ArrayDeque, a LinkedList, an Object[] or a Vector. If the entered Object is not one of the these Objects the data elements will all be null.

Usage:                      hparray = DataType.convert_to_highestPrecision(obj);
This method is the static equivalent of the above instance method, convert_to_highestPrecision();.

Convert to double
public double[] convert_to_double()
public static double[] convert_to_double(Object obj)
Usage:                      darray = dt.convert_to_double();
This method returns as a double array, double[], an array of the elements of the entered Object, in the order of its elements, converted to the type double. Each elements must be of a type listed
above and the entered Object must be an ArrayList, an ArrayDeque, a LinkedList, an Object[] or a Vector. If the entered Object is not one of the these Objects the data elements will all be null.

Usage:                      darray = DataType.convert_to_double(obj);
This method is the static equivalent of the above instance method, convert_to_double();.

Convert to BigDecimal
public BigDecimal[] convert_to_BigDecimal()
public static BigDecimal[] convert_to_BigDecimal(Object obj)
Usage:                      bdarray = dt.convert_to_BigDecimal();
This method returns as a BigDecimal array, BigDecimal[], an array of the elements of the entered Object, in the order of its elements, converted to the type BigDecimal. Each elements must be of a type listed
above and the entered Object must be an ArrayList, an ArrayDeque, a LinkedList, an Object[] or a Vector. If the entered Object is not one of the these Objects the data elements will all be null.

Usage:                      bdarray = DataType.convert_to_BigDecimal(obj);
This method is the static equivalent of the above instance method, convert_to_BigDecimal();.

Convert to String
public String[] convert_to_String()
public static String[] convert_to_String(Object obj)
Usage:                      sarray = dt.convert_to_String();
This method returns as a String array, String[], an array of the elements of the entered Object, in the order of its elements, converted to the type String. Each elements must be of a type listed
above and the entered Object must be an ArrayList, an ArrayDeque, a LinkedList, an Object[] or a Vector. If the entered Object is not one of the these Objects the data elements will all be null.

Usage:                      bdarray = DataType.convert_to_String(obj);
This method is the static equivalent of the above instance method, convert_to_String();.



OTHER CLASSES USED BY THIS CLASS

This class uses the following classes in this library:



This page was prepared by Dr Michael Thomas Flanagan