java.util code cleanup

This commit is contained in:
Joel Dice 2008-02-28 15:18:46 -07:00
parent e93ea33f82
commit 51a731847a
6 changed files with 8 additions and 28 deletions

View File

@ -24,11 +24,9 @@ public class ArrayList<T> implements List<T> {
this(0);
}
public ArrayList(Collection<T> source) {
public ArrayList(Collection<? extends T> source) {
this(source.size());
for (T o : source) {
add(o);
}
addAll(source);
}
private void grow() {
@ -162,20 +160,7 @@ public class ArrayList<T> implements List<T> {
}
public <S> S[] toArray(S[] a) {
Object[] retVal = null;
if (a.length >= size) {
retVal = a;
} else {
retVal = new Object[size];
}
for (int i = 0; i < size; ++i) {
retVal[i] = array[i];
}
if (a.length > size) {
a[size] = null;
}
return (S[])retVal;
return Collections.toArray(this, a);
}
public void clear() {

View File

@ -23,7 +23,7 @@ public interface Collection<T> extends Iterable<T> {
public boolean remove(T element);
public <T> T[] toArray(T[] array);
public <S> S[] toArray(S[] array);
public void clear();
}

View File

@ -15,7 +15,7 @@ public class HashSet<T> implements Set<T> {
private final HashMap<T, Object> map;
public HashSet(Collection<T> c) {
public HashSet(Collection<? extends T> c) {
map = new HashMap(c.size());
addAll(c);
}

View File

@ -15,7 +15,7 @@ public class LinkedList<T> implements List<T> {
private Cell<T> rear;
private int size;
public LinkedList(Collection<T> c) {
public LinkedList(Collection<? extends T> c) {
addAll(c);
}

View File

@ -22,6 +22,4 @@ public interface List<T> extends Collection<T> {
public void add(int index, T element);
public boolean isEmpty();
public <S> S[] toArray(S[] a);
}

View File

@ -21,11 +21,8 @@ public class Vector<T> implements List<T> {
this(0);
}
public Vector(List<T> list) {
this(list.size());
for (T o : list) {
add(o);
}
public Vector(Collection<? extends T> source) {
list = new ArrayList(source);
}
public synchronized int size() {