goodslib
Class ArrayOfChar

java.lang.Object
  extended bygoodsjpi.Persistent
      extended bygoodslib.AnyArray
          extended bygoodslib.ArrayOfChar
All Implemented Interfaces:
java.lang.Comparable, java.io.Serializable
Direct Known Subclasses:
PersistentString

public class ArrayOfChar
extends AnyArray
implements java.lang.Comparable

ArrayOfChar is just that, an array of chars. 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  char[] array
          array holds the chars in an []
 
Fields inherited from class goodslib.AnyArray
used
 
Fields inherited from class goodsjpi.Persistent
defaultMetaobject, metaobject
 
Constructor Summary
ArrayOfChar(char[] src)
          Creates a new ArrayOfChar instance, as a copy of the given char[]
ArrayOfChar(int size)
          Creates a new ArrayOfChar instance.
ArrayOfChar(int size, int allocatedSize)
          Creates a new ArrayOfChar instance.
ArrayOfChar(java.lang.String str)
          Creates a new ArrayOfChar instance.
 
Method Summary
 void append(char[] tail)
          append add the given values to the end of the array
 void append(java.lang.String tail)
          append the given String at the end
 void changeSize(int newSize)
          Resize the amount of space taken by the array.
 int compare(ArrayOfChar a)
          compare compares two object.
 int compare(java.lang.String s)
          compare works like the compare(ArrayOfChar)
 int compareTo(java.lang.Object o)
          compareTo calls the other compare functions, depending on the given object
 void copy(int dstIndex, char[] src, int srcIndex, int count)
          copy into this array from a destination, a given amount of values.
 boolean equals(java.lang.Object obj)
          equals checks whether the given object is equivalent to this.
 char getAt(int index)
          Get a char at the specified index
 int hashCode()
          Return a hashCode
 int indexOf(char ch)
          indexOf returns the first occurrence of val
 void insert(int index, int count, char value)
          insert a "count" amount of values at a given index.
 int lastIndexOf(char ch)
          Find the lastIndexOf a given value
 char pop()
          Use the array as a stack and pop a value.
 void push(char value)
          Use the array as a stack with the push method.
 void putAt(int index, char value)
          Put a char value at a given index
 void remove(int index, int count)
          remove a number of values.
 char[] toArray()
          toArray converts the internal representation to a char[] , of correct size.
 char top()
          Check the top boolean with the top method.
 java.lang.String toString()
          toString makes a String out of the bytes
 
Methods inherited from class goodslib.AnyArray
length
 
Methods inherited from class goodsjpi.Persistent
attachToStorage, clone, clusterWith, finalize, getDatabase, getOid, getStorageId, onLoad
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

array

protected char[] array
array holds the chars in an []

Constructor Detail

ArrayOfChar

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

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

ArrayOfChar

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

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

ArrayOfChar

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

Parameters:
src - a char[] that will be copied

ArrayOfChar

public ArrayOfChar(java.lang.String str)
Creates a new ArrayOfChar instance.

Parameters:
str - a String value
Method Detail

putAt

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

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

getAt

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

Parameters:
index - of the char you want
Returns:
a char 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,
                   char 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 char 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(char value)
Use the array as a stack with the push method.

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

pop

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

top

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

append

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

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

append

public void append(java.lang.String tail)
append the given String at the end

Parameters:
tail - a String value

toArray

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

Returns:
a char[] value

toString

public java.lang.String toString()
toString makes a String out of the bytes

Returns:
a String representation of the bytes

copy

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

compareTo

public int compareTo(java.lang.Object o)
compareTo calls the other compare functions, depending on the given object

Specified by:
compareTo in interface java.lang.Comparable
Parameters:
o - an Object to compare against
Returns:
an int , the result

compare

public int compare(java.lang.String s)
compare works like the compare(ArrayOfChar)

Parameters:
s - a String value to compare against
Returns:
an int , the result

compare

public int compare(ArrayOfChar a)
compare compares two object. In that it works like the equals method. But compare returns more than just a boolean yes/no, it also introduces an ordering between the objects.

Parameters:
a - ArrayOfChar to compare against
Returns:
an int , 0 if equal, negative if the object is smaller and positive if it is bigger.

hashCode

public int hashCode()
Return a hashCode

Overrides:
hashCode in class Persistent
Returns:
an int value, the hash

equals

public boolean equals(java.lang.Object obj)
equals checks whether the given object is equivalent to this. Ie. If it has the same data representation. It does not have to be the same, which is checked by == operator.

Parameters:
obj - an Object to check
Returns:
a boolean indicating whether obj is equivalent

indexOf

public int indexOf(char ch)
indexOf returns the first occurrence of val

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

lastIndexOf

public int lastIndexOf(char ch)
Find the lastIndexOf a given value

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