mirror of
https://github.com/corda/corda.git
synced 2025-02-10 12:51:37 +00:00
add java.util.Collection.toArray()
This commit is contained in:
parent
7911989055
commit
0a7f94abfe
@ -62,6 +62,10 @@ public abstract class AbstractCollection<T> implements Collection<T> {
|
||||
|
||||
public abstract int size();
|
||||
|
||||
public Object[] toArray() {
|
||||
return toArray(new Object[size()]);
|
||||
}
|
||||
|
||||
public <S> S[] toArray(S[] array) {
|
||||
return Collections.toArray(this, array);
|
||||
}
|
||||
|
@ -159,10 +159,6 @@ public class ArrayList<T> extends AbstractList<T> {
|
||||
return size() == 0;
|
||||
}
|
||||
|
||||
public <S> S[] toArray(S[] a) {
|
||||
return Collections.toArray(this, a);
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
array = null;
|
||||
size = 0;
|
||||
|
@ -81,6 +81,10 @@ public class Arrays {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public Object[] toArray() {
|
||||
return toArray(new Object[size()]);
|
||||
}
|
||||
|
||||
public <S> S[] toArray(S[] a) {
|
||||
return (S[])array;
|
||||
}
|
||||
|
@ -23,6 +23,8 @@ public interface Collection<T> extends Iterable<T> {
|
||||
|
||||
public boolean remove(Object element);
|
||||
|
||||
public Object[] toArray();
|
||||
|
||||
public <S> S[] toArray(S[] array);
|
||||
|
||||
public void clear();
|
||||
|
@ -129,6 +129,10 @@ public class Collections {
|
||||
synchronized (lock) { return collection.remove((T)e); }
|
||||
}
|
||||
|
||||
public Object[] toArray() {
|
||||
return toArray(new Object[size()]);
|
||||
}
|
||||
|
||||
public <T> T[] toArray(T[] array) {
|
||||
synchronized (lock) { return collection.toArray(array); }
|
||||
}
|
||||
@ -319,10 +323,13 @@ public class Collections {
|
||||
return inner.size();
|
||||
}
|
||||
|
||||
public Object[] toArray() {
|
||||
return toArray(new Object[size()]);
|
||||
}
|
||||
|
||||
public <S> S[] toArray(S[] array) {
|
||||
return inner.toArray(array);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> Set<T> unmodifiableSet(Set<T> hs) {
|
||||
|
@ -334,6 +334,10 @@ public class HashMap<K, V> implements Map<K, V> {
|
||||
return removeCell(e.getKey()) != null;
|
||||
}
|
||||
|
||||
public Object[] toArray() {
|
||||
return toArray(new Object[size()]);
|
||||
}
|
||||
|
||||
public <T> T[] toArray(T[] array) {
|
||||
return Collections.toArray(this, array);
|
||||
}
|
||||
@ -374,6 +378,10 @@ public class HashMap<K, V> implements Map<K, V> {
|
||||
return removeCell(key) != null;
|
||||
}
|
||||
|
||||
public Object[] toArray() {
|
||||
return toArray(new Object[size()]);
|
||||
}
|
||||
|
||||
public <T> T[] toArray(T[] array) {
|
||||
return Collections.toArray(this, array);
|
||||
}
|
||||
@ -412,6 +420,10 @@ public class HashMap<K, V> implements Map<K, V> {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public Object[] toArray() {
|
||||
return toArray(new Object[size()]);
|
||||
}
|
||||
|
||||
public <T> T[] toArray(T[] array) {
|
||||
return Collections.toArray(this, array);
|
||||
}
|
||||
|
@ -10,7 +10,7 @@
|
||||
|
||||
package java.util;
|
||||
|
||||
public class HashSet<T> implements Set<T> {
|
||||
public class HashSet<T> extends AbstractSet<T> implements Set<T> {
|
||||
private static final Object Value = new Object();
|
||||
|
||||
private final HashMap<T, Object> map;
|
||||
@ -54,10 +54,6 @@ public class HashSet<T> implements Set<T> {
|
||||
return map.remove(element) != Value;
|
||||
}
|
||||
|
||||
public <T> T[] toArray(T[] array) {
|
||||
return Collections.toArray(this, array);
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
map.clear();
|
||||
}
|
||||
|
@ -85,10 +85,6 @@ public class LinkedList<T> extends AbstractSequentialList<T> {
|
||||
}
|
||||
}
|
||||
|
||||
public <S> S[] toArray(S[] a) {
|
||||
return Collections.toArray(this, a);
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return size;
|
||||
}
|
||||
|
@ -144,6 +144,10 @@ public class TreeMap<K,V> implements Map<K,V> {
|
||||
return set.removeAndReturn(new MyEntry(key, null)) != null;
|
||||
}
|
||||
|
||||
public Object[] toArray() {
|
||||
return toArray(new Object[size()]);
|
||||
}
|
||||
|
||||
public <T> T[] toArray(T[] array) {
|
||||
return Collections.toArray(this, array);
|
||||
}
|
||||
@ -182,6 +186,10 @@ public class TreeMap<K,V> implements Map<K,V> {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public Object[] toArray() {
|
||||
return toArray(new Object[size()]);
|
||||
}
|
||||
|
||||
public <T> T[] toArray(T[] array) {
|
||||
return Collections.toArray(this, array);
|
||||
}
|
||||
|
@ -77,10 +77,6 @@ public class Vector<T> extends AbstractList<T> {
|
||||
return list.isEmpty();
|
||||
}
|
||||
|
||||
public synchronized <S> S[] toArray(S[] a) {
|
||||
return list.toArray(a);
|
||||
}
|
||||
|
||||
public void removeElementAt(int index) {
|
||||
remove(index);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user