javax.media.j3d
Class WakeupIndexedList

java.lang.Object
  extended by javax.media.j3d.WakeupIndexedList
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable

 class WakeupIndexedList
extends java.lang.Object
implements java.lang.Cloneable, java.io.Serializable

A strongly type unorder indexed array list. All operations remove(WakeupCondition), add(WakeupCondition), contains(WakeupCondition) etc. take O(1) time. The class is designed to optimize speed. So many reductance procedures call and range check as found in ArrayList are removed.

Use the following code to iterate through an array.

  WakeupIndexedList  list = new WakeupIndexedList(YourClass.class);
  // add element here

  YourClass[] arr = (YourClass []) list.toArray();
  int size = list.arraySize();
  for (int i=0; i < size; i++) {
      YourClass obj = arr[i];
      ....
  }
 

Note:

Limitation:


Field Summary
(package private)  java.lang.Object[] cloneData
          Clone copy of elementData return by toArray(true);
(package private)  int cloneSize
           
(package private)  java.lang.Class componentType
          Component Type of individual array element entry
(package private) static boolean debug
           
(package private)  WakeupCondition[] elementData
          The array buffer into which the elements of the ArrayList are stored.
(package private)  boolean isDirty
           
(package private)  int listType
           
(package private)  int size
          The size of the ArrayList (the number of elements it contains).
(package private)  VirtualUniverse univ
           
 
Constructor Summary
WakeupIndexedList(java.lang.Class componentType, int listType, VirtualUniverse univ)
          Constructs an empty list.
WakeupIndexedList(int initialCapacity, java.lang.Class componentType, int listType, VirtualUniverse univ)
          Constructs an empty list with the specified initial capacity.
WakeupIndexedList(int initialCapacity, int listType, VirtualUniverse univ)
          Constructs an empty list with the specified initial capacity.
WakeupIndexedList(int listType, VirtualUniverse univ)
          Constructs an empty list.
 
Method Summary
(package private)  void add(WakeupCondition o)
          Appends the specified element to the end of this list.
(package private)  int arraySize()
          Returns the size of entry use in toArray() number of elements in this list.
(package private)  void clear()
          Removes all of the elements from this list.
(package private)  void clearMirror()
           
protected  java.lang.Object clone()
          Returns a shallow copy of this ArrayList instance.
(package private)  boolean contains(WakeupCondition o)
          Returns true if this list contains the specified element.
(package private)  java.lang.Object get(int index)
          Returns the element at the specified position in this list.
(package private)  java.lang.Class getComponentType()
           
(package private)  int indexOf(WakeupCondition o)
          Searches for the last occurence of the given argument, testing for equality using the equals method.
(package private) static void init(WakeupCondition obj, int len)
          Initialize all indexes to -1
(package private)  boolean isEmpty()
          Tests if this list has no elements.
private  void readObject(java.io.ObjectInputStream s)
          Reconstitute the ArrayList instance from a stream (that is, deserialize it).
(package private)  void remove(int index)
          Removes the element at the specified position in this list.
(package private)  boolean remove(WakeupCondition o)
          Removes the specified element in this list.
(package private)  java.lang.Object removeLastElement()
          Removes the element at the last position in this list.
(package private)  void set(int index, WakeupCondition o)
          Replaces the element at the specified position in this list with the specified element.
(package private)  int size()
          Returns the number of elements in this list.
(package private)  java.lang.Object[] toArray()
          Returns an array containing all of the elements in this list.
(package private)  java.lang.Object[] toArray(boolean copy)
          Returns an array containing all of the elements in this list.
(package private)  java.lang.Object[] toArray(WakeupCondition startElement)
          Returns an array containing elements starting from startElement all of the elements in this list.
 java.lang.String toString()
           
(package private)  void trimToSize()
          Trims the capacity of this ArrayList instance to be the list's current size.
private  void writeObject(java.io.ObjectOutputStream s)
          Save the state of the ArrayList instance to a stream (that is, serialize it).
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

debug

static final boolean debug
See Also:
Constant Field Values

elementData

transient WakeupCondition[] elementData
The array buffer into which the elements of the ArrayList are stored. The capacity of the ArrayList is the length of this array buffer. It is non-private to enable compiler do inlining for get(), set(), remove() when -O flag turn on.


cloneData

transient java.lang.Object[] cloneData
Clone copy of elementData return by toArray(true);


cloneSize

transient int cloneSize

isDirty

transient boolean isDirty

componentType

java.lang.Class componentType
Component Type of individual array element entry


size

int size
The size of the ArrayList (the number of elements it contains). We make it non-private to enable compiler do inlining for getSize() when -O flag turn on.


listType

int listType

univ

VirtualUniverse univ
Constructor Detail

WakeupIndexedList

WakeupIndexedList(int initialCapacity,
                  java.lang.Class componentType,
                  int listType,
                  VirtualUniverse univ)
Constructs an empty list with the specified initial capacity. and the class data Type

Parameters:
initialCapacity - the initial capacity of the list.
componentType - class type of element in the list.

