mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 08:14:09 -08:00
classlib: more argument validation in Collections methods (#839)
This commit is contained in:
parent
5b5c26cf99
commit
2756fe4384
|
@ -183,6 +183,9 @@ public class TCollections extends TObject {
|
|||
}
|
||||
|
||||
public static <T> TList<T> nCopies(final int n, final T o) {
|
||||
if (n < 0) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
return new TAbstractList<>() {
|
||||
@Override public T get(int index) {
|
||||
if (index < 0 || index >= n) {
|
||||
|
@ -455,6 +458,7 @@ public class TCollections extends TObject {
|
|||
}
|
||||
|
||||
public static <T> TList<T> unmodifiableList(final TList<? extends T> list) {
|
||||
TObjects.requireNonNull(list);
|
||||
return new TAbstractList<>() {
|
||||
@Override public T get(int index) {
|
||||
return list.get(index);
|
||||
|
@ -462,10 +466,14 @@ public class TCollections extends TObject {
|
|||
@Override public int size() {
|
||||
return list.size();
|
||||
}
|
||||
@Override public boolean remove(Object o) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static <T> TCollection<T> unmodifiableCollection(final TCollection<? extends T> c) {
|
||||
TObjects.requireNonNull(c);
|
||||
return new TAbstractCollection<>() {
|
||||
@Override public TIterator<T> iterator() {
|
||||
return unmodifiableIterator(c.iterator());
|
||||
|
@ -473,6 +481,9 @@ public class TCollections extends TObject {
|
|||
@Override public int size() {
|
||||
return c.size();
|
||||
}
|
||||
@Override public boolean remove(Object o) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -491,6 +502,7 @@ public class TCollections extends TObject {
|
|||
}
|
||||
|
||||
public static <T> TSet<T> unmodifiableSet(final TSet<? extends T> s) {
|
||||
TObjects.requireNonNull(s);
|
||||
return new TAbstractSet<>() {
|
||||
@Override public TIterator<T> iterator() {
|
||||
return unmodifiableIterator(s.iterator());
|
||||
|
@ -498,14 +510,21 @@ public class TCollections extends TObject {
|
|||
@Override public int size() {
|
||||
return s.size();
|
||||
}
|
||||
@Override public boolean remove(Object o) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static <K, V> TMap<K, V> unmodifiableMap(final TMap<? extends K, ? extends V> m) {
|
||||
TObjects.requireNonNull(m);
|
||||
return new TAbstractMap<>() {
|
||||
@Override public TSet<Entry<K, V>> entrySet() {
|
||||
return unmodifiableMapEntrySet(m.entrySet());
|
||||
}
|
||||
@Override public V remove(Object o) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -518,6 +537,9 @@ public class TCollections extends TObject {
|
|||
@Override public TIterator<Entry<K, V>> iterator() {
|
||||
return unmodifiableMapEntryIterator(c.iterator());
|
||||
}
|
||||
@Override public boolean remove(Object o) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user