|
Genuts API | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectcom.genuts.gameui.util.SpriteVector
The SpriteVector class implements a growable array of Sprite 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 SpriteVector can grow or shrink as needed to accommodate adding and
removing sprites after the SpriteVector has been created.
The SpriteVector 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 Sprite
objects.
It is really useful to store unused sprites like bullet instead of new instanciations.
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 sprites in the vector. |
protected Sprite[] |
elementData
The array buffer into which the sprites of the vector are stored. |
| Constructor Summary | |
SpriteVector()
Constructs an empty vector. |
|
SpriteVector(int initialCapacity)
Constructs an empty vector with the specified initial capacity. |
|
SpriteVector(int initialCapacity,
int capacityIncrement)
Constructs an empty vector with the specified initial capacity and capacity increment. |
|
| Method Summary | |
void |
addElement(Sprite sprite)
Adds the specified sprite to the end of this vector, increasing its size by one. |
int |
capacity()
Returns the current capacity of this vector. |
boolean |
contains(Sprite elem)
Tests if the specified sprite is a component in this vector. |
void |
copyInto(Sprite[] anArray)
Copies the sprites of this vector into the specified array. |
Sprite |
elementAt(int index)
Returns the sprite 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 sprites specified by the minimum capacity argument. |
Sprite |
firstElement()
Returns the first sprite of this vector. |
int |
indexOf(Sprite elem)
Searches for the first occurence of the given argument, testing for equality using the == operator. |
int |
indexOf(Sprite 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(Sprite sprite,
int index)
Inserts the specified sprite as a component in this vector at the specified index.
|
boolean |
isEmpty()
Tests if this vector has no sprites. |
Sprite |
lastElement()
Returns the last sprite of the vector. |
int |
lastIndexOf(Sprite elem)
Returns the index of the last occurrence of the specified sprite in this vector. |
int |
lastIndexOf(Sprite elem,
int index)
Searches backwards for the specified sprite, 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(Sprite sprite)
Removes the first occurrence of the argument from this vector. |
void |
removeElementAt(int index)
Deletes the sprite at the specified index. |
void |
setElementAt(Sprite sprite,
int index)
Sets the component at the specified index of this vector to be the specified sprite. |
void |
setSize(int newSize)
Sets the size of this vector. |
int |
size()
Returns the number of sprites in this vector. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
protected Sprite[] elementData
protected int elementCount
protected int capacityIncrement
| Constructor Detail |
public SpriteVector(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 SpriteVector(int initialCapacity)
initialCapacity - the initial capacity of the vector.public SpriteVector()
| Method Detail |
public final void copyInto(Sprite[] anArray)
anArray - the array into which the sprites 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 sprites; false otherwise.public final boolean contains(Sprite elem)
elem - a sprite.
true if the specified sprite is a component in this vector; false
otherwise.public final int indexOf(Sprite elem)
elem - a sprite
public final int indexOf(Sprite elem,
int index)
index,
and testing for equality using the == operator.
elem - a sprite.index - the index to start searching from.
java.lang.ArrayIndexOutOfBoundsException - if an invalid index was given.public final int lastIndexOf(Sprite elem)
elem - the desired sprite.
public final int lastIndexOf(Sprite elem,
int index)
index, and
returns an index to it.
elem - the desired sprite.index - the index to start searching from.
java.lang.ArrayIndexOutOfBoundsException - if an invalid index was given.public final Sprite elementAt(int index)
index - an index into this vector.
java.lang.ArrayIndexOutOfBoundsException - if an invalid index was given.public final Sprite firstElement()
null if there is no
element in this vector.public final Sprite lastElement()
null if there is no element in this vector.
public final void setElementAt(Sprite sprite,
int index)
index must be a value greater than or equal to 0 and less than the current size
of the vector.
sprite - what the sprite 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 sprite to remove.
java.lang.ArrayIndexOutOfBoundsException - if the index was invalid.size()
public final void insertElementAt(Sprite sprite,
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.
sprite - the component to insert.index - where to insert the new component.
java.lang.ArrayIndexOutOfBoundsException - if the index was invalid.size()public final void addElement(Sprite sprite)
sprite - the component to be added.public final boolean removeElement(Sprite sprite)
sprite - 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 | ||||||||||