com.fdsapi.arrays
Class ArrayConverter

java.lang.Object
  |
  +--com.fdsapi.arrays.ArrayConverter
All Implemented Interfaces:
java.lang.Cloneable

public class ArrayConverter
extends java.lang.Object
implements java.lang.Cloneable

Mention either can overwrite data in input array with converted data or copy the output into another array. By default it allocates a new array and puts the converted data into a new array of the same size of the input array. Note calling the convert methods is thread safe IF the various set.../remove... methods are not called during this operation which can often be the case if the application for example creates the ArrayConverter class at startup. setTypeConverter(Object.class, new ConverterNumToString(new ConverterDateToString())); setTypeConverter(Number.class, new ConverterNumToString()); setTypeConverter(Date.class, new ConverterDateToString()); *

View Code


Constructor Summary
ArrayConverter()
          Creates a new instance of ArrayConverter
ArrayConverter(boolean overWriteExistingArray)
          Creates a new instance of ArrayConverter and when convert is called if true is passed the array passed into the convert method will be used in place to contain the resulting data, thus saving the the array creation for the output.
ArrayConverter(java.lang.String[] header)
          Creates a new instance of ArrayConverter and allows you to use colnames from a header when setting column converters.
ArrayConverter(java.lang.String[] header, boolean overWriteExistingArray)
          Creates an instance that allows for column converters to be set by name, and allows the developer to indicate whether they want the output array to be the original array or not
 
Method Summary
 java.lang.Object clone()
          Make a clone of the ArrayConverter
 java.lang.Object[][] convert(ArrayHeaderLocator arrayHeaderLocator, java.lang.Object[][] data)
          This method 'Converts' the data in the input array.
 java.lang.Object[][] convert(java.lang.Object[][] data)
          This method 'Converts' the data in the input array.
 java.lang.Object[][] convert(java.lang.String[] header, java.lang.Object[][] data)
          This method 'Converts' the data in the input array.
 ArrayConverter copy()
          Clones the ArrayConverter and then casts it to the appropriate type
 ArrayConverterFactory getArrayConverterFactory()
          Get the backing ArrayConverterFactory
static void main(java.lang.String[] args)
          Method that has test and sample usage code
 boolean overWriteExistingArray()
          Returns true if an array will not be allocated to hold the converted results, and false otherwise
 void removeColConverter(int colNum)
          Remove the column converter for the specified column
 void removeColConverter(java.lang.String colName)
          Remove the column converter for the specified column
 void removeTypeConverter(java.lang.Class type)
          Remove the Converter for the specified data type
 void setArrayConverterFactory(ArrayConverterFactory factory)
          Set the factory that will be used to determine which Converters to create
 void setArrayHeaderLocator(ArrayHeaderLocator headerLocator)
          Specify the ArrayHeaderLocator object that maps column names to column numbers.
 void setArrayHeaderLocator(java.lang.String[] header)
          Set the ArrayHeaderLocator by passing in an array representing the column names
 void setColConverter(int colNum, Converter converter)
          Set the column Converter to be used for a particular column number.
 void setColConverter(java.lang.String colName, Converter converter)
          Set the column Converter to be used for a particular column name.
 void setDefaultConverter(Converter converter)
          Set the default Converter that will be used if no other matches are found
 void setOverWriteExistingArray(boolean overWriteExistingArray)
          If the contents of the original array are no longer needed then ArrayConverter will not allocate memory and will instead reuse the original data's array.
 void setTypeConverter(java.lang.Class type, Converter converter)
          Set the column coverter to be used for the specified datatype.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ArrayConverter

public ArrayConverter()
Creates a new instance of ArrayConverter


ArrayConverter

public ArrayConverter(java.lang.String[] header)
Creates a new instance of ArrayConverter and allows you to use colnames from a header when setting column converters.


ArrayConverter

