All Packages Class Hierarchy This Package Previous Next Index
Class Acme.FlexVector
java.lang.Object
|
+----Acme.FlexVector
- public class FlexVector
- extends Object
- implements Cloneable
Improved version of java.util.Vector.
Usage is identical to java.util.Vector. The changes are all internal.
So far the only change is that removing elements from the beginning
of the vector is handled much more efficiently.
Note that this can't be a subclass of Vector because Vector is full
of final methods, which can't be overridden.
Fetch the software.
Fetch the entire Acme package.
-
capacityIncrement
- The size of the increment.
-
elementCount
- The number of elements in the buffer.
-
elementData
- The buffer where elements are stored.
-
elementOffset
- The offset for the first element.
-
FlexVector()
- Constructs an empty vector.
-
FlexVector(int)
- Constructs an empty vector with the specified storage capacity.
-
FlexVector(int, int)
- Constructs an empty vector with the specified storage
capacity and the specified capacityIncrement.
-
addElement(Object)
- Adds the specified object as the last element of the vector.
-
capacity()
- Returns the current capacity of the vector.
-
clone()
- Clones this vector.
-
contains(Object)
- Returns true if the specified object is a value of the collection.
-
copyInto(Object[])
- Copies the elements of this vector into the specified array.
-
elementAt(int)
- Returns the element at the specified index.
-
elements()
- Returns an enumeration of the elements.
-
ensureCapacity(int)
- Ensures that the vector has at least the specified capacity.
-
firstElement()
- Returns the first element of the sequence.
-
indexOf(Object)
- Searches for the specified object, starting from the first position
and returns an index to it.
-
indexOf(Object, int)
- Searches for the specified object, starting at the specified
position and returns an index to it.
-
insertElementAt(Object, int)
- Inserts the specified object as an element at the specified index.
-
isEmpty()
- Returns true if the collection contains no values.
-
lastElement()
- Returns the last element of the sequence.
-
lastIndexOf(Object)
- Searches backwards for the specified object, starting from the last
position and returns an index to it.
-
lastIndexOf(Object, int)
- Searches backwards for the specified object, starting from the specified
position and returns an index to it.
-
removeAllElements()
- Removes all elements of the vector.
-
removeElement(Object)
- Removes the element from the vector.
-
removeElementAt(int)
- Deletes the element at the specified index.
-
setElementAt(Object, int)
- Sets the element at the specified index to be the specified object.
-
setSize(int)
- Sets the size of the vector.
-
size()
- Returns the number of elements in the vector.
-
toString()
- Converts the vector to a string.
-
trimToSize()
- Trims the vector's capacity down to size.
elementData
protected Object elementData[]
- The buffer where elements are stored.
elementCount
protected int elementCount
- The number of elements in the buffer.
elementOffset
protected int elementOffset
- The offset for the first element.
capacityIncrement
protected int capacityIncrement
- The size of the increment. If it is 0 the size of the
the buffer is doubled everytime it needs to grow.
FlexVector
public FlexVector(int initialCapacity,
int capacityIncrement)
- Constructs an empty vector with the specified storage
capacity and the specified capacityIncrement.
- Parameters:
- initialCapacity - the initial storage capacity of the vector
- capacityIncrement - how much to increase the element's
size by.
FlexVector
public FlexVector(int initialCapacity)
- Constructs an empty vector with the specified storage capacity.
- Parameters:
- initialCapacity - the initial storage capacity of the vector
FlexVector
public FlexVector()
- Constructs an empty vector.
copyInto
public final synchronized void copyInto(Object anArray[])
- Copies the elements of this vector into the specified array.
- Parameters:
- anArray - the array where elements get copied into
trimToSize
public final synchronized void trimToSize()
- Trims the vector's capacity down to size. Use this operation to
minimize the storage of a vector. Subsequent insertions will
cause reallocation.
ensureCapacity
public final synchronized void ensureCapacity(int minCapacity)
- Ensures that the vector has at least the specified capacity.
- Parameters:
- minCapacity - the desired minimum capacity
setSize
public final synchronized void setSize(int newSize)
- Sets the size of the vector. If the size shrinks, the extra elements
(at the end of the vector) are lost; if the size increases, the
new elements are set to null.
- Parameters:
- newSize - the new size of the vector
capacity
public final int capacity()
- Returns the current capacity of the vector.
size
public final int size()
- Returns the number of elements in the vector.
Note that this is not the same as the vector's capacity.
isEmpty
public final boolean isEmpty()
- Returns true if the collection contains no values.
elements
public final synchronized Enumeration elements()
- Returns an enumeration of the elements. Use the Enumeration methods on
the returned object to fetch the elements sequentially.
contains
public final boolean contains(Object elem)
- Returns true if the specified object is a value of the collection.
- Parameters:
- elem - the desired element
indexOf
public final int indexOf(Object elem)
- Searches for the specified object, starting from the first position
and returns an index to it.
- Parameters:
- elem - the desired element
- Returns:
- the index of the element, or -1 if it was not found.
indexOf
public final synchronized int indexOf(Object elem,
int index)
- Searches for the specified object, starting at the specified
position and returns an index to it.
- Parameters:
- elem - the desired element
- index - the index where to start searching
- Returns:
- the index of the element, or -1 if it was not found.
lastIndexOf
public final int lastIndexOf(Object elem)
- Searches backwards for the specified object, starting from the last
position and returns an index to it.
- Parameters:
- elem - the desired element
- Returns:
- the index of the element, or -1 if it was not found.
lastIndexOf
public final synchronized int lastIndexOf(Object elem,
int index)
- Searches backwards for the specified object, starting from the specified
position and returns an index to it.
- Parameters:
- elem - the desired element
- index - the index where to start searching
- Returns:
- the index of the element, or -1 if it was not found.
elementAt
public final synchronized Object elementAt(int index)
- Returns the element at the specified index.
- Parameters:
- index - the index of the desired element
- Throws: ArrayIndexOutOfBoundsException
- If an invalid
index was given.
firstElement
public final synchronized Object firstElement()
- Returns the first element of the sequence.
- Throws: NoSuchElementException
- If the sequence is empty.
lastElement
public final synchronized Object lastElement()
- Returns the last element of the sequence.
- Throws: NoSuchElementException
- If the sequence is empty.
setElementAt
public final synchronized void setElementAt(Object obj,
int index)
- Sets the element at the specified index to be the specified object.
The previous element at that position is discarded.
- Parameters:
- obj - what the element is to be set to
- index - the specified index
- Throws: ArrayIndexOutOfBoundsException
- If the index was invalid.
removeElementAt
public final synchronized void removeElementAt(int index)
- Deletes the element at the specified index. Elements with an index
greater than the current index are moved down.
- Parameters:
- index - the element to remove
- Throws: ArrayIndexOutOfBoundsException
- If the index was invalid.
insertElementAt
public final synchronized void insertElementAt(Object obj,
int index)
- Inserts the specified object as an element at the specified index.
Elements with an index greater or equal to the current index
are shifted up.
- Parameters:
- obj - the element to insert
- index - where to insert the new element
- Throws: ArrayIndexOutOfBoundsException
- If the index was invalid.
addElement
public final synchronized void addElement(Object obj)
- Adds the specified object as the last element of the vector.
- Parameters:
- obj - the element to be added
removeElement
public final synchronized boolean removeElement(Object obj)
- Removes the element from the vector. If the object occurs more
than once, only the first is removed. If the object is not an
element, returns false.
- Parameters:
- obj - the element to be removed
- Returns:
- true if the element was actually removed; false otherwise.
removeAllElements
public final synchronized void removeAllElements()
- Removes all elements of the vector. The vector becomes empty.
clone
public synchronized Object clone()
- Clones this vector. The elements are not cloned.
- Overrides:
- clone in class Object
toString
public final synchronized String toString()
- Converts the vector to a string. Useful for debugging.
- Overrides:
- toString in class Object
All Packages Class Hierarchy This Package Previous Next Index
ACME Java ACME Labs