All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class tw.edu.ncnu.im.cnclab.DataStru.ListArray

java.lang.Object
   |
   +----tw.edu.ncnu.im.cnclab.DataStru.ListArray

public class ListArray
extends Object
implements Cloneable, Serializable
The ListArray class implements an array with linked-list support. Like an array, it contains components that can be accessed using an integer index. Also, the ListArray is capable of double linked-list. For example :

Get index of next item of index i in ListArray la :
    nextIndex = la.getNextIndex(i);
    
Get all item of ListArray la :
    for(Enumeration e=la.elements(); e.hasMoreElements();){
       System.out.println(e.nextElement());
    }
    

Unlike java.util.Vector, ListArray can not change size.

Version:
0.4 Jul 8, 1999
Author:
Ding-Yi Chen
See Also:
Enumeration, ListItem, ListArray2

Variable Index

 o capacity
The capacity of the ListArray.
 o first
First availible item of the ListArray.
 o itemArray
The array buffer into which the components of the ListArray are stored.
 o last
Last availible item of the ListArray.
 o numOfItem
The number of valid object in this ListArray.

Constructor Index

 o ListArray(int)
Constructs an empty ListArray with the specified initial capacity.

Method Index

 o addItemAt(Object, int)
Add an item at specified index.
 o clone()
Returns a deep-copied clone of this ListArray.
 o copyFrom(ListArray)
Copies the components from specified ListArray to this ListArray The size of these ListArrays must be identical.
 o count()
Number of valid items in this ListArray.
 o deleteAllItems()
Remove all items.
 o deleteItemAt(int)
Delete an item at specified index.
 o elements()
Returns an enumeration of the components of this ListArray.
 o getFirst()
Get first item of linked-list.
 o getFirstIndex()
Get index of first item of linked-list.
 o getLast()
Get last item of linked-list.
 o getLastIndex()
Get index of last item of linked-list.
 o getNext(int)
Get next ListItem of linked-list.
 o getNext(ListItem)
Get next ListItem of linked-list.
 o getNextIndex(int)
Get index of next item of linked-list.
 o getPrev(int)
Get previous ListItem of linked-list.
 o getPrev(ListItem)
Get prev ListItem of linked-list.
 o getPrevIndex(int)
Get index of prev item of linked-list.
 o itemAt(int)
Get the item at specified index.
 o itemExistAt(int)
Check whether item exist at specified index.
 o purge()
Remove deleted items
 o purge(int[])
Remove deleted items from specified index translation table
 o purgeIndexTable()
Create index translation table.
 o setItemAt(Object, int)
Set an item at specified index.

Variables

 o capacity
 protected int capacity
The capacity of the ListArray.

 o numOfItem
 protected int numOfItem
The number of valid object in this ListArray.

 o itemArray
 protected ListItem itemArray[]
The array buffer into which the components of the ListArray are stored.

 o first
 protected ListItem first
First availible item of the ListArray. Used in linked-list.

 o last
 protected ListItem last
Last availible item of the ListArray. Used in linked-list.

Constructors

 o ListArray
 public ListArray(int capacity)
Constructs an empty ListArray with the specified initial capacity.

Parameters:
capacity - the initial capacity of the ListArray.

Methods

 o addItemAt
 public synchronized void addItemAt(Object object,
                                    int index)
Add an item at specified index.

Parameters:
object - the item to insert.
index - where to insert the new component.
 o deleteAllItems
 public void deleteAllItems()
Remove all items.

 o clone
 public synchronized Object clone()
Returns a deep-copied clone of this ListArray.

Returns:
a deep-copied clone of this ListArray.
Overrides:
clone in class Object
 o copyFrom
 public synchronized void copyFrom(ListArray src)
Copies the components from specified ListArray to this ListArray The size of these ListArrays must be identical.

Parameters:
src - the source ListArray
 o count
 public int count()
Number of valid items in this ListArray.

Returns:
Number of valid items in this ListArray
 o deleteItemAt
 public synchronized void deleteItemAt(int index) throws NullItemException
Delete an item at specified index.

Parameters:
index - the index of the item to delete
 o itemAt
 public Object itemAt(int index)
Get the item at specified index.

Parameters:
index - the index of the item.
Returns:
the item at specified index ; null if no such item
 o itemExistAt
 public boolean itemExistAt(int index)
Check whether item exist at specified index.

Parameters:
index - the index of the item.
Returns:
true if item exist at index.
 o purge
 public synchronized void purge()
Remove deleted items

 o purge
 public synchronized void purge(int indexTable[])
Remove deleted items from specified index translation table

Parameters:
indexTable - the index translation table
 o purgeIndexTable
 public synchronized int[] purgeIndexTable()
Create index translation table.

While purging graph, if we purge the adjacency matrix of edges directly, some edges will not put on the right place. Thus, index trnaslation table is required while

Returns:
indexTable index trnaslation table
 o setItemAt
 public synchronized void setItemAt(Object obj,
                                    int index)
Set an item at specified index.

if item exist, then set object into item ; otherwise add item at specified index.

Parameters:
obj - the item to replace.
index - where to set the new component (obj).
 o getFirstIndex
 public int getFirstIndex()
Get index of first item of linked-list.

Returns:
index of first item of linked-list.
 o getLastIndex
 public int getLastIndex()
Get index of last item of linked-list.

Returns:
index of last item of linked-list.
 o getFirst
 public ListItem getFirst()
Get first item of linked-list.

Returns:
first item of linked-list.
 o getLast
 public ListItem getLast()
Get last item of linked-list.

Returns:
last item of linked-list.
 o getNextIndex
 public int getNextIndex(int index)
Get index of next item of linked-list.

Parameters:
index - index of current item
Returns:
index of next item of linked-list.
 o getNext
 public ListItem getNext(ListItem li)
Get next ListItem of linked-list.

Parameters:
li - the listitem
Returns:
next ListItem of li .
 o getNext
 public ListItem getNext(int index)
Get next ListItem of linked-list.

Parameters:
index - index of current item
Returns:
next ListItem of linked-list.
 o getPrevIndex
 public int getPrevIndex(int index)
Get index of prev item of linked-list.

Parameters:
index - index of current item.
Returns:
index of prev item of linked-list.
 o getPrev
 public ListItem getPrev(int index)
Get previous ListItem of linked-list.

Parameters:
index - index of current item
Returns:
index of previous item of linked-list.
 o getPrev
 public ListItem getPrev(ListItem li)
Get prev ListItem of linked-list.

Parameters:
li - the listitem
Returns:
prev ListItem of li .
 o elements
 public final synchronized Enumeration elements()
Returns an enumeration of the components of this ListArray.

Returns:
an enumeration of the components of this ListArray.
See Also:
Enumeration

All Packages  Class Hierarchy  This Package  Previous  Next  Index