public ArrayConverter(boolean overWriteExistingArray)
Creates a new instance of ArrayConverter and when convert is called if true is passed the array passed into the convert method will be used in place to contain the resulting data, thus saving the the array creation for the output. If false is passed the array will be created. false is also the default value if a boolean isn't provided. Remember because Converters can change the type of an Object (say from Date to String) the original array must be type compatible if it is used for output.


ArrayConverter

public ArrayConverter(java.lang.String[] header,
                      boolean overWriteExistingArray)
Creates an instance that allows for column converters to be set by name, and allows the developer to indicate whether they want the output array to be the original array or not

Method Detail

convert

public java.lang.Object[][] convert(java.lang.String[] header,
                                    java.lang.Object[][] data)
This method 'Converts' the data in the input array. It can either put the output in the input array or create a new array depending on how this ArrayConverter object is configured. Use this signature if the column names have changed position. Note this does not change the ArrayHeaderLocator instance variable.


convert

public java.lang.Object[][] convert(java.lang.Object[][] data)
This method 'Converts' the data in the input array. It can either put the output in the input array or create a new array depending on how this ArrayConverter object is configured. Use this signature when either the location of the column name is the same as when this instances ArrayHeaderLocator indicates or no converters by column name have been specified


convert

public java.lang.Object[][] convert(ArrayHeaderLocator arrayHeaderLocator,
                                    java.lang.Object[][] data)
This method 'Converts' the data in the input array. It can either put the output in the input array or create a new array depending on how this ArrayConverter object is configured. Use this signature if the column names have changed position. Note this does not change the ArrayHeaderLocator instance variable.


setOverWriteExistingArray

public void setOverWriteExistingArray(boolean overWriteExistingArray)
If the contents of the original array are no longer needed then ArrayConverter will not allocate memory and will instead reuse the original data's array. This happens when true is passed to this routine. Note the converted objects and input array must be of compatible types if you set this to true or you will get an exception. Object[][] arrays are always type compatible.


overWriteExistingArray

public boolean overWriteExistingArray()
Returns true if an array will not be allocated to hold the converted results, and false otherwise


setDefaultConverter

public void setDefaultConverter(Converter converter)
Set the default Converter that will be used if no other matches are found


setColConverter

public void setColConverter(int colNum,
                            Converter converter)
Set the column Converter to be used for a particular column number. colNum uses array indexing which starts at 0 as opposed to 1. Column converters have the highest precedence column number and column name Converters have equal precedence and when they conflict the last one that was executed wins.


removeColConverter

public void removeColConverter(int colNum)
Remove the column converter for the specified column


setColConverter

public void setColConverter(java.lang.String colName,
                            Converter converter)
Set the column Converter to be used for a particular column name. This name will be used to match Converters to columns of the same name. Column converters have the highest precedence column number and column name Converters have equal precedence and when they conflict the last one that was executed wins. *


removeColConverter

public void removeColConverter(java.lang.String colName)
Remove the column converter for the specified column


setTypeConverter

public void setTypeConverter(java.lang.Class type,
                             Converter converter)
Set the column coverter to be used for the specified datatype. Note column converters have over type Converters


removeTypeConverter

public void removeTypeConverter(java.lang.Class type)
Remove the Converter for the specified data type


setArrayConverterFactory

public void setArrayConverterFactory(ArrayConverterFactory factory)
Set the factory that will be used to determine which Converters to create


getArrayConverterFactory

public ArrayConverterFactory getArrayConverterFactory()
Get the backing ArrayConverterFactory


clone

public java.lang.Object clone()
Make a clone of the ArrayConverter

Overrides:
clone in class java.lang.Object

copy

public ArrayConverter copy()
Clones the ArrayConverter and then casts it to the appropriate type


setArrayHeaderLocator

public void setArrayHeaderLocator(ArrayHeaderLocator headerLocator)
Specify the ArrayHeaderLocator object that maps column names to column numbers. This is not required if you don't specify Converters by column name


setArrayHeaderLocator

public void setArrayHeaderLocator(java.lang.String[] header)
Set the ArrayHeaderLocator by passing in an array representing the column names


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
Method that has test and sample usage code

java.lang.Exception