|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectmoka.lang.Object
moka.util.Vector
The Vector
class implements a growable array of
objects. Like an array, it contains components that can be
accessed using an integer index. However, the size of a
Vector
can grow or shrink as needed to accommodate
adding and removing items after the Vector
has been created.
Each vector tries to optimize storage management by maintaining a
capacity
and a capacityIncrement
. The
capacity
is always at least as large as the vector
size; it is usually larger because as components are added to the
vector, the vector's storage increases in chunks the size of
capacityIncrement
. An application can increase the
capacity of a vector before inserting a large number of
components; this reduces the amount of incremental reallocation.
Field Summary | |
int |
capacity
The actual capacity of the Vector. |
int |
capacityIncrement
The capacity increment of the Vector. |
int |
size
The actual size of the Vector. |
Constructor Summary | |
Vector()
Creates a new Vector with an initial capacity of 10 and a capacity increment of 5. |
|
Vector(Enumeration enu)
Creates a new Vector adding the elements of the specified enumeration. |
|
Vector(int initialCapacity,
int capacityIncrement)
Creates a new Vector with the specified capacity and capacity increment. |
Method Summary | |
void |
add(int index,
Object o)
Inserts the specified element at the specified position in this vector. |
void |
clear()
Removes all of the elements from this vector. |
boolean |
contains(Object o)
Returns true if this vector contains the specified element. |
void |
copyInto(Object[] anArray,
int fromIndex,
int toIndex)
Copies the components of this vector into the specified array. |
Object |
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 vector. |
void |
enqueue(Object item)
Enqueues an item at the end of this queue. |
void |
finalize()
Frees the memory used by this object. |
Object |
get(int index)
Returns the element at the specified position in this vector. |
int |
indexOf(Object o)
Returns the index in this vector of the first occurrence of the specified element, or -1 if this list does not contain this element. |
int |
indexOf(Object elem,
int index)
Searches for the first occurence of the given argument, beginning the search at index . |
int |
lastIndexOf(Object o)
Returns the index in this vector of the last occurrence of the specified element, or -1 if this list does not contain this element. |
int |
lastIndexOf(Object elem,
int index)
Searches backwards for the specified object, starting from the specified index, and returns an index to it. |
Object |
peek()
Looks at the object at the top of this stack without removing it from the stack. |
Object |
pop()
Removes the object at the top of this stack and returns that object as the value of this function. |
void |
push(Object item)
Pushes an item onto the top of this stack. |
Object |
remove(int index)
Removes the element at the specified position in this vector. |
boolean |
remove(Object o)
Removes the first occurrence in this vector of the specified element. |
Object |
set(int index,
Object element)
Replaces the element at the specified position in this vector with the specified element. |
void |
setCapacity(int newCapacity)
Sets the capacity of this vector. |
java.lang.String |
toString()
Returns a string representation of this Vector, containing the String representation of each element. |
void |
trimToSize()
Trims the capacity of this vector to be the vector's current size. |
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 |
public int capacity
public int capacityIncrement
public int size
Constructor Detail |
public Vector()
public Vector(int initialCapacity, int capacityIncrement)
initialCapacity
- The initial capacity.capacityIncrement
- The capacity increment.public Vector(Enumeration enu)
Method Detail |
public Enumeration elements()
public void add(int index, Object o)
index
- index at which the specified element is to be inserted.public void push(Object item)
item
- the item to be pushed onto this stack.public void enqueue(Object item)
item
- the item to be enqueued.public void clear()
public void finalize()
finalize
in class Object
public boolean contains(Object o)
o
- element whose presence in this vector is to be tested.
public Object get(int index)
index
- index of element to return.
public int indexOf(Object o)
o
- element to search for.
public int lastIndexOf(Object o)
o
- element to search for.
public Object remove(int index)
index
- the index of the element to removed.
public boolean remove(Object o)
o
- element to be removed from this vector, if present.
public Object peek()
public Object pop()
public Object dequeue()
public Object set(int index, Object element)
index
- index of element to replace.element
- element to be stored at the specified position.
public void copyInto(Object[] anArray, int fromIndex, int toIndex)
anArray
- the array into which the components get copied.fromIndex
- the index of the first object in the vector
to copy.toIndex
- the index after the last object in the vector
to copy.public int indexOf(Object elem, int index)
index
.
elem
- an object.index
- the index to start searching from.
index
or later in the
vector or -1
if the object is not
found.public int lastIndexOf(Object elem, int index)
elem
- the desired component.index
- the index to start searching from.
index
in
the vector or return -1
if the object is not found.public void setCapacity(int newCapacity)
newCapacity
- the new size of this vector.public java.lang.String toString()
toString
in class Object
public void trimToSize()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |