mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 16:14:10 -08:00
Add several unimplemented collection methods
This commit is contained in:
parent
608e62ae3b
commit
5fa48c089a
|
@ -18,13 +18,9 @@ package org.teavm.classlib.java.util;
|
|||
import java.util.Arrays;
|
||||
import org.teavm.classlib.java.io.TSerializable;
|
||||
import org.teavm.classlib.java.lang.*;
|
||||
import org.teavm.classlib.java.util.function.TUnaryOperator;
|
||||
import org.teavm.interop.Rename;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Alexey Andreev
|
||||
* @param <E>
|
||||
*/
|
||||
public class TArrayList<E> extends TAbstractList<E> implements TCloneable, TSerializable {
|
||||
private E[] array;
|
||||
private int size;
|
||||
|
@ -184,4 +180,11 @@ public class TArrayList<E> extends TAbstractList<E> implements TCloneable, TSeri
|
|||
throw new TIndexOutOfBoundsException();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void replaceAll(TUnaryOperator<E> operator) {
|
||||
for (int i = 0; i < size; ++i) {
|
||||
array[i] = operator.apply(array[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,6 +18,10 @@ package org.teavm.classlib.java.util;
|
|||
import java.lang.reflect.Array;
|
||||
import java.util.Objects;
|
||||
import java.util.RandomAccess;
|
||||
import java.util.function.IntFunction;
|
||||
import java.util.function.IntToDoubleFunction;
|
||||
import java.util.function.IntToLongFunction;
|
||||
import java.util.function.IntUnaryOperator;
|
||||
import org.teavm.classlib.java.lang.TClass;
|
||||
import org.teavm.classlib.java.lang.TComparable;
|
||||
import org.teavm.classlib.java.lang.TDouble;
|
||||
|
@ -1600,4 +1604,28 @@ public class TArrays extends TObject {
|
|||
}
|
||||
return new TArrayDoubleStreamImpl(array, startInclusive, endExclusive);
|
||||
}
|
||||
|
||||
public static <T> void setAll(T[] array, IntFunction<? extends T> generator) {
|
||||
for (int i = 0; i < array.length; ++i) {
|
||||
array[i] = generator.apply(i);
|
||||
}
|
||||
}
|
||||
|
||||
public static void setAll(int[] array, IntUnaryOperator generator) {
|
||||
for (int i = 0; i < array.length; ++i) {
|
||||
array[i] = generator.applyAsInt(i);
|
||||
}
|
||||
}
|
||||
|
||||
public static void setAll(long[] array, IntToLongFunction generator) {
|
||||
for (int i = 0; i < array.length; ++i) {
|
||||
array[i] = generator.applyAsLong(i);
|
||||
}
|
||||
}
|
||||
|
||||
public static void setAll(double[] array, IntToDoubleFunction generator) {
|
||||
for (int i = 0; i < array.length; ++i) {
|
||||
array[i] = generator.applyAsDouble(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -89,9 +89,6 @@ public class TLinkedList<E> extends TAbstractSequentialList<E> implements TDeque
|
|||
|
||||
@Override
|
||||
public boolean offer(E e) {
|
||||
if (e == null) {
|
||||
throw new IllegalArgumentException("Element can't be null");
|
||||
}
|
||||
Entry<E> entry = new Entry<>();
|
||||
entry.item = e;
|
||||
entry.next = firstEntry;
|
||||
|
@ -108,11 +105,10 @@ public class TLinkedList<E> extends TAbstractSequentialList<E> implements TDeque
|
|||
|
||||
@Override
|
||||
public E remove() {
|
||||
E elem = poll();
|
||||
if (elem == null) {
|
||||
if (isEmpty()) {
|
||||
throw new TNoSuchElementException();
|
||||
}
|
||||
return elem;
|
||||
return poll();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -152,9 +148,6 @@ public class TLinkedList<E> extends TAbstractSequentialList<E> implements TDeque
|
|||
|
||||
@Override
|
||||
public void addLast(E e) {
|
||||
if (e == null) {
|
||||
throw new IllegalArgumentException("Element can't be null");
|
||||
}
|
||||
Entry<E> entry = new Entry<>();
|
||||
entry.item = e;
|
||||
entry.previous = lastEntry;
|
||||
|
@ -187,11 +180,10 @@ public class TLinkedList<E> extends TAbstractSequentialList<E> implements TDeque
|
|||
|
||||
@Override
|
||||
public E removeLast() {
|
||||
E elem = pollLast();
|
||||
if (elem == null) {
|
||||
if (isEmpty()) {
|
||||
throw new TNoSuchElementException();
|
||||
}
|
||||
return elem;
|
||||
return pollLast();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -15,6 +15,8 @@
|
|||
*/
|
||||
package org.teavm.classlib.java.util;
|
||||
|
||||
import org.teavm.classlib.java.util.function.TUnaryOperator;
|
||||
|
||||
public interface TList<E> extends TCollection<E> {
|
||||
boolean addAll(int index, TCollection<? extends E> c);
|
||||
|
||||
|
@ -36,6 +38,13 @@ public interface TList<E> extends TCollection<E> {
|
|||
|
||||
TList<E> subList(int fromIndex, int toIndex);
|
||||
|
||||
default void replaceAll(TUnaryOperator<E> operator) {
|
||||
TListIterator<E> iter = listIterator();
|
||||
while (iter.hasNext()) {
|
||||
iter.set(operator.apply(iter.next()));
|
||||
}
|
||||
}
|
||||
|
||||
default void sort(TComparator<? super E> c) {
|
||||
TCollections.sort(this, c);
|
||||
}
|
||||
|
|
|
@ -52,6 +52,10 @@ public final class TObjects extends TObject {
|
|||
return obj;
|
||||
}
|
||||
|
||||
public static boolean nonNull(Object obj) {
|
||||
return obj != null;
|
||||
}
|
||||
|
||||
public static boolean deepEquals(Object a, Object b) {
|
||||
if (a == b) {
|
||||
return true;
|
||||
|
|
Loading…
Reference in New Issue
Block a user