com.phoenix_int.aserver.types
Class PHXSimpleArray

java.lang.Object
  extended by com.phoenix_int.aserver.types.PHXSimpleType
      extended by com.phoenix_int.aserver.types.PHXSimpleArray
All Implemented Interfaces:
IPHXType, IPHXType2, IPHXUnits
Direct Known Subclasses:
PHXBooleanArray, PHXDoubleArray, PHXLongArray, PHXObjectArray, PHXRawFileArray, PHXStringArray

public abstract class PHXSimpleArray
extends PHXSimpleType
implements IPHXType2

This class enables components to create resizeable arrays where the number of dimensions is variable as well as the size of each dimension.

Typically you don't use this class directly but one of its sub-classes that are created and passed to you automatically.


Field Summary
protected  java.lang.Object _data
           
protected  boolean _lockDims
           
protected  boolean _lockResize
           
 
Constructor Summary
protected PHXSimpleArray(java.lang.Object data)
          Constructs a PHXSimpleArray that wraps a particular Analysis Server style variable.
 
Method Summary
protected  void _getMetaData()
          Gets the meta data off of the first element of the array and sets it into our meta data info.
protected  void _getMetaData(PHXSimpleType v)
          Worker which takes the meta data from an instance of PHXSimpleType and sets it into our meta data.
protected  void _setMetaData()
          Call this function to set the meta data from this object into every element of the array.
protected  void _setMetaData(PHXSimpleType v)
          Sets a simple type's meta data based on the meta data in this object.
protected  java.lang.Object allocateElement(java.lang.Class elementClass)
          Allocates a single element in a default state.
static boolean checkRectangular(java.lang.Object obj)
          Check if the array is rectangular
protected abstract  boolean dataTypeOK(java.lang.Class c)
          Must override this function and return true if the specified class is acceptable as an array element component type.
protected abstract  java.lang.Object elementFromString(java.lang.String value)
          Sub-classes must provide an implementation of this function which converts a string form of a single element to Object form.
 void fromString(int[] index, PHXStringBuffer value)
          Sets the value of a single element based on string input.
 void fromString(int[] index, java.lang.String value)
          Sets the value of a single element based on string input.
 void fromString(int index, java.lang.String value)
          Sets the value of a single element based on string input for 1-d arrays.
 void fromString(java.lang.String in)
          reads in the entire array in string form.
 void fromString2(PHXStringBuffer in)
          reads in the entire array in string form.
static PHXSimpleArray generateFor(java.lang.Object o)
          Static method to generate a new instance of one of the sub-classes of PHXSimpleArray as appropriate for the type of variable passed in.
static PHXSimpleArray generateFor(java.lang.Object o, java.lang.Class c)
          Static method to generate a new instance of one of the sub-classes of PHXSimpleArray as appropriate for the type of variable passed in.
 java.lang.Object getArray()
          Gets the entire contents of the array
 java.lang.Object getArrayElement(int index)
          Gets a particular element from a 1-d array
 java.lang.Object getArrayElement(int[] index)
          Gets a particular element from the array
 java.lang.Class getComponentType()
          Returns the component type of the array wrapped with this class
static java.lang.Class getComponentType(java.lang.Object v)
          Gets the component type of an array, even for n-d arrays.
 int[] getDimensions()
           
static int[] getDimensions(java.lang.Object array)
          Gets the array of dimensions of the array
 java.lang.Object getFirst()
          Returns the first element of the array, or throws ArrayIndexOutOfBounds if there are no elements.
 int getLength()
          Gets the length of the first dimension of the array
 int getLength(int dim)
          Gets the length of a dimension of the array
 boolean getLockResize()
           
protected  int[] getnDIndex(long oneDIndex, int[] actualSize)
           
 int getNumDimensions()
          Gets the number of dimensions of the array
static int getNumDimensions(java.lang.Object o)
           
 PHXSimpleArray getSelf()
           
static boolean incrementIndex(int[] index, int[] size)
          Utility function for incrementing an nD index on the array
 void lockDimensions()
          Tells this array that the number of dimensions cannot be changed from what they are right now.
 int[] newIndex()
          Produces a new index based zeroed out, but with the proper dimensions
