jumbo.euclid
Class ObjectArray

java.lang.Object
  |
  +--jumbo.euclid.Status
        |
        +--jumbo.euclid.ObjectArray

public class ObjectArray
extends Status

ObjectArray - array of Objects.

ObjectArray represents a 1-dimensional vector/array of Objects, and is used in SpreadSheets, etc. The class is designed with the idea that all Objects are of the same type, but this is not enforced, and you may wish to experiment.

There is provision for 2 homegenous arrays, INT and REAL , for compatibility with RealArray and IntArray In some cases the type of the Object (e.g. integer) might lead to additional features.

It can be sorted if all Objects are of type Sortable.

Hacked from RealArray - it shares a number of functions.


Field Summary
static int INT
           
static int OBJECT
           
static int REAL
           
 
Constructor Summary
ObjectArray()
          default is an array of zero points
ObjectArray(int n)
          creates n-element array initialised to null
ObjectArray(IntArray ia)
          convert an IntArray to a ObjectArray
ObjectArray(int n, java.lang.Object elem1)
          set all elements of the array to a given Object
ObjectArray(ObjectArray m)
          copy constructor
ObjectArray(ObjectArray m, int low, int high)
          subarray of another array - inclusive; if low > high or other silly indices, creates default array
ObjectArray(RealArray ra)
          convert an RealArray to a ObjectArray
 
Method Summary
 void addArray(ObjectArray f)
          append elements
 void addElement(java.lang.Object f)
          append element
 void clearArray()
          clear all elements of array to null (or 0 or 0.0)
static java.lang.Object[] copy(java.lang.Object[] f)
          copy a Object[] into a new one
 void deleteElement(int elem)
          delete element and close up; if outside range, take no action
 void deleteElements(int low, int high)
          delete elements and close up; if outside range take no action
 java.lang.Object elementAt(int elem)
          extracts a given element from the array
 boolean equals(ObjectArray f)
          are two arrays equal in all elements?
 java.lang.Object[] getArray()
          return the array as a Object[]; this has to resize the array to the precise length used , or confusion will result! Note that this gives the user access to the actual array, so that they can alter its contents.
 IntArray getIntArray()
          return contents as a IntArray if INT, else null
 java.lang.Class getObjectClass()
          get the Class of the objects, if this is common to all, else null.
 int getObjectType()
          get the type of the Objects as INT, etc
 RealArray getRealArray()
          return contents as a RealArray if REAL , else null
 ObjectArray getReorderedArray(IntSet idx)
          reorder by index in IntSet; does NOT modify array
 java.lang.Object[] getReverseArray()
          return the elements in reverse order as Object[]
 java.lang.String[] getStringValues()
          returns values as strings
 ObjectArray getSubArray(int start, int end)
          RHS: get a subObjectArray from element start to end
 IntSet indexSortAscending()
           
 IntSet indexSortDescending()
          sort array into descending order via indexes; array NOT MODIFIED
 void insertArray(int elem, ObjectArray f)
          insert a ObjectArray at position elem and expand
 void insertElementAt(int elem, java.lang.Object f)
          insert element and expand; if outside range, take no action
 boolean isHomogeneous()
           
static void main(java.lang.String[] args)
           
 void reverse()
          MODIFIES ObjectArray to be in reverse order
 void setElementAt(int elem, java.lang.Object f)
          set a given element into the array; must be less than current max index
 void setElements(int start, java.lang.Object[] a)
          copy a smaller array into the array statrting at start
 void setMaxIndex(int max)
          reset the maximum index (for when poking elements) (no other effect)
 void shallowCopy(ObjectArray m)
          shallowCopy
 int size()
          get actual number of elements
 void sortAscending()
          MODIFIES ObjectArray to be in ascending order
 void sortDescending()
          MODIFIES ObjectArray to be in descending order
 java.lang.String toString()
          concatenates values with spaces
 
Methods inherited from class jumbo.euclid.Status
NYI
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

OBJECT

public static final int OBJECT

INT

public static final int INT

REAL

public static final int REAL
Constructor Detail

ObjectArray

public ObjectArray()
default is an array of zero points

ObjectArray

