moka.util
Class SerialList

java.lang.Object
  extended bymoka.lang.Object
      extended bymoka.io.Serializable
          extended bymoka.util.SerialList

public class SerialList
extends Serializable

The SerialList class implements a serializable list of serializable elements. Like an array, it contains components that can be accessed using an integer index. However, the size of a SerialList can grow or shrink as needed to accommodate adding and removing items after the SerialList has been created.

Each serializable linked lists tries to optimize storage management by reallocating memory every time the size of the array grows or shrinks.

Since:
MDK1.0a

Field Summary
 int size
          The actual size of the SerialList.
 
Constructor Summary
SerialList()
          Creates a new SerialList.
SerialList(Enumeration enu)
          Creates a new SerialList adding the elements of the specified enumeration.
 
Method Summary
 void add(int index, Serializable o)
          Inserts the specified element at the specified position in this serial list.
 void clear()
          Removes all of the elements from this linked list.
 boolean contains(Serializable o)
          Returns true if this linked list contains the specified element.
 void copyInto(Serializable[] anArray, int fromIndex, int toIndex)
          Copies the components of this linked list into the specified array.
 Serializable dequeue()
          Removes the object at the beginning of this queue and returns that object as the value of this function.
 Enumeration elements()
          Returns an enumeration of the components of this SerialList.
 void enqueue(Serializable item)
          Enqueues an item at the end of this queue.
 void finalize()
          Frees the memory used by this object.
 Serializable get(int index)
          Returns the element at the specified position in this linked list.
 int indexOf(Serializable o)
          Returns the index in this linked list of the first occurrence of the specified element, or -1 if this list does not contain this element.
 int indexOf(Serializable elem, int index)
          Searches for the first occurence of the given argument, beginning the search at index.
 int lastIndexOf(Serializable o)
          Returns the index in this linked list of the last occurrence of the specified element, or -1 if this list does not contain this element.
 int lastIndexOf(Serializable elem, int index)
          Searches backwards for the specified object, starting from the specified index, and returns an index to it.
 Serializable peek()
          Looks at the object at the top of this stack without removing it from the stack.
 Serializable pop()
          Removes the object at the top of this stack and returns that object as the value of this function.
 void push(Serializable item)
          Pushes an item onto the top of this stack.
 Serializable remove(int index)
          Removes the element at the specified position in this linked list.
 boolean remove(Serializable o)
          Removes the first occurrence in this linked list of the specified element.
 Serializable set(int index, Serializable element)
          Replaces the element at the specified position in this linked list with the specified element.
 java.lang.String toString()
          Returns a string representation of this LinkedList, containing the String representation of each element.
 
Methods inherited from class moka.io.Serializable
deserialize, serialize
 
Methods inherited from class moka.lang.Object
equals, getClassName
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

size

public int size
The actual size of the SerialList. Should be only read.

Constructor Detail

SerialList

public SerialList()
Creates a new SerialList.


SerialList

public SerialList(Enumeration enu)
Creates a new SerialList adding the elements of the specified enumeration. These elements should be serializable The enumeration is finalized after this operation.

Method Detail

elements

public Enumeration elements()
Returns an enumeration of the components of this SerialList. The returned Enumeration object will generate all items in this SerialList. The first item generated is the item at index 0, then the item at index 1, and so on.

Returns:
an enumeration of the components of this vector.

add

public void add(int index,
                Serializable o)
Inserts the specified element at the specified position in this serial list. Shifts the element currently at that position (if any) and any subsequent elements to the right (adds one to their indices).

Parameters:
index - index at which the specified element is to be inserted.

push

public void push(Serializable item)
Pushes an item onto the top of this stack.

Parameters:
item - the item to be pushed onto this stack.

enqueue

public void enqueue(Serializable item)
Enqueues an item at the end of this queue.

Parameters:
item - the item to be enqueued.

clear

public void clear()
Removes all of the elements from this linked list. This linked list will be empty after this call returns.


finalize

public void finalize()
Frees the memory used by this object.

Overrides:
finalize in class Object

contains

public boolean contains(Serializable o)
Returns true if this linked list contains the specified element.

Parameters:
o - element whose presence in this linked list is to be tested.
Returns:
true if this linked list contains the specified element.

get

public Serializable get(int index)
Returns the element at the specified position in this linked list.

Parameters:
index - index of element to return.
Returns:
the element at the specified position in this linked list.

indexOf

public int indexOf(Serializable o)
Returns the index in this linked list of the first occurrence of the specified element, or -1 if this list does not contain this element.

Parameters:
o - element to search for.
Returns:
the index in this linked list of the first occurrence of the specified element, or -1 if this linked list does not contain this element.

lastIndexOf

public int lastIndexOf(Serializable o)
Returns the index in this linked list of the last occurrence of the specified element, or -1 if this list does not contain this element.

Parameters:
o - element to search for.
Returns:
the index in this linked list of the last occurrence of the specified element, or -1 if this linked list does not contain this element.

remove

public Serializable remove(int index)
Removes the element at the specified position in this linked list. Shifts any subsequent elements to the left (subtracts one from their indices). Returns the element that was removed from the linked list.

Parameters:
index - the index of the element to removed.
Returns:
the element previously at the specified position.

remove

public boolean remove(Serializable o)
Removes the first occurrence in this linked list of the specified element. If this linked list does not contain the element, it is unchanged.

Parameters:
o - element to be removed from this linked list, if present.
Returns:
true if this linked list contained the specified element.

peek

public Serializable peek()
Looks at the object at the top of this stack without removing it from the stack.

Returns:
the object at the top of this stack (the last item of the LinkedList object).

pop

public Serializable pop()
Removes the object at the top of this stack and returns that object as the value of this function.

Returns:
The object at the top of this stack (the last item of the LinkedList object).

dequeue

public Serializable dequeue()
Removes the object at the beginning of this queue and returns that object as the value of this function.

Returns:
The object at the beginning of this queue (the first item of the LinkedList object).

set

public Serializable set(int index,
                        Serializable element)
Replaces the element at the specified position in this linked list with the specified element.

Parameters:
index - index of element to replace.
element - element to be stored at the specified position.
Returns:
the element previously at the specified position.

copyInto

public void copyInto(Serializable[] anArray,
                     int fromIndex,
                     int toIndex)
Copies the components of this linked list into the specified array. The array must be big enough to hold all the objects copied from this linked list.

Parameters:
anArray - the array into which the components get copied.
fromIndex - the index of the first object in the linked list to copy.
toIndex - the index after the last object in the linked list to copy.

indexOf

public int indexOf(Serializable elem,
                   int index)
Searches for the first occurence of the given argument, beginning the search at index.

Parameters:
elem - an object.
index - the index to start searching from.
Returns:
the index of the first occurrence of the object argument in this linked list at position index or later in the vector or -1 if the object is not found.

lastIndexOf

public int lastIndexOf(Serializable elem,
                       int index)
Searches backwards for the specified object, starting from the specified index, and returns an index to it.

Parameters:
elem - the desired component.
index - the index to start searching from.
Returns:
the index of the last occurrence of the specified object in this vector at position less than or equal to index in the linked list or return -1 if the object is not found.

toString

public java.lang.String toString()
Returns a string representation of this LinkedList, containing the String representation of each element.

Overrides:
toString in class Object
Returns:
a string representation of the object.