summaryrefslogtreecommitdiffstats
path: root/libjava/classpath/java/util/Vector.java
diff options
context:
space:
mode:
Diffstat (limited to 'libjava/classpath/java/util/Vector.java')
-rw-r--r--libjava/classpath/java/util/Vector.java84
1 files changed, 44 insertions, 40 deletions
diff --git a/libjava/classpath/java/util/Vector.java b/libjava/classpath/java/util/Vector.java
index eb72ae49df8..ea29ce09315 100644
--- a/libjava/classpath/java/util/Vector.java
+++ b/libjava/classpath/java/util/Vector.java
@@ -82,8 +82,8 @@ import java.lang.reflect.Array;
* @since 1.0
* @status updated to 1.4
*/
-public class Vector extends AbstractList
- implements List, RandomAccess, Cloneable, Serializable
+public class Vector<T> extends AbstractList<T>
+ implements List<T>, RandomAccess, Cloneable, Serializable
{
/**
* Compatible with JDK 1.0+.
@@ -95,7 +95,7 @@ public class Vector extends AbstractList
* in positions 0 through elementCount - 1, and all remaining slots are null.
* @serial the elements
*/
- protected Object[] elementData;
+ protected T[] elementData;
/**
* The number of elements currently in the vector, also returned by
@@ -130,10 +130,10 @@ public class Vector extends AbstractList
* @throws NullPointerException if c is null
* @since 1.2
*/
- public Vector(Collection c)
+ public Vector(Collection<? extends T> c)
{
elementCount = c.size();
- elementData = c.toArray(new Object[elementCount]);
+ elementData = c.toArray((T[]) new Object[elementCount]);
}
/**
@@ -149,7 +149,7 @@ public class Vector extends AbstractList
{
if (initialCapacity < 0)
throw new IllegalArgumentException();
- elementData = new Object[initialCapacity];
+ elementData = (T[]) new Object[initialCapacity];
this.capacityIncrement = capacityIncrement;
}
@@ -192,7 +192,7 @@ public class Vector extends AbstractList
// vector since that is a much less likely case; it's more efficient to
// not do the check and lose a bit of performance in that infrequent case
- Object[] newArray = new Object[elementCount];
+ T[] newArray = (T[]) new Object[elementCount];
System.arraycopy(elementData, 0, newArray, 0, elementCount);
elementData = newArray;
}
@@ -218,7 +218,7 @@ public class Vector extends AbstractList
else
newCapacity = elementData.length + capacityIncrement;
- Object[] newArray = new Object[Math.max(newCapacity, minCapacity)];
+ T[] newArray = (T[]) new Object[Math.max(newCapacity, minCapacity)];
System.arraycopy(elementData, 0, newArray, 0, elementCount);
elementData = newArray;
@@ -284,9 +284,9 @@ public class Vector extends AbstractList
* @see #iterator()
*/
// No need to synchronize as the Enumeration is not thread-safe!
- public Enumeration elements()
+ public Enumeration<T> elements()
{
- return new Enumeration()
+ return new Enumeration<T>()
{
private int i = 0;
@@ -295,7 +295,7 @@ public class Vector extends AbstractList
return i < elementCount;
}
- public Object nextElement()
+ public T nextElement()
{
if (i >= elementCount)
throw new NoSuchElementException();
@@ -385,7 +385,7 @@ public class Vector extends AbstractList
* @throws ArrayIndexOutOfBoundsException index &lt; 0 || index &gt;= size()
* @see #get(int)
*/
- public synchronized Object elementAt(int index)
+ public synchronized T elementAt(int index)
{
checkBoundExclusive(index);
return elementData[index];
@@ -397,7 +397,7 @@ public class Vector extends AbstractList
* @return the first Object in the Vector
* @throws NoSuchElementException the Vector is empty
*/
- public synchronized Object firstElement()
+ public synchronized T firstElement()
{
if (elementCount == 0)
throw new NoSuchElementException();
@@ -411,7 +411,7 @@ public class Vector extends AbstractList
* @return the last Object in the Vector
* @throws NoSuchElementException the Vector is empty
*/
- public synchronized Object lastElement()
+ public synchronized T lastElement()
{
if (elementCount == 0)
throw new NoSuchElementException();
@@ -427,7 +427,7 @@ public class Vector extends AbstractList
* @throws ArrayIndexOutOfBoundsException the index is out of range
* @see #set(int, Object)
*/
- public void setElementAt(Object obj, int index)
+ public void setElementAt(T obj, int index)
{
set(index, obj);
}
@@ -454,7 +454,7 @@ public class Vector extends AbstractList
* @throws ArrayIndexOutOfBoundsException index &lt; 0 || index &gt; size()
* @see #add(int, Object)
*/
- public synchronized void insertElementAt(Object obj, int index)
+ public synchronized void insertElementAt(T obj, int index)
{
checkBoundInclusive(index);
if (elementCount == elementData.length)
@@ -472,7 +472,7 @@ public class Vector extends AbstractList
*
* @param obj the object to add to the Vector
*/
- public synchronized void addElement(Object obj)
+ public synchronized void addElement(T obj)
{
if (elementCount == elementData.length)
ensureCapacity(elementCount + 1);
@@ -570,11 +570,11 @@ public class Vector extends AbstractList
* @throws NullPointerException if <code>a</code> is null
* @since 1.2
*/
- public synchronized Object[] toArray(Object[] a)
+ public synchronized <S> S[] toArray(S[] a)
{
if (a.length < elementCount)
- a = (Object[]) Array.newInstance(a.getClass().getComponentType(),
- elementCount);
+ a = (S[]) Array.newInstance(a.getClass().getComponentType(),
+ elementCount);
else if (a.length > elementCount)
a[elementCount] = null;
System.arraycopy(elementData, 0, a, 0, elementCount);
@@ -589,7 +589,7 @@ public class Vector extends AbstractList
* @throws ArrayIndexOutOfBoundsException index &lt; 0 || index &gt;= size()
* @since 1.2
*/
- public Object get(int index)
+ public T get(int index)
{
return elementAt(index);
}
@@ -604,10 +604,10 @@ public class Vector extends AbstractList
* @throws ArrayIndexOutOfBoundsException index &lt; 0 || index &gt;= size()
* @since 1.2
*/
- public synchronized Object set(int index, Object element)
+ public synchronized T set(int index, T element)
{
checkBoundExclusive(index);
- Object temp = elementData[index];
+ T temp = elementData[index];
elementData[index] = element;
return temp;
}
@@ -619,7 +619,7 @@ public class Vector extends AbstractList
* @return true, as specified by List
* @since 1.2
*/
- public boolean add(Object o)
+ public boolean add(T o)
{
addElement(o);
return true;
@@ -647,7 +647,7 @@ public class Vector extends AbstractList
* @throws ArrayIndexOutOfBoundsException index &lt; 0 || index &gt; size()
* @since 1.2
*/
- public void add(int index, Object element)
+ public void add(int index, T element)
{
insertElementAt(element, index);
}
@@ -660,10 +660,10 @@ public class Vector extends AbstractList
* @throws ArrayIndexOutOfBoundsException index &lt; 0 || index &gt;= size()
* @since 1.2
*/
- public synchronized Object remove(int index)
+ public synchronized T remove(int index)
{
checkBoundExclusive(index);
- Object temp = elementData[index];
+ T temp = elementData[index];
modCount++;
elementCount--;
if (index < elementCount)
@@ -689,7 +689,7 @@ public class Vector extends AbstractList
* @throws NullPointerException if c is null
* @since 1.2
*/
- public synchronized boolean containsAll(Collection c)
+ public synchronized boolean containsAll(Collection<?> c)
{
// Here just for the sychronization.
return super.containsAll(c);
@@ -705,7 +705,7 @@ public class Vector extends AbstractList
* @throws NullPointerException if c is null
* @since 1.2
*/
- public synchronized boolean addAll(Collection c)
+ public synchronized boolean addAll(Collection<? extends T> c)
{
return addAll(elementCount, c);
}
@@ -718,10 +718,12 @@ public class Vector extends AbstractList
* @throws NullPointerException if c is null
* @since 1.2
*/
- public synchronized boolean removeAll(Collection c)
+ public synchronized boolean removeAll(Collection<?> c)
{
- if (c == null)
- throw new NullPointerException();
+ // The NullPointerException is thrown implicitly when the Vector
+ // is not empty and c is null. The RI allows null arguments when
+ // the vector is empty. See Mauve test:
+ // gnu/testlet/java/util/Vector/removeAll.java
int i;
int j;
@@ -747,10 +749,12 @@ public class Vector extends AbstractList
* @throws NullPointerException if c is null
* @since 1.2
*/
- public synchronized boolean retainAll(Collection c)
+ public synchronized boolean retainAll(Collection<?> c)
{
- if (c == null)
- throw new NullPointerException();
+ // The NullPointerException is thrown implicitly when the Vector
+ // is not empty and c is null. The RI allows null arguments when
+ // the vector is empty. See Mauve test:
+ // gnu/testlet/java/util/Vector/retainAll.java
int i;
int j;
@@ -779,10 +783,10 @@ public class Vector extends AbstractList
* @throws ArrayIndexOutOfBoundsException index &lt; 0 || index &gt; size()
* @since 1.2
*/
- public synchronized boolean addAll(int index, Collection c)
+ public synchronized boolean addAll(int index, Collection<? extends T> c)
{
checkBoundInclusive(index);
- Iterator itr = c.iterator();
+ Iterator<? extends T> itr = c.iterator();
int csize = c.size();
modCount++;
@@ -853,12 +857,12 @@ public class Vector extends AbstractList
* @see ConcurrentModificationException
* @since 1.2
*/
- public synchronized List subList(int fromIndex, int toIndex)
+ public synchronized List<T> subList(int fromIndex, int toIndex)
{
- List sub = super.subList(fromIndex, toIndex);
+ List<T> sub = super.subList(fromIndex, toIndex);
// We must specify the correct object to synchronize upon, hence the
// use of a non-public API
- return new Collections.SynchronizedList(this, sub);
+ return new Collections.SynchronizedList<T>(this, sub);
}
/**
OpenPOWER on IntegriCloud