static int[] parseIndex(java.lang.String index)
          Takes a string of the form "anything[n, n2, n3]" or "n, n2, n3" and returns an int[] of the index values.
 void resize(int[] newSize)
          Resize the nD array to the new size specified.
 void setArray(java.lang.Object v)
          Sets the entire array.
 void setArrayElement(int[] index, java.lang.Object v)
          Sets a particular element of the array
 void setArrayElement(int index, java.lang.Object v)
          Sets a particular element of a 1-d array
 void setDimensions(int[] dim)
          Sets the dimensions of the array.
 void setFirst(java.lang.Object val)
          Sets the first element of the array, or throws ArrayIndexOutOfBounds if there are no elements.
 void setLength(int len)
          Sets the length of the first dimension of the array.
 void setLength(int len, int dim)
          Sets the length of a dimensions of the array.
 void setLockResize(boolean lockResize)
          Tells this array that it cannot be resized.
 java.lang.String toString()
          Returns the string form of this array.
 java.lang.String toString(int index)
          Converts a single element of a 1-d array to a string
 java.lang.String toString(int[] index)
          Converts a single element to a string
 java.lang.String toString(java.lang.String index)
          Converts a single element to a string
 PHXStringBuffer toString2()
          Returns the string form of this array.
 PHXStringBuffer toString2(int[] index)
          Converts a single element to a string
 PHXStringBuffer toString2(java.lang.String index)
          Converts a single element to a string
 boolean validElement(int[] index, int[] size)
          Is the given index valid?
 
Methods inherited from class com.phoenix_int.aserver.types.PHXSimpleType
addPropertyChangeListener, getDescription, getEnumTokens, getHasChanged, getUnits, removePropertyChangeListener, setDescription, setHasChanged, setUnits
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_data

protected java.lang.Object _data

_lockDims

protected boolean _lockDims

_lockResize

protected boolean _lockResize
Constructor Detail

PHXSimpleArray

protected PHXSimpleArray(java.lang.Object data)
Constructs a PHXSimpleArray that wraps a particular Analysis Server style variable.

Parameters:
v - The Analysis Server variable to wrap, which must be an array.
Method Detail

lockDimensions

public void lockDimensions()
Tells this array that the number of dimensions cannot be changed from what they are right now.


setLockResize

public void setLockResize(boolean lockResize)
Tells this array that it cannot be resized. Implies lockDimensions.


getLockResize

public boolean getLockResize()

_getMetaData

protected void _getMetaData()
Gets the meta data off of the first element of the array and sets it into our meta data info. Call this from base classes in the constructor and after anything that might change the meta information on the first array element.


_getMetaData

protected void _getMetaData(PHXSimpleType v)
Worker which takes the meta data from an instance of PHXSimpleType and sets it into our meta data. Override this in order to add more custom meta data in sub-classes. Be sure to cal super._getMetaData(PHXSimpleType), though!


dataTypeOK

protected abstract boolean dataTypeOK(java.lang.Class c)
Must override this function and return true if the specified class is acceptable as an array element component type.


resize

public void resize(int[] newSize)
            throws java.lang.IllegalAccessException,
                   java.lang.InstantiationException
Resize the nD array to the new size specified. Preserve elements if the # of dimensions stays the same, else initialize the array with default values.

Parameters:
newSize - the new dimensions for the array
Throws:
java.lang.IllegalAccessException
java.lang.InstantiationException

getFirst

public java.lang.Object getFirst()
Returns the first element of the array, or throws ArrayIndexOutOfBounds if there are no elements.


setFirst

public void setFirst(java.lang.Object val)
Sets the first element of the array, or throws ArrayIndexOutOfBounds if there are no elements.


getLength

public int getLength()
Gets the length of the first dimension of the array


getLength

public int getLength(int dim)
Gets the length of a dimension of the array

Parameters:
dim - the dimension of interest
Returns:
the size of the dimension

setLength

public void setLength(int len)
               throws java.lang.IllegalAccessException,
                      java.lang.InstantiationException
Sets the length of the first dimension of the array. Will preserve as many element values as possible.

