goodslib
Class ArrayOfBoolean

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

public class ArrayOfBoolean
extends AnyArray

ArrayOfBoolean is just that, an array of booleans. For efficiency they are stored in a byte[] internally.

See Also:
Serialized Form

Field Summary
protected  byte[] array
          array holds the booleans in a byte []
 
Fields inherited from class goodslib.AnyArray
used
 
Fields inherited from class goodsjpi.Persistent
defaultMetaobject, metaobject
 
Constructor Summary
ArrayOfBoolean(boolean[] src)
          Creates a new ArrayOfBoolean instance, as a copy of the given boolean[]
ArrayOfBoolean(int size)
          Creates a new ArrayOfBoolean instance.
ArrayOfBoolean(int size, int allocatedSize)
          Creates a new ArrayOfBoolean instance.
 
Method Summary
 void append(boolean[] 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, boolean[] src, int srcIndex, int count)
          copy into this array from a destination, a given amount of values.
 boolean getAt(int index)
          Get a boolean at the specified index
 int indexOf(boolean val)
          indexOf returns the first occurrence of val
 void insert(int index, int count, boolean value)
          insert a "count" amount of values at a given index.
 int lastIndexOf(boolean val)
          Find the lastIndexOf a given value
 boolean pop()
          Use the array as a stack and pop a value.
 void push(boolean value)
          Use the array as a stack with the push method.
 void putAt(int index, boolean value)
          Put a boolean value at a given index
 void remove(int index, int count)
          remove a number of values.
 boolean[] toArray()
          toArray makes a Java boolean[] out of the values.
 boolean top()
          Check the top boollean 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 byte[] array
array holds the booleans in a byte []

Constructor Detail

ArrayOfBoolean

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

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

ArrayOfBoolean

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

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

ArrayOfBoolean

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

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

putAt

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

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

getAt

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

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

changeSize

public void changeSize(int newSize)
Resize the amount of space taken by the array. Either grow or shrink as neccessary. 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,
                   boolean 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 boolean 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(boolean value)
Use the array as a stack with the push method.

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

pop

public boolean 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 boolean value

top

public boolean top()
Check the top boollean 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 boolean value

append

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

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

toArray

public boolean[] toArray()
toArray makes a Java boolean[] out of the values. Internally they are stored in a byte[] for space efficiency

Returns:
the array as a boolean[]

copy

public void copy(int dstIndex,
                 boolean[] 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 boolean[] , where to copy from
srcIndex - an int , where to start copying from
count - an int , how many values to copy

indexOf

public int indexOf(boolean val)
indexOf returns the first occurrence of val

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

lastIndexOf

public int lastIndexOf(boolean val)
Find the lastIndexOf a given value

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