Methods Summary |
---|
public void | add(int location, E object)Adds the specified object into this vector at the specified location. The
object is inserted before any element with the same or a higher index
increasing their index by 1. If the location is equal to the size of this
vector, the object is added at the end.
insertElementAt(object, location);
|
public boolean | add(E object)Adds the specified object at the end of this vector.
addElement(object);
return true;
|
public synchronized boolean | addAll(int location, java.util.Collection collection)Inserts the objects in the specified collection at the specified location
in this vector. The objects are inserted in the order in which they are
returned from the Collection iterator. The elements with an index equal
or higher than {@code location} have their index increased by the size of
the added collection.
if (0 <= location && location <= elementCount) {
int size = collection.size();
if (size == 0) {
return false;
}
int required = size - (elementData.length - elementCount);
if (required > 0) {
growBy(required);
}
int count = elementCount - location;
if (count > 0) {
System.arraycopy(elementData, location, elementData, location
+ size, count);
}
Iterator<? extends E> it = collection.iterator();
while (it.hasNext()) {
elementData[location++] = it.next();
}
elementCount += size;
modCount++;
return true;
}
throw new ArrayIndexOutOfBoundsException(location);
|
public synchronized boolean | addAll(java.util.Collection collection)Adds the objects in the specified collection to the end of this vector.
return addAll(elementCount, collection);
|
public synchronized void | addElement(E object)Adds the specified object at the end of this vector.
if (elementCount == elementData.length) {
growByOne();
}
elementData[elementCount++] = object;
modCount++;
|
public synchronized int | capacity()Returns the number of elements this vector can hold without growing.
return elementData.length;
|
public void | clear()Removes all elements from this vector, leaving it empty.
removeAllElements();
|
public synchronized java.lang.Object | clone()Returns a new vector with the same elements, size, capacity and capacity
increment as this vector.
try {
Vector<E> vector = (Vector<E>) super.clone();
vector.elementData = elementData.clone();
return vector;
} catch (CloneNotSupportedException e) {
return null;
}
|
public boolean | contains(java.lang.Object object)Searches this vector for the specified object.
return indexOf(object, 0) != -1;
|
public synchronized boolean | containsAll(java.util.Collection collection)Searches this vector for all objects in the specified collection.
return super.containsAll(collection);
|
public synchronized void | copyInto(java.lang.Object[] elements)Attempts to copy elements contained by this {@code Vector} into the
corresponding elements of the supplied {@code Object} array.
System.arraycopy(elementData, 0, elements, 0, elementCount);
|
public synchronized E | elementAt(int location)Returns the element at the specified location in this vector.
if (location < elementCount) {
return (E)elementData[location];
}
throw new ArrayIndexOutOfBoundsException(location);
|
public java.util.Enumeration | elements()Returns an enumeration on the elements of this vector. The results of the
enumeration may be affected if the contents of this vector is modified.
return new Enumeration<E>() {
int pos = 0;
public boolean hasMoreElements() {
synchronized (Vector.this) {
return pos < elementCount;
}
}
public E nextElement() {
synchronized (Vector.this) {
if (pos < elementCount) {
return (E)elementData[pos++];
}
}
throw new NoSuchElementException();
}
};
|
public synchronized void | ensureCapacity(int minimumCapacity)Ensures that this vector can hold the specified number of elements
without growing.
if (elementData.length < minimumCapacity) {
int next = (capacityIncrement <= 0 ? elementData.length
: capacityIncrement)
+ elementData.length;
grow(minimumCapacity > next ? minimumCapacity : next);
}
|
public synchronized boolean | equals(java.lang.Object object)Compares the specified object to this vector and returns if they are
equal. The object must be a List which contains the same objects in the
same order.
if (this == object) {
return true;
}
if (object instanceof List) {
List<?> list = (List) object;
if (list.size() != size()) {
return false;
}
int index = 0;
Iterator<?> it = list.iterator();
while (it.hasNext()) {
Object e1 = elementData[index++], e2 = it.next();
if (!(e1 == null ? e2 == null : e1.equals(e2))) {
return false;
}
}
return true;
}
return false;
|
public synchronized E | firstElement()Returns the first element in this vector.
if (elementCount > 0) {
return (E)elementData[0];
}
throw new NoSuchElementException();
|
public synchronized E | get(int location)Returns the element at the specified location in this vector.
return elementAt(location);
|
private void | grow(int newCapacity)
E[] newData = newElementArray(newCapacity);
// Assumes elementCount is <= newCapacity
assert elementCount <= newCapacity;
System.arraycopy(elementData, 0, newData, 0, elementCount);
elementData = newData;
|
private void | growBy(int required)
int adding = 0;
if (capacityIncrement <= 0) {
if ((adding = elementData.length) == 0) {
adding = required;
}
while (adding < required) {
adding += adding;
}
} else {
adding = (required / capacityIncrement) * capacityIncrement;
if (adding < required) {
adding += capacityIncrement;
}
}
E[] newData = newElementArray(elementData.length + adding);
System.arraycopy(elementData, 0, newData, 0, elementCount);
elementData = newData;
|
private void | growByOne()JIT optimization
int adding = 0;
if (capacityIncrement <= 0) {
if ((adding = elementData.length) == 0) {
adding = 1;
}
} else {
adding = capacityIncrement;
}
E[] newData = newElementArray(elementData.length + adding);
System.arraycopy(elementData, 0, newData, 0, elementCount);
elementData = newData;
|
public synchronized int | hashCode()Returns an integer hash code for the receiver. Objects which are equal
return the same value for this method.
int result = 1;
for (int i = 0; i < elementCount; i++) {
result = (31 * result)
+ (elementData[i] == null ? 0 : elementData[i].hashCode());
}
return result;
|
public int | indexOf(java.lang.Object object)Searches in this vector for the index of the specified object. The search
for the object starts at the beginning and moves towards the end of this
vector.
return indexOf(object, 0);
|
public synchronized int | indexOf(java.lang.Object object, int location)Searches in this vector for the index of the specified object. The search
for the object starts at the specified location and moves towards the end
of this vector.
if (object != null) {
for (int i = location; i < elementCount; i++) {
if (object.equals(elementData[i])) {
return i;
}
}
} else {
for (int i = location; i < elementCount; i++) {
if (elementData[i] == null) {
return i;
}
}
}
return -1;
|
public synchronized void | insertElementAt(E object, int location)Inserts the specified object into this vector at the specified location.
This object is inserted before any previous element at the specified
location. All elements with an index equal or greater than
{@code location} have their index increased by 1. If the location is
equal to the size of this vector, the object is added at the end.
if (0 <= location && location <= elementCount) {
if (elementCount == elementData.length) {
growByOne();
}
int count = elementCount - location;
if (count > 0) {
System.arraycopy(elementData, location, elementData,
location + 1, count);
}
elementData[location] = object;
elementCount++;
modCount++;
} else {
throw new ArrayIndexOutOfBoundsException(location);
}
|
public synchronized boolean | isEmpty()Returns if this vector has no elements, a size of zero.
return elementCount == 0;
|
public synchronized E | lastElement()Returns the last element in this vector.
try {
return (E)elementData[elementCount - 1];
} catch (IndexOutOfBoundsException e) {
throw new NoSuchElementException();
}
|
public synchronized int | lastIndexOf(java.lang.Object object)Searches in this vector for the index of the specified object. The search
for the object starts at the end and moves towards the start of this
vector.
return lastIndexOf(object, elementCount - 1);
|
public synchronized int | lastIndexOf(java.lang.Object object, int location)Searches in this vector for the index of the specified object. The search
for the object starts at the specified location and moves towards the
start of this vector.
if (location < elementCount) {
if (object != null) {
for (int i = location; i >= 0; i--) {
if (object.equals(elementData[i])) {
return i;
}
}
} else {
for (int i = location; i >= 0; i--) {
if (elementData[i] == null) {
return i;
}
}
}
return -1;
}
throw new ArrayIndexOutOfBoundsException(location);
|
private E[] | newElementArray(int size)
return (E[])new Object[size];
|
public synchronized E | remove(int location)Removes the object at the specified location from this vector. All
elements with an index bigger than {@code location} have their index
decreased by 1.
if (location < elementCount) {
E result = (E)elementData[location];
elementCount--;
int size = elementCount - location;
if (size > 0) {
System.arraycopy(elementData, location + 1, elementData,
location, size);
}
elementData[elementCount] = null;
modCount++;
return result;
}
throw new ArrayIndexOutOfBoundsException(location);
|
public boolean | remove(java.lang.Object object)Removes the first occurrence, starting at the beginning and moving
towards the end, of the specified object from this vector. All elements
with an index bigger than the element that gets removed have their index
decreased by 1.
return removeElement(object);
|
public synchronized boolean | removeAll(java.util.Collection collection)Removes all occurrences in this vector of each object in the specified
Collection.
return super.removeAll(collection);
|
public synchronized void | removeAllElements()Removes all elements from this vector, leaving the size zero and the
capacity unchanged.
Arrays.fill(elementData, 0, elementCount, null);
modCount++;
elementCount = 0;
|
public synchronized boolean | removeElement(java.lang.Object object)Removes the first occurrence, starting at the beginning and moving
towards the end, of the specified object from this vector. All elements
with an index bigger than the element that gets removed have their index
decreased by 1.
int index;
if ((index = indexOf(object, 0)) == -1) {
return false;
}
removeElementAt(index);
return true;
|
public synchronized void | removeElementAt(int location)Removes the element found at index position {@code location} from
this {@code Vector}. All elements with an index bigger than
{@code location} have their index decreased by 1.
if (0 <= location && location < elementCount) {
elementCount--;
int size = elementCount - location;
if (size > 0) {
System.arraycopy(elementData, location + 1, elementData,
location, size);
}
elementData[elementCount] = null;
modCount++;
} else {
throw new ArrayIndexOutOfBoundsException(location);
}
|
protected void | removeRange(int start, int end)Removes the objects in the specified range from the start to the, but not
including, end index. All elements with an index bigger than or equal to
{@code end} have their index decreased by {@code end - start}.
if (start >= 0 && start <= end && end <= size()) {
if (start == end) {
return;
}
if (end != elementCount) {
System.arraycopy(elementData, end, elementData, start,
elementCount - end);
int newCount = elementCount - (end - start);
Arrays.fill(elementData, newCount, elementCount, null);
elementCount = newCount;
} else {
Arrays.fill(elementData, start, elementCount, null);
elementCount = start;
}
modCount++;
} else {
throw new IndexOutOfBoundsException();
}
|
public synchronized boolean | retainAll(java.util.Collection collection)Removes all objects from this vector that are not contained in the
specified collection.
return super.retainAll(collection);
|
public synchronized E | set(int location, E object)Replaces the element at the specified location in this vector with the
specified object.
if (location < elementCount) {
E result = (E)elementData[location];
elementData[location] = object;
return result;
}
throw new ArrayIndexOutOfBoundsException(location);
|
public synchronized void | setElementAt(E object, int location)Replaces the element at the specified location in this vector with the
specified object.
if (location < elementCount) {
elementData[location] = object;
} else {
throw new ArrayIndexOutOfBoundsException(location);
}
|
public synchronized void | setSize(int length)Sets the size of this vector to the specified size. If there are more
than length elements in this vector, the elements at end are lost. If
there are less than length elements in the vector, the additional
elements contain null.
if (length == elementCount) {
return;
}
ensureCapacity(length);
if (elementCount > length) {
Arrays.fill(elementData, length, elementCount, null);
}
elementCount = length;
modCount++;
|
public synchronized int | size()Returns the number of elements in this vector.
return elementCount;
|
public synchronized java.util.List | subList(int start, int end)Returns a List of the specified portion of this vector from the start
index to one less than the end index. The returned List is backed by this
vector so changes to one are reflected by the other.
return new Collections.SynchronizedRandomAccessList<E>(
super.subList(start, end), this);
|
public synchronized java.lang.Object[] | toArray()Returns a new array containing all elements contained in this vector.
Object[] result = new Object[elementCount];
System.arraycopy(elementData, 0, result, 0, elementCount);
return result;
|
public synchronized T[] | toArray(T[] contents)Returns an array containing all elements contained in this vector. If the
specified array is large enough to hold the elements, the specified array
is used, otherwise an array of the same type is created. If the specified
array is used and is larger than this vector, the array element following
the collection elements is set to null.
if (elementCount > contents.length) {
Class<?> ct = contents.getClass().getComponentType();
contents = (T[]) Array.newInstance(ct, elementCount);
}
System.arraycopy(elementData, 0, contents, 0, elementCount);
if (elementCount < contents.length) {
contents[elementCount] = null;
}
return contents;
|
public synchronized java.lang.String | toString()Returns the string representation of this vector.
if (elementCount == 0) {
return "[]";
}
int length = elementCount - 1;
StringBuffer buffer = new StringBuffer(size() * 16);
buffer.append('[");
for (int i = 0; i < length; i++) {
if (elementData[i] == this) {
buffer.append("(this Collection)");
} else {
buffer.append(elementData[i]);
}
buffer.append(", ");
}
if (elementData[length] == this) {
buffer.append("(this Collection)");
} else {
buffer.append(elementData[length]);
}
buffer.append(']");
return buffer.toString();
|
public synchronized void | trimToSize()Sets the capacity of this vector to be the same as the size.
if (elementData.length != elementCount) {
grow(elementCount);
}
|
private synchronized void | writeObject(java.io.ObjectOutputStream stream)
stream.defaultWriteObject();
|