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); this(0);
} }
public ArrayList(Collection<T> source) { public ArrayList(Collection<? extends T> source) {
this(source.size()); this(source.size());
for (T o : source) { addAll(source);
add(o);
}
} }
private void grow() { private void grow() {
@ -162,20 +160,7 @@ public class ArrayList<T> implements List<T> {
} }
public <S> S[] toArray(S[] a) { public <S> S[] toArray(S[] a) {
Object[] retVal = null; return Collections.toArray(this, a);
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;
} }
public void clear() { public void clear() {

View File

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

View File

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

View File

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

View File

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

View File

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