WakeupIndexedList

WakeupIndexedList(java.lang.Class componentType,
                  int listType,
                  VirtualUniverse univ)
Constructs an empty list.

Parameters:
componentType - class type of element in the list.

WakeupIndexedList

WakeupIndexedList(int initialCapacity,
                  int listType,
                  VirtualUniverse univ)
Constructs an empty list with the specified initial capacity.

Parameters:
initialCapacity - the initial capacity of the list.

WakeupIndexedList

WakeupIndexedList(int listType,
                  VirtualUniverse univ)
Constructs an empty list. componentType default to Object.

Method Detail

init

static final void init(WakeupCondition obj,
                       int len)
Initialize all indexes to -1


size

final int size()
Returns the number of elements in this list.

Returns:
the number of elements in this list.

arraySize

final int arraySize()
Returns the size of entry use in toArray() number of elements in this list.

Returns:
the number of elements in this list.

isEmpty

final boolean isEmpty()
Tests if this list has no elements.

Returns:
true if this list has no elements; false otherwise.

contains

final boolean contains(WakeupCondition o)
Returns true if this list contains the specified element.

Parameters:
o - element whose presence in this List is to be tested.

indexOf

final int indexOf(WakeupCondition o)
Searches for the last occurence of the given argument, testing for equality using the equals method.

Parameters:
o - an object.
Returns:
the index of the first occurrence of the argument in this list; returns -1 if the object is not found.
See Also:
Object.equals(Object)

clone

protected final java.lang.Object clone()
Returns a shallow copy of this ArrayList instance. (The elements themselves are not copied.)

Overrides:
clone in class java.lang.Object
Returns:
a clone of this ArrayList instance.

toArray

final java.lang.Object[] toArray(boolean copy)
Returns an array containing all of the elements in this list. The size of the array may longer than the actual size. Use arraySize() to retrieve the size. The array return is a copied of internal array. if copy is true.

Returns:
an array containing all of the elements in this list

toArray

final java.lang.Object[] toArray()
Returns an array containing all of the elements in this list. The size of the array may longer than the actual size. Use arraySize() to retrieve the size. The array return is a copied of internal array. So another thread can continue add/delete the current list. However, it should be noticed that two call to toArray() may return the same copy.

Returns:
an array containing all of the elements in this list

toArray

final java.lang.Object[] toArray(WakeupCondition startElement)
Returns an array containing elements starting from startElement all of the elements in this list. A new array of exact size is always allocated.

Parameters:
startElement - starting element to copy
Returns:
an array containing elements starting from startElement, null if element not found.

trimToSize

final void trimToSize()
Trims the capacity of this ArrayList instance to be the list's current size. An application can use this operation to minimize the storage of an ArrayList instance.


get

final java.lang.Object get(int index)
Returns the element at the specified position in this list.

Parameters:
index - index of element to return.
Returns:
the element at the specified position in this list.
Throws:
java.lang.IndexOutOfBoundsException - if index is out of range (index < 0 || index >= size()).

set

final void set(int index,
               WakeupCondition o)
Replaces the element at the specified position in this list with the specified element.

Parameters:
index - index of element to replace.
o - element to be stored at the specified position.
Throws:
java.lang.IndexOutOfBoundsException - if index out of range (index < 0 || index >= size()).

add

final void add(WakeupCondition o)
Appends the specified element to the end of this list. It is the user responsible to ensure that the element add is of the same type as array componentType.

Parameters:
o - element to be appended to this list.

remove

final void remove(int index)
Removes the element at the specified position in this list. Replace the removed element by the last one.

Parameters:
index - the index of the element to removed.
Throws:
java.lang.IndexOutOfBoundsException - if index out of range (index < 0 || index >= size()).

removeLastElement

final java.lang.Object removeLastElement()
Removes the element at the last position in this list.

Returns:
The element remove
Throws:
java.lang.IndexOutOfBoundsException - if array is empty

remove

final boolean remove(WakeupCondition o)
Removes the specified element in this list. Replace the removed element by the last one.

Parameters:
o - the element to removed.
Returns:
true if object remove
Throws:
java.lang.IndexOutOfBoundsException - if index out of range (index < 0 || index >= size()).

clear

final void clear()
Removes all of the elements from this list. The list will be empty after this call returns.


clearMirror

final void clearMirror()

getComponentType

final java.lang.Class getComponentType()

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

writeObject

private void writeObject(java.io.ObjectOutputStream s)
                  throws java.io.IOException
Save the state of the ArrayList instance to a stream (that is, serialize it).

Throws:
java.io.IOException

readObject

private void readObject(java.io.ObjectInputStream s)
                 throws java.io.IOException,
                        java.lang.ClassNotFoundException
Reconstitute the ArrayList instance from a stream (that is, deserialize it).

Throws:
java.io.IOException
java.lang.ClassNotFoundException


Copyright 1996-2008 Sun Microsystems, Inc. All Rights Reserved. Use is subject to license terms.