Parameters:
len - the new length of the 1D array
Throws:
java.lang.IllegalArgumentException - thrown if arguments are incorrect or don't jive with the current array
java.lang.IllegalAccessException
java.lang.InstantiationException

setLength

public void setLength(int len,
                      int dim)
               throws java.lang.IllegalAccessException,
                      java.lang.InstantiationException
Sets the length of a dimensions of the array. You may grow the array by 1 dimension if 'dim' is the next dim that needs defining. You may shorten the array by passing in 'len' < 0 and 'dim' as the first dimension after the valid dimensions.

Parameters:
len - the new length of the dimension.
dim - the dimension to change
Throws:
java.lang.IllegalArgumentException - thrown if arguments are incorrect or don't jive with the current array
java.lang.IllegalAccessException
java.lang.InstantiationException

getDimensions

public static int[] getDimensions(java.lang.Object array)
Gets the array of dimensions of the array

Returns:
the array with the dimensions

getDimensions

public int[] getDimensions()

setDimensions

public void setDimensions(int[] dim)
                   throws java.lang.IllegalAccessException,
                          java.lang.InstantiationException
Sets the dimensions of the array. Will preserve as many element values as possible.

Parameters:
dim - the new dimensions for the array
Throws:
java.lang.IllegalAccessException
java.lang.InstantiationException

getNumDimensions

public static int getNumDimensions(java.lang.Object o)

getNumDimensions

public int getNumDimensions()
Gets the number of dimensions of the array


fromString

public void fromString(int index,
                       java.lang.String value)
Sets the value of a single element based on string input for 1-d arrays. Data is converted as appropriate.

Parameters:
index - Which element to set.
value - The new value.

fromString

public void fromString(int[] index,
                       PHXStringBuffer value)
Sets the value of a single element based on string input. Data is converted as appropriate.

Parameters:
index - Which element to set.
value - The new value.

fromString

public void fromString(int[] index,
                       java.lang.String value)
Sets the value of a single element based on string input. Data is converted as appropriate.

Parameters:
index - Which element to set.
value - The new value.

elementFromString

protected abstract java.lang.Object elementFromString(java.lang.String value)
Sub-classes must provide an implementation of this function which converts a string form of a single element to Object form. This is only used when the element type does not implement IPHXType or IPHXType2. For primitives, return the wrapper objects.


toString

public java.lang.String toString(int index)
Converts a single element of a 1-d array to a string

Parameters:
index - the index of the desired element
Returns:
the desired element, in string form

parseIndex

public static int[] parseIndex(java.lang.String index)
Takes a string of the form "anything[n, n2, n3]" or "n, n2, n3" and returns an int[] of the index values.


toString

public java.lang.String toString(java.lang.String index)
Converts a single element to a string

Parameters:
index - the index of the desired element
Returns:
the desired element, in string form

toString2

public PHXStringBuffer toString2(java.lang.String index)
                          throws java.io.IOException
Converts a single element to a string

Parameters:
index - the index of the desired element
Returns:
the desired element, in string form
Throws:
java.io.IOException

toString

public java.lang.String toString(int[] index)
Converts a single element to a string

Parameters:
index - the index of the desired element
Returns:
the desired element, in string form

toString2

public PHXStringBuffer toString2(int[] index)
                          throws java.io.IOException
Converts a single element to a string

Parameters:
index - the index of the desired element
Returns:
the desired element, in string form
Throws:
java.io.IOException

getArrayElement

public java.lang.Object getArrayElement(int index)
Gets a particular element from a 1-d array

Parameters:
index - the 1D array index into the 1D array
Returns:
the specified element
Throws:
java.lang.IllegalArgumentException - thrown if 1D reference is given to a >1D array

getArrayElement

public java.lang.Object getArrayElement(int[] index)
Gets a particular element from the array

Parameters:
index - the 1D array index into the 1D array
Returns:
the specified element
Throws:
java.lang.IllegalArgumentException - thrown if 1D reference is given to a >1D array

setArrayElement

public void setArrayElement(int index,
                            java.lang.Object v)
Sets a particular element of a 1-d array

Parameters:
index - Which index to set
v - The new value. Note that this takes an instance of a PHXType.

setArrayElement

