diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/TArrayList.java b/classlib/src/main/java/org/teavm/classlib/java/util/TArrayList.java index 22728d3b7..12146335a 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/TArrayList.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/TArrayList.java @@ -16,6 +16,7 @@ package org.teavm.classlib.java.util; import java.util.Arrays; +import java.util.function.Consumer; import org.teavm.classlib.java.io.TSerializable; import org.teavm.classlib.java.lang.*; import org.teavm.classlib.java.util.function.TUnaryOperator; @@ -187,4 +188,11 @@ public class TArrayList extends TAbstractList implements TCloneable, TSeri array[i] = operator.apply(array[i]); } } + + @Override + public void forEach(Consumer action) { + for (int i = 0; i < size; i++) { + action.accept(array[i]); + } + } } diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/TOptional.java b/classlib/src/main/java/org/teavm/classlib/java/util/TOptional.java index b7661aa64..901bfe817 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/TOptional.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/TOptional.java @@ -21,6 +21,8 @@ import java.util.function.Function; import java.util.function.Predicate; import java.util.function.Supplier; +import org.teavm.classlib.java.util.stream.TStream; + public final class TOptional { private static TOptional emptyInstance; private final T value; @@ -56,6 +58,18 @@ public final class TOptional { return value != null; } + public boolean isEmpty() { + return value == null; + } + + public TStream stream() { + if (!isPresent()) { + return TStream.empty(); + } else { + return TStream.of(value); + } + } + public void ifPresent(Consumer consumer) { if (value != null) { consumer.accept(value);