Methods Summary |
---|
public boolean | add(E o)Appends the specified element to the end of this ModVector.
modCount++;
ensureCapacityHelper(elementCount + 1);
elementData[elementCount++] = o;
return true;
|
public void | add(int index, E element)Inserts the specified element at the specified position in this ModVector.
Shifts the element currently at that position (if any) and any
subsequent elements to the right (adds one to their indices).
insertElementAt(element, index);
|
public boolean | addAll(java.util.Collection c)Appends all of the elements in the specified Collection to the end of
this ModVector, in the order that they are returned by the specified
Collection's Iterator. The behavior of this operation is undefined if
the specified Collection is modified while the operation is in progress.
(This implies that the behavior of this call is undefined if the
specified Collection is this ModVector, and this ModVector is nonempty.)
modCount++;
Object[] a = c.toArray();
int numNew = a.length;
ensureCapacityHelper(elementCount + numNew);
System.arraycopy(a, 0, elementData, elementCount, numNew);
elementCount += numNew;
return numNew != 0;
|
public boolean | addAll(int index, java.util.Collection c)Inserts all of the elements in in the specified Collection into this
ModVector at the specified position. Shifts the element currently at
that position (if any) and any subsequent elements to the right
(increases their indices). The new elements will appear in the ModVector
in the order that they are returned by the specified Collection's
iterator.
modCount++;
if (index < 0 || index > elementCount)
throw new ArrayIndexOutOfBoundsException(index);
Object[] a = c.toArray();
int numNew = a.length;
ensureCapacityHelper(elementCount + numNew);
int numMoved = elementCount - index;
if (numMoved > 0)
System.arraycopy(elementData, index, elementData, index + numNew,
numMoved);
System.arraycopy(a, 0, elementData, index, numNew);
elementCount += numNew;
return numNew != 0;
|
public void | addElement(E obj)Adds the specified component to the end of this vector,
increasing its size by one. The capacity of this vector is
increased if its size becomes greater than its capacity.
This method is identical in functionality to the add(Object) method
(which is part of the List interface).
modCount++;
ensureCapacityHelper(elementCount + 1);
elementData[elementCount++] = obj;
|
public int | capacity()Returns the current capacity of this vector.
return elementData.length;
|
public void | clear()Removes all of the elements from this ModVector. The ModVector will
be empty after this call returns (unless it throws an exception).
removeAllElements();
|
public java.lang.Object | clone()Returns a clone of this vector. The copy will contain a
reference to a clone of the internal data array, not a reference
to the original internal data array of this ModVector object.
try {
ModVector<E> v = (ModVector<E>) super.clone();
v.elementData = new Object[elementCount];
System.arraycopy(elementData, 0, v.elementData, 0, elementCount);
v.modCount = 0;
return v;
} catch (CloneNotSupportedException e) {
// this shouldn't happen, since we are Cloneable
throw new InternalError();
}
|
public boolean | contains(java.lang.Object elem)Tests if the specified object is a component in this vector.
return indexOf(elem, 0) >= 0;
|
public boolean | containsAll(java.util.Collection c)Returns true if this ModVector contains all of the elements in the
specified Collection.
return super.containsAll(c);
|
public void | copyInto(java.lang.Object[] anArray)Copies the components of this vector into the specified array. The
item at index k in this vector is copied into component
k of anArray. The array must be big enough to hold
all the objects in this vector, else an
IndexOutOfBoundsException is thrown.
System.arraycopy(elementData, 0, anArray, 0, elementCount);
|
public E | elementAt(int index)Returns the component at the specified index.
This method is identical in functionality to the get method
(which is part of the List interface).
if (index >= elementCount) {
throw new ArrayIndexOutOfBoundsException(index + " >= " + elementCount);
}
return (E)elementData[index];
|
public java.util.Enumeration | elements()Returns an enumeration of the components of this vector. The
returned Enumeration object will generate all items in
this vector. The first item generated is the item at index 0,
then the item at index 1, and so on.
return new Enumeration<E>() {
int count = 0;
public boolean hasMoreElements() {
return count < elementCount;
}
public E nextElement() {
synchronized (ModVector.this) {
if (count < elementCount) {
return (E)elementData[count++];
}
}
throw new NoSuchElementException("ModVector Enumeration");
}
};
|
public void | ensureCapacity(int minCapacity)Increases the capacity of this vector, if necessary, to ensure
that it can hold at least the number of components specified by
the minimum capacity argument.
If the current capacity of this vector is less than
minCapacity, then its capacity is increased by replacing its
internal data array, kept in the field elementData, with a
larger one. The size of the new data array will be the old size plus
capacityIncrement, unless the value of
capacityIncrement is less than or equal to zero, in which case
the new capacity will be twice the old capacity; but if this new size
is still smaller than minCapacity, then the new capacity will
be minCapacity.
modCount++;
ensureCapacityHelper(minCapacity);
|
private void | ensureCapacityHelper(int minCapacity)This implements the unsynchronized semantics of ensureCapacity.
Synchronized methods in this class can internally call this
method for ensuring capacity without incurring the cost of an
extra synchronization.
int oldCapacity = elementData.length;
if (minCapacity > oldCapacity) {
Object[] oldData = elementData;
int newCapacity = (capacityIncrement > 0) ?
(oldCapacity + capacityIncrement) : (oldCapacity * 2);
if (newCapacity < minCapacity) {
newCapacity = minCapacity;
}
elementData = new Object[newCapacity];
System.arraycopy(oldData, 0, elementData, 0, elementCount);
}
|
public boolean | equals(java.lang.Object o)Compares the specified Object with this ModVector for equality. Returns
true if and only if the specified Object is also a List, both Lists
have the same size, and all corresponding pairs of elements in the two
Lists are equal. (Two elements e1 and
e2 are equal if (e1==null ? e2==null :
e1.equals(e2)) .) In other words, two Lists are defined to be
equal if they contain the same elements in the same order.
return super.equals(o);
|
public E | firstElement()Returns the first component (the item at index 0) of
this vector.
if (elementCount == 0) {
throw new NoSuchElementException();
}
return (E)elementData[0];
|
public E | get(int index)Returns the element at the specified position in this ModVector.
if (index >= elementCount)
throw new ArrayIndexOutOfBoundsException(index);
return (E)elementData[index];
|
public int | hashCode()Returns the hash code value for this ModVector.
return super.hashCode();
|
public int | indexOf(java.lang.Object elem)Searches for the first occurence of the given argument, testing
for equality using the equals method.
return indexOf(elem, 0);
|
public int | indexOf(java.lang.Object elem, int index)Searches for the first occurence of the given argument, beginning
the search at index , and testing for equality using
the equals method.
if (elem == null) {
for (int i = index ; i < elementCount ; i++)
if (elementData[i]==null)
return i;
} else {
for (int i = index ; i < elementCount ; i++)
if (elem.equals(elementData[i]))
return i;
}
return -1;
|
public void | insertElementAt(E obj, int index)Inserts the specified object as a component in this vector at the
specified 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.
The index must be a value greater than or equal to 0
and less than or equal to the current size of the vector. (If the
index is equal to the current size of the vector, the new element
is appended to the ModVector.)
This method is identical in functionality to the add(Object, int) method
(which is part of the List interface). Note that the add method reverses
the order of the parameters, to more closely match array usage.
modCount++;
if (index > elementCount) {
throw new ArrayIndexOutOfBoundsException(index
+ " > " + elementCount);
}
ensureCapacityHelper(elementCount + 1);
System.arraycopy(elementData, index, elementData, index + 1, elementCount - index);
elementData[index] = obj;
elementCount++;
|
public boolean | isEmpty()Tests if this vector has no components.
return elementCount == 0;
|
public E | lastElement()Returns the last component of the vector.
if (elementCount == 0) {
throw new NoSuchElementException();
}
return (E)elementData[elementCount - 1];
|
public int | lastIndexOf(java.lang.Object elem)Returns the index of the last occurrence of the specified object in
this vector.
return lastIndexOf(elem, elementCount-1);
|
public int | lastIndexOf(java.lang.Object elem, int index)Searches backwards for the specified object, starting from the
specified index, and returns an index to it.
if (index >= elementCount)
throw new IndexOutOfBoundsException(index + " >= "+ elementCount);
if (elem == null) {
for (int i = index; i >= 0; i--)
if (elementData[i]==null)
return i;
} else {
for (int i = index; i >= 0; i--)
if (elem.equals(elementData[i]))
return i;
}
return -1;
|
public boolean | remove(java.lang.Object o)Removes the first occurrence of the specified element in this ModVector
If the ModVector does not contain the element, it is unchanged. More
formally, removes the element with the lowest index i such that
(o==null ? get(i)==null : o.equals(get(i))) (if such
an element exists).
return removeElement(o);
|
public E | remove(int index)Removes the element at the specified position in this ModVector.
shifts any subsequent elements to the left (subtracts one from their
indices). Returns the element that was removed from the ModVector.
modCount++;
if (index >= elementCount)
throw new ArrayIndexOutOfBoundsException(index);
Object oldValue = elementData[index];
int numMoved = elementCount - index - 1;
if (numMoved > 0)
System.arraycopy(elementData, index+1, elementData, index,
numMoved);
elementData[--elementCount] = null; // Let gc do its work
return (E)oldValue;
|
public boolean | removeAll(java.util.Collection c)Removes from this ModVector all of its elements that are contained in the
specified Collection.
return super.removeAll(c);
|
public void | removeAllElements()Removes all components from this vector and sets its size to zero.
This method is identical in functionality to the clear method
(which is part of the List interface).
modCount++;
// Let gc do its work
for (int i = 0; i < elementCount; i++)
elementData[i] = null;
elementCount = 0;
|
public boolean | removeElement(java.lang.Object obj)Removes the first (lowest-indexed) occurrence of the argument
from this vector. If the object is found in this vector, each
component in the vector with an index greater or equal to the
object's index is shifted downward to have an index one smaller
than the value it had previously.
This method is identical in functionality to the remove(Object)
method (which is part of the List interface).
modCount++;
int i = indexOf(obj);
if (i >= 0) {
removeElementAt(i);
return true;
}
return false;
|
public void | removeElementAt(int index)Deletes the component at the specified index. Each component in
this vector with an index greater or equal to the specified
index is shifted downward to have an index one
smaller than the value it had previously. The size of this vector
is decreased by 1.
The index must be a value greater than or equal to 0
and less than the current size of the vector.
This method is identical in functionality to the remove method
(which is part of the List interface). Note that the remove method
returns the old value that was stored at the specified position.
modCount++;
if (index >= elementCount) {
throw new ArrayIndexOutOfBoundsException(index + " >= " +
elementCount);
}
else if (index < 0) {
throw new ArrayIndexOutOfBoundsException(index);
}
int j = elementCount - index - 1;
if (j > 0) {
System.arraycopy(elementData, index + 1, elementData, index, j);
}
elementCount--;
elementData[elementCount] = null; /* to let gc do its work */
|
protected void | removeRange(int fromIndex, int toIndex)Removes from this List all of the elements whose index is between
fromIndex, inclusive and toIndex, exclusive. Shifts any succeeding
elements to the left (reduces their index).
This call shortens the ArrayList by (toIndex - fromIndex) elements. (If
toIndex==fromIndex, this operation has no effect.)
modCount++;
int numMoved = elementCount - toIndex;
System.arraycopy(elementData, toIndex, elementData, fromIndex,
numMoved);
// Let gc do its work
int newElementCount = elementCount - (toIndex-fromIndex);
while (elementCount != newElementCount)
elementData[--elementCount] = null;
|
public boolean | retainAll(java.util.Collection c)Retains only the elements in this ModVector that are contained in the
specified Collection. In other words, removes from this ModVector all
of its elements that are not contained in the specified Collection.
return super.retainAll(c);
|
public E | set(int index, E element)Replaces the element at the specified position in this ModVector with the
specified element.
if (index >= elementCount)
throw new ArrayIndexOutOfBoundsException(index);
Object oldValue = elementData[index];
elementData[index] = element;
return (E)oldValue;
|
public void | setElementAt(E obj, int index)Sets the component at the specified index of this
vector to be the specified object. The previous component at that
position is discarded.
The index must be a value greater than or equal to 0
and less than the current size of the vector.
This method is identical in functionality to the set method
(which is part of the List interface). Note that the set method reverses
the order of the parameters, to more closely match array usage. Note
also that the set method returns the old value that was stored at the
specified position.
if (index >= elementCount) {
throw new ArrayIndexOutOfBoundsException(index + " >= " +
elementCount);
}
elementData[index] = obj;
|
public void | setSize(int newSize)Sets the size of this vector. If the new size is greater than the
current size, new 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.
modCount++;
if (newSize > elementCount) {
ensureCapacityHelper(newSize);
} else {
for (int i = newSize ; i < elementCount ; i++) {
elementData[i] = null;
}
}
elementCount = newSize;
|
public int | size()Returns the number of components in this vector.
return elementCount;
|
public java.util.List | subList(int fromIndex, int toIndex)Returns a view of the portion of this List between fromIndex,
inclusive, and toIndex, exclusive. (If fromIndex and ToIndex are
equal, the returned List is empty.) The returned List is backed by this
List, so changes in the returned List are reflected in this List, and
vice-versa. The returned List supports all of the optional List
operations supported by this List.
This method eliminates the need for explicit range operations (of
the sort that commonly exist for arrays). Any operation that expects
a List can be used as a range operation by operating on a subList view
instead of a whole List. For example, the following idiom
removes a range of elements from a List:
list.subList(from, to).clear();
Similar idioms may be constructed for indexOf and lastIndexOf,
and all of the algorithms in the Collections class can be applied to
a subList.
The semantics of the List returned by this method become undefined if
the backing list (i.e., this List) is structurally modified in
any way other than via the returned List. (Structural modifications are
those that change the size of the List, or otherwise perturb it in such
a fashion that iterations in progress may yield incorrect results.)
//return Collections.synchronizedList(super.subList(fromIndex, toIndex),
// this);
return null;
|
public java.lang.Object[] | toArray()Returns an array containing all of the elements in this ModVector
in the correct order.
Object[] result = new Object[elementCount];
System.arraycopy(elementData, 0, result, 0, elementCount);
return result;
|
public T[] | toArray(T[] a)Returns an array containing all of the elements in this ModVector in the
correct order; the runtime type of the returned array is that of the
specified array. If the ModVector fits in the specified array, it is
returned therein. Otherwise, a new array is allocated with the runtime
type of the specified array and the size of this ModVector.
If the ModVector fits in the specified array with room to spare
(i.e., the array has more elements than the ModVector),
the element in the array immediately following the end of the
ModVector is set to null. This is useful in determining the length
of the ModVector only if the caller knows that the ModVector
does not contain any null elements.
if (a.length < elementCount)
a = (T[])java.lang.reflect.Array.newInstance(
a.getClass().getComponentType(), elementCount);
System.arraycopy(elementData, 0, a, 0, elementCount);
if (a.length > elementCount)
a[elementCount] = null;
return a;
|
public java.lang.String | toString()Returns a string representation of this ModVector, containing
the String representation of each element.
return super.toString();
|
public void | trimToSize()Trims the capacity of this vector to be the vector's current
size. If the capacity of this vector is larger than its current
size, then the capacity is changed to equal the size by replacing
its internal data array, kept in the field elementData,
with a smaller one. An application can use this operation to
minimize the storage of a vector.
modCount++;
int oldCapacity = elementData.length;
if (elementCount < oldCapacity) {
Object oldData[] = elementData;
elementData = new Object[elementCount];
System.arraycopy(oldData, 0, elementData, 0, elementCount);
}
|
private void | writeObject(java.io.ObjectOutputStream s)Save the state of the ModVector instance to a stream (that
is, serialize it). This method is present merely for synchronization.
It just calls the default readObject method.
s.defaultWriteObject();
|