goodslib
Class ArrayOfObject

java.lang.Object
  extended bygoodsjpi.Persistent
      extended bygoodslib.AnyArray
          extended bygoodslib.ArrayOfObject
All Implemented Interfaces:
java.io.Serializable

public class ArrayOfObject
extends AnyArray

ArrayOfObject is just that, an array of Persistents. It is fully persistent, as it it's derived from Persistent. All reads cause a fetch of the data, all writes mark it dirty and to be saved.

See Also:
Serialized Form

Field Summary
protected  Persistent[] array
          array holds the Persistents in an []
 
Fields inherited from class goodslib.AnyArray
used
 
Fields inherited from class goodsjpi.Persistent
defaultMetaobject, metaobject
 
Constructor Summary
ArrayOfObject(int size)
          Creates a new ArrayOfObject instance.
ArrayOfObject(int size, int allocatedSize)
          Creates a new ArrayOfObject instance.
ArrayOfObject(Persistent[] src)
          Creates a new ArrayOfObject instance, as a copy of the given Persistent[]
 
Method Summary
 void append(Persistent[] tail)
          append add the given values to the end of the array
 void changeSize(int newSize)
          Resize the amount of space taken by the array.
 void copy(int dstIndex, Persistent[] src, int srcIndex, int count)
          copy into this array from a destination, a given amount of values.
 Persistent getAt(int index)
          Get a Persistent at the specified index
 int indexOf(Persistent obj)
          indexOf returns the first occurrence of val
 void insert(int index, int count, Persistent value)
          insert a "count" amount of values at a given index.
 int lastIndexOf(Persistent obj)
          Find the lastIndexOf a given value
 Persistent pop()
          Use the array as a stack and pop a value.
 void push(Persistent value)
          Use the array as a stack with the push method.
 void putAt(int index, Persistent value)
          Put a Persistent value at a given index
 void remove(int index, int count)
          remove a number of values.
 Persistent[] toArray()
          toArray converts the internal representation to a Persistent[] , of correct size.
 Persistent top()
          Check the top boolean with the top method.
 
Methods inherited from class goodslib.AnyArray
length
 
Methods inherited from class goodsjpi.Persistent
attachToStorage, clone, clusterWith, finalize, getDatabase, getOid, getStorageId, hashCode, onLoad
 
Methods inherited from class java.lang.Object
equals, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

array

protected Persistent[] array
array holds the Persistents in an []

Constructor Detail

ArrayOfObject

public ArrayOfObject(int size)
Creates a new ArrayOfObject instance.

Parameters:
size - is the initial size, (length)

ArrayOfObject

public ArrayOfObject(int size,
                     int allocatedSize)
Creates a new ArrayOfObject instance. (Full of false)

Parameters:
size - , or length of the array
allocatedSize - is the size it can grow to without re-sizing

ArrayOfObject

public ArrayOfObject(Persistent[] src)
Creates a new ArrayOfObject instance, as a copy of the given Persistent[]

Parameters:
src - a Persistent[] that will be copied
Method Detail

putAt

public void putAt(int index,
                  Persistent value)
Put a Persistent value at a given index

Parameters:
index - an int value, where the value should be set
value - the Persistent value to be set

getAt

public Persistent getAt(int index)
Get a Persistent at the specified index

Parameters:
index - of the Persistent you want
Returns:
a Persistent value, at index "index"

changeSize

public void changeSize(int newSize)
Resize the amount of space taken by the array. Either grow or shrink as necessary. You get an IndexOutOfBoundException for negative values.
of course the old data is copied.

Parameters:
newSize - an int denoting the new size.

insert

public void insert(int index,
                   int count,
                   Persistent value)
insert a "count" amount of values at a given index. Throws an IndexOutOfBoundsException for too small (<0) or too big (>length) count or index.

Parameters:
index - , where to start inserting value(s)
count - , how many values to insert
value - a Persistent value to insert

remove

public void remove(int index,
                   int count)
remove a number of values. The array shrinks in it's length, but no resizing is done. Get an IndexOutOfBoundsException for inappropriate index or count values.

Parameters:
index - , where to start removing
count - , how many values to remove

push

public void push(Persistent value)
Use the array as a stack with the push method.

Parameters:
value - , a Persistent to push to the stack

pop

public Persistent pop()
Use the array as a stack and pop a value. (Value is removed) IndexOutOfBoundsExceptions comes when array has hit 0 length.

Returns:
the top most Persistent value

top

public Persistent top()
Check the top boolean with the top method. This returns what pop returns, just it doesn't remove the value. In other stack implementations it may be called peek()

Returns:
a Persistent value

append

public void append(Persistent[] tail)
append add the given values to the end of the array

Parameters:
tail - a Persistent[] that will be appended

toArray

public Persistent[] toArray()
toArray converts the internal representation to a Persistent[] , of correct size. Ie: the .length of the return == this.size()

Returns:
a Persistent[] value

copy

public void copy(int dstIndex,
                 Persistent[] src,
                 int srcIndex,
                 int count)
copy into this array from a destination, a given amount of values. Get a IndexOutOfBounds if the src or count don't fit

Parameters:
dstIndex - , the index (of this array) where to copy to
src - a Persistent[] , where to copy from
srcIndex - an int , where to start copying from
count - an int , how many values to copy

indexOf

public int indexOf(Persistent obj)
indexOf returns the first occurrence of val

Parameters:
obj - a Persistent to be looked for
Returns:
an int, where the value was found, or -1

lastIndexOf

public int lastIndexOf(Persistent obj)
Find the lastIndexOf a given value

Parameters:
obj - a Persistent value to be found (from the back)
Returns:
an int , where the value was found, or -1