|
Genuts API | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectcom.genuts.gameui.util.TickableVector
The TickableVector class implements a growable array of Tickable objects. Like an array or
the java.util.Vector, it contains components that can be accessed using an integer index.
However, the size of a TickableVector can grow or shrink as needed to accommodate adding and
removing tickables after the TickableVector has been created.
The TickableVector works as java.util.Vector whitout any synchronization
or iterator facilities. The number of method is reduced.
This object is made to reduce garbage collector actions, and to optimize the storage of Tickable
objects.
Vector| Field Summary | |
protected int |
capacityIncrement
The amount by which the capacity of the vector is automatically incremented when its size becomes greater than its capacity. |
protected int |
elementCount
The number of valid tickables in the vector. |
protected Tickable[] |
elementData
The array buffer into which the tickables of the vector are stored. |
| Constructor Summary | |
TickableVector()
Constructs an empty vector. |
|
TickableVector(int initialCapacity)
Constructs an empty vector with the specified initial capacity. |
|
TickableVector(int initialCapacity,
int capacityIncrement)
Constructs an empty vector with the specified initial capacity and capacity increment. |
|
| Method Summary | |
void |
addElement(Tickable tickable)
Adds the specified tickable to the end of this vector, increasing its size by one. |
int |
capacity()
Returns the current capacity of this vector. |
boolean |
contains(Tickable elem)
Tests if the specified tickable is a component in this vector. |
void |
copyInto(Tickable[] anArray)
Copies the tickables of this vector into the specified array. |
Tickable |
elementAt(int index)
Returns the tickable at the specified index. |
void |
ensureCapacity(int minCapacity)
Increases the capacity of this vector, if necessary, to ensure that it can hold at least the number of tickables specified by the minimum capacity argument. |
Tickable |
firstElement()
Returns the first tickable of this vector. |
int |
indexOf(Tickable elem)
Searches for the first occurence of the given argument, testing for equality using the == operator. |
int |
indexOf(Tickable elem,
int index)
Searches for the first occurence of the given argument, beginning the search at index,
and testing for equality using the == operator. |
void |
insertElementAt(Tickable tickable,
int index)
Inserts the specified tickable as a component in this vector at the specified index.
|
boolean |
isEmpty()
Tests if this vector has no tickables. |
Tickable |
lastElement()
Returns the last tickable of the vector. |
int |
lastIndexOf(Tickable elem)
Returns the index of the last occurrence of the specified tickable in this vector. |
int |
lastIndexOf(Tickable elem,
int index)
Searches backwards for the specified tickable, starting from the specified index, and
returns an index to it. |
void |
removeAllElements()
Removes all components from this vector and sets its size to zero. |
boolean |
removeElement(Tickable tickable)
Removes the first occurrence of the argument from this vector. |
void |
removeElementAt(int index)
Deletes the tickable at the specified index. |
void |
setElementAt(Tickable tickable,
int index)
Sets the component at the specified index of this vector to be the specified tickable. |
void |
setSize(int newSize)
Sets the size of this vector. |
int |
size()
Returns the number of tickables in this vector. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
protected Tickable[] elementData
protected int elementCount
protected int capacityIncrement
| Constructor Detail |
public TickableVector(int initialCapacity,
int capacityIncrement)
initialCapacity - the initial capacity of the vector.capacityIncrement - the amount by which the capacity is increased when the vector overflows.
java.lang.IllegalArgumentException - if the initial capacity is less than or equal to zero or
the increment capacity is less than zero.public TickableVector(int initialCapacity)
initialCapacity - the initial capacity of the vector.public TickableVector()
| Method Detail |
public final void copyInto(Tickable[] anArray)
anArray - the array into which the tickables get copied.public final void ensureCapacity(int minCapacity)
minCapacity - the desired minimum capacity.public final void setSize(int newSize)
null
items are added to the end of the vector. If the new size is less than the current size, all components
at index newSize and greater are discarded.
newSize - the new size of this vector.public final int capacity()
public final int size()
public final boolean isEmpty()
true if this vector has no tickables; false otherwise.public final boolean contains(Tickable elem)
elem - a tickable.
true if the specified tickable is a component in this vector; false
otherwise.public final int indexOf(Tickable elem)
elem - a tickable
public final int indexOf(Tickable elem,
int index)
index,
and testing for equality using the == operator.
elem - a tickable.index - the index to start searching from.
java.lang.ArrayIndexOutOfBoundsException - if an invalid index was given.public final int lastIndexOf(Tickable elem)
elem - the desired tickable.
public final int lastIndexOf(Tickable elem,
int index)
index, and
returns an index to it.
elem - the desired tickable.index - the index to start searching from.
java.lang.ArrayIndexOutOfBoundsException - if an invalid index was given.public final Tickable elementAt(int index)
index - an index into this vector.
java.lang.ArrayIndexOutOfBoundsException - if an invalid index was given.public final Tickable firstElement()
null if there is no
element in this vector.public final Tickable lastElement()
null if there is no element in this vector.
public final void setElementAt(Tickable tickable,
int index)
index must be a value greater than or equal to 0 and less than the current size
of the vector.
tickable - what the tickable is to be set to.index - the specified index.
java.lang.ArrayIndexOutOfBoundsException - if the index was invalid.size()public final void removeElementAt(int index)
index
greater or equal to the specified index is shifted downward to have an index one smaller than the
value it had previously.index must be a value greater than or equal to 0 and less than the current size of
the vector.
index - the index of the tickable to remove.
java.lang.ArrayIndexOutOfBoundsException - if the index was invalid.size()
public final void insertElementAt(Tickable tickable,
int index)
index.
Each component in this vector with an index greater or equal to the specified index is
shifted upward to have an index one greater than the value it had previously. index must be a value greater than or equal to 0 and less than or equal to the current
size of the vector.
tickable - the component to insert.index - where to insert the new component.
java.lang.ArrayIndexOutOfBoundsException - if the index was invalid.size()public final void addElement(Tickable tickable)
tickable - the component to be added.public final boolean removeElement(Tickable tickable)
tickable - component to be removed.
true if the argument was a component of this vector; false otherwise.public final void removeAllElements()
|
Genuts API | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||