public void setArrayElement(int[] index,
                            java.lang.Object v)
Sets a particular element of the array

Parameters:
index - Which index to set
v - The new value. Note that this takes an instance of a PHXType.

getArray

public java.lang.Object getArray()
Gets the entire contents of the array

Returns:
the base array object

setArray

public void setArray(java.lang.Object v)
Sets the entire array. Array is checked for validity and rectangularity. _getMetaData() is called.

Parameters:
v - the new array (nD)
Throws:
java.lang.IllegalArgumentException - thrown if array passed in is not rectangular

getSelf

public PHXSimpleArray getSelf()

checkRectangular

public static boolean checkRectangular(java.lang.Object obj)
Check if the array is rectangular

Parameters:
obj - the array to check
Returns:
is the array rectangular?
Throws:
java.lang.NullPointerException - thrown if one of the values in the array is null

getComponentType

public static java.lang.Class getComponentType(java.lang.Object v)
Gets the component type of an array, even for n-d arrays.

Parameters:
v - The array to get the component type for

getComponentType

public java.lang.Class getComponentType()
Returns the component type of the array wrapped with this class


generateFor

public static PHXSimpleArray generateFor(java.lang.Object o)
                                  throws java.lang.IllegalArgumentException
Static method to generate a new instance of one of the sub-classes of PHXSimpleArray as appropriate for the type of variable passed in.

Throws:
java.lang.IllegalArgumentException

generateFor

public static PHXSimpleArray generateFor(java.lang.Object o,
                                         java.lang.Class c)
                                  throws java.lang.IllegalArgumentException
Static method to generate a new instance of one of the sub-classes of PHXSimpleArray as appropriate for the type of variable passed in. If 'o' is null, a new 0 length array will be generated based on 'c' as the component type.

Throws:
java.lang.IllegalArgumentException

fromString

public void fromString(java.lang.String in)
reads in the entire array in string form.

bounds[3,2] { 1,2,3,4,5,6 }

Specified by:
fromString in interface IPHXType
Parameters:
in - the value of the variable

fromString2

public void fromString2(PHXStringBuffer in)
reads in the entire array in string form.

bounds[3,2] { 1,2,3,4,5,6 }

Specified by:
fromString2 in interface IPHXType2

toString

public java.lang.String toString()
Returns the string form of this array. Puts each element in quotes, even if it is a number and backslashes any quote or backslash characters (" and \).

Specified by:
toString in interface IPHXType
Overrides:
toString in class java.lang.Object
Returns:
the value as a String

toString2

public PHXStringBuffer toString2()
Returns the string form of this array. Puts each element in quotes, even if it is a number and backslashes any quote or backslash characters (" and \).

Specified by:
toString2 in interface IPHXType2

incrementIndex

public static boolean incrementIndex(int[] index,
                                     int[] size)
Utility function for incrementing an nD index on the array

Parameters:
index - the index to increment
size - the maximum size of the array
Returns:
did the incrment work?
Throws:
java.lang.IllegalArgumentException - thrown if index lengths don't match

newIndex

public int[] newIndex()
Produces a new index based zeroed out, but with the proper dimensions

Returns:
the new index

validElement

public boolean validElement(int[] index,
                            int[] size)
Is the given index valid?

Parameters:
index - the index to check
size - the maximum size
Returns:
is the given index valid?

allocateElement

protected java.lang.Object allocateElement(java.lang.Class elementClass)
                                    throws java.lang.IllegalAccessException,
                                           java.lang.InstantiationException
Allocates a single element in a default state. If the class type in question has a default constructor, there is no need to override this.

Throws:
java.lang.IllegalAccessException
java.lang.InstantiationException

_setMetaData

protected void _setMetaData(PHXSimpleType v)
Sets a simple type's meta data based on the meta data in this object. Override this to set additional information in sub-classes. Be sure to call super._setMetaData(PHXSimpleType)


_setMetaData

protected void _setMetaData()
Call this function to set the meta data from this object into every element of the array.


getnDIndex

protected int[] getnDIndex(long oneDIndex,
                           int[] actualSize)
                    throws java.lang.IllegalArgumentException
Throws:
java.lang.IllegalArgumentException