mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 08:14:09 -08:00
Added missing methods to Optional and ArrayList
This commit is contained in:
parent
7271a394db
commit
0c15600700
|
@ -16,6 +16,7 @@
|
||||||
package org.teavm.classlib.java.util;
|
package org.teavm.classlib.java.util;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.function.Consumer;
|
||||||
import org.teavm.classlib.java.io.TSerializable;
|
import org.teavm.classlib.java.io.TSerializable;
|
||||||
import org.teavm.classlib.java.lang.*;
|
import org.teavm.classlib.java.lang.*;
|
||||||
import org.teavm.classlib.java.util.function.TUnaryOperator;
|
import org.teavm.classlib.java.util.function.TUnaryOperator;
|
||||||
|
@ -187,4 +188,11 @@ public class TArrayList<E> extends TAbstractList<E> implements TCloneable, TSeri
|
||||||
array[i] = operator.apply(array[i]);
|
array[i] = operator.apply(array[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void forEach(Consumer<? super E> action) {
|
||||||
|
for (int i = 0; i < size; i++) {
|
||||||
|
action.accept(array[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,8 @@ import java.util.function.Function;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
import org.teavm.classlib.java.util.stream.TStream;
|
||||||
|
|
||||||
public final class TOptional<T> {
|
public final class TOptional<T> {
|
||||||
private static TOptional<?> emptyInstance;
|
private static TOptional<?> emptyInstance;
|
||||||
private final T value;
|
private final T value;
|
||||||
|
@ -56,6 +58,18 @@ public final class TOptional<T> {
|
||||||
return value != null;
|
return value != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isEmpty() {
|
||||||
|
return value == null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TStream<T> stream() {
|
||||||
|
if (!isPresent()) {
|
||||||
|
return TStream.empty();
|
||||||
|
} else {
|
||||||
|
return TStream.of(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void ifPresent(Consumer<? super T> consumer) {
|
public void ifPresent(Consumer<? super T> consumer) {
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
consumer.accept(value);
|
consumer.accept(value);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user