public ObjectArray(int n)
creates n-element array initialised to null

ObjectArray

public ObjectArray(int n,
                   java.lang.Object elem1)
set all elements of the array to a given Object

ObjectArray

public ObjectArray(IntArray ia)
convert an IntArray to a ObjectArray

ObjectArray

public ObjectArray(RealArray ra)
convert an RealArray to a ObjectArray

ObjectArray

public ObjectArray(ObjectArray m,
                   int low,
                   int high)
subarray of another array - inclusive; if low > high or other silly indices, creates default array

ObjectArray

public ObjectArray(ObjectArray m)
copy constructor
Method Detail

getObjectClass

public java.lang.Class getObjectClass()
get the Class of the objects, if this is common to all, else null. some of the elements can be null (i.e. 'missing')

isHomogeneous

public boolean isHomogeneous()

getObjectType

public int getObjectType()
get the type of the Objects as INT, etc

shallowCopy

public void shallowCopy(ObjectArray m)
shallowCopy

elementAt

public java.lang.Object elementAt(int elem)
                           throws java.lang.ArrayIndexOutOfBoundsException
extracts a given element from the array
Throws:
java.lang.ArrayIndexOutOfBoundsException - elem >= size of this

size

public int size()
get actual number of elements

getArray

public java.lang.Object[] getArray()
return the array as a Object[]; this has to resize the array to the precise length used , or confusion will result! Note that this gives the user access to the actual array, so that they can alter its contents. This should be used with care, but Java should stop any access outside the buffer limits.

getRealArray

public RealArray getRealArray()
return contents as a RealArray if REAL , else null

getIntArray

public IntArray getIntArray()
return contents as a IntArray if INT, else null

clearArray

public void clearArray()
clear all elements of array to null (or 0 or 0.0)

getReverseArray

public java.lang.Object[] getReverseArray()
return the elements in reverse order as Object[]

setMaxIndex

public void setMaxIndex(int max)
reset the maximum index (for when poking elements) (no other effect)

equals

public boolean equals(ObjectArray f)
               throws UnequalArraysException
are two arrays equal in all elements?
Throws:
UnequalArraysException - f is different size from this

setElementAt

public void setElementAt(int elem,
                         java.lang.Object f)
                  throws java.lang.ArrayIndexOutOfBoundsException
set a given element into the array; must be less than current max index
Throws:
java.lang.ArrayIndexOutOfBoundsException - elem >= size of this

getSubArray

public ObjectArray getSubArray(int start,
                               int end)
RHS: get a subObjectArray from element start to end

setElements

public void setElements(int start,
                        java.lang.Object[] a)
copy a smaller array into the array statrting at start

deleteElement

public void deleteElement(int elem)
delete element and close up; if outside range, take no action

deleteElements

public void deleteElements(int low,
                           int high)
delete elements and close up; if outside range take no action

insertElementAt

public void insertElementAt(int elem,
                            java.lang.Object f)
insert element and expand; if outside range, take no action

insertArray

public void insertArray(int elem,
                        ObjectArray f)
insert a ObjectArray at position elem and expand

addElement

public void addElement(java.lang.Object f)
append element

addArray

public void addArray(ObjectArray f)
append elements

getReorderedArray

public ObjectArray getReorderedArray(IntSet idx)
                              throws BadSubscriptException
reorder by index in IntSet; does NOT modify array
Throws:
BadSubscriptException - an element of idx is outside range of this

getStringValues

public java.lang.String[] getStringValues()
returns values as strings

toString

public java.lang.String toString()
concatenates values with spaces
Overrides:
toString in class java.lang.Object

copy

public static java.lang.Object[] copy(java.lang.Object[] f)
copy a Object[] into a new one

sortAscending

public void sortAscending()
MODIFIES ObjectArray to be in ascending order

sortDescending

public void sortDescending()
MODIFIES ObjectArray to be in descending order

reverse

public void reverse()
MODIFIES ObjectArray to be in reverse order

indexSortAscending

public IntSet indexSortAscending()

indexSortDescending

public IntSet indexSortDescending()
sort array into descending order via indexes; array NOT MODIFIED

main

public static void main(java.lang.String[] args)