2015-03-13 18:52:59 +00:00
|
|
|
/* Copyright (c) 2008-2015, Avian Contributors
|
2008-02-19 18:06:52 +00:00
|
|
|
|
|
|
|
Permission to use, copy, modify, and/or distribute this software
|
|
|
|
for any purpose with or without fee is hereby granted, provided
|
|
|
|
that the above copyright notice and this permission notice appear
|
|
|
|
in all copies.
|
|
|
|
|
|
|
|
There is NO WARRANTY for this software. See license.txt for
|
|
|
|
details. */
|
|
|
|
|
2007-07-22 03:47:29 +00:00
|
|
|
package java.util;
|
|
|
|
|
2014-04-16 20:33:32 +00:00
|
|
|
public class Vector<T> extends AbstractList<T> implements java.io.Serializable, Cloneable, RandomAccess {
|
2007-07-22 03:47:29 +00:00
|
|
|
private final ArrayList<T> list;
|
|
|
|
|
|
|
|
public Vector(int capacity) {
|
|
|
|
list = new ArrayList(capacity);
|
|
|
|
}
|
|
|
|
|
|
|
|
public Vector() {
|
|
|
|
this(0);
|
|
|
|
}
|
|
|
|
|
2008-02-28 22:18:46 +00:00
|
|
|
public Vector(Collection<? extends T> source) {
|
|
|
|
list = new ArrayList(source);
|
2007-09-26 14:57:34 +00:00
|
|
|
}
|
|
|
|
|
2007-07-22 03:47:29 +00:00
|
|
|
public synchronized int size() {
|
|
|
|
return list.size();
|
|
|
|
}
|
|
|
|
|
2009-04-22 21:24:26 +00:00
|
|
|
public synchronized boolean contains(Object element) {
|
2007-07-22 19:06:21 +00:00
|
|
|
return list.contains(element);
|
|
|
|
}
|
|
|
|
|
2007-09-26 16:32:39 +00:00
|
|
|
public synchronized void add(int index, T element) {
|
|
|
|
list.add(index, element);
|
|
|
|
}
|
|
|
|
|
2008-03-21 00:40:18 +00:00
|
|
|
public void insertElementAt(T element, int index) {
|
|
|
|
add(index, element);
|
|
|
|
}
|
|
|
|
|
2007-07-22 03:47:29 +00:00
|
|
|
public synchronized boolean add(T element) {
|
|
|
|
return list.add(element);
|
|
|
|
}
|
|
|
|
|
2008-02-28 18:37:10 +00:00
|
|
|
public synchronized boolean addAll(Collection<? extends T> collection) {
|
|
|
|
return list.addAll(collection);
|
|
|
|
}
|
|
|
|
|
2007-07-22 03:47:29 +00:00
|
|
|
public void addElement(T element) {
|
|
|
|
add(element);
|
|
|
|
}
|
|
|
|
|
|
|
|
public synchronized T get(int index) {
|
|
|
|
return list.get(index);
|
|
|
|
}
|
|
|
|
|
2007-11-14 16:32:36 +00:00
|
|
|
public synchronized T set(int index, T value) {
|
|
|
|
return list.set(index, value);
|
|
|
|
}
|
|
|
|
|
2008-11-11 15:20:49 +00:00
|
|
|
public void setElementAt(T value, int index) {
|
|
|
|
set(index, value);
|
2008-03-21 00:40:18 +00:00
|
|
|
}
|
|
|
|
|
2007-07-22 03:47:29 +00:00
|
|
|
public T elementAt(int index) {
|
|
|
|
return get(index);
|
|
|
|
}
|
|
|
|
|
|
|
|
public synchronized T remove(int index) {
|
|
|
|
return list.remove(index);
|
|
|
|
}
|
|
|
|
|
2007-09-26 14:57:34 +00:00
|
|
|
public synchronized boolean isEmpty() {
|
|
|
|
return list.isEmpty();
|
|
|
|
}
|
|
|
|
|
2007-10-15 20:06:06 +00:00
|
|
|
public void removeElementAt(int index) {
|
|
|
|
remove(index);
|
2007-08-30 23:31:32 +00:00
|
|
|
}
|
|
|
|
|
2011-07-01 14:43:43 +00:00
|
|
|
public synchronized void removeAllElements() {
|
|
|
|
list.clear();
|
|
|
|
}
|
|
|
|
|
2009-04-22 21:24:26 +00:00
|
|
|
public synchronized boolean remove(Object element) {
|
2007-07-22 03:47:29 +00:00
|
|
|
return list.remove(element);
|
|
|
|
}
|
|
|
|
|
2007-08-30 23:31:32 +00:00
|
|
|
public boolean removeElement(T element) {
|
|
|
|
return remove(element);
|
|
|
|
}
|
|
|
|
|
2007-07-22 03:47:29 +00:00
|
|
|
public synchronized void clear() {
|
|
|
|
list.clear();
|
|
|
|
}
|
|
|
|
|
2009-08-04 23:58:31 +00:00
|
|
|
public synchronized int indexOf(Object element) {
|
2007-08-30 23:31:32 +00:00
|
|
|
return list.indexOf(element);
|
|
|
|
}
|
|
|
|
|
2009-08-04 23:58:31 +00:00
|
|
|
public synchronized int lastIndexOf(Object element) {
|
2007-08-30 23:31:32 +00:00
|
|
|
return list.lastIndexOf(element);
|
|
|
|
}
|
|
|
|
|
2007-07-22 19:06:21 +00:00
|
|
|
public synchronized void copyInto(Object[] array) {
|
|
|
|
for (int i = 0; i < size(); ++i) {
|
|
|
|
array[i] = list.get(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-22 03:47:29 +00:00
|
|
|
public Iterator<T> iterator() {
|
2009-08-04 23:24:29 +00:00
|
|
|
return listIterator();
|
|
|
|
}
|
|
|
|
|
|
|
|
public ListIterator<T> listIterator(int index) {
|
|
|
|
return new Collections.ArrayListIterator(this, index);
|
|
|
|
}
|
|
|
|
|
|
|
|
public ListIterator<T> listIterator() {
|
|
|
|
return listIterator(0);
|
2007-07-22 03:47:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public Enumeration<T> elements() {
|
|
|
|
return new Collections.IteratorEnumeration(iterator());
|
|
|
|
}
|
2013-10-25 18:28:32 +00:00
|
|
|
|
|
|
|
public synchronized Object clone() {
|
|
|
|
Vector copy = new Vector(size());
|
|
|
|
for (T t : this) {
|
|
|
|
copy.add(t);
|
|
|
|
}
|
|
|
|
return copy;
|
|
|
|
}
|
2007-07-22 03:47:29 +00:00
|
|
|
}
|