mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 08:14:09 -08:00
classlib: fix Stream.dropWhile
This commit is contained in:
parent
31674f9744
commit
d4f98a57d0
|
@ -17,28 +17,42 @@ package org.teavm.classlib.java.util.stream.doubleimpl;
|
||||||
|
|
||||||
import java.util.function.DoublePredicate;
|
import java.util.function.DoublePredicate;
|
||||||
|
|
||||||
public class TDropWhileDoubleStream extends TWrappingDoubleStreamImpl {
|
public class TDropWhileDoubleStream extends TSimpleDoubleStreamImpl {
|
||||||
|
private TSimpleDoubleStreamImpl sourceStream;
|
||||||
private DoublePredicate predicate;
|
private DoublePredicate predicate;
|
||||||
|
|
||||||
/* set to `true` as soon as we see a value `v` in the source stream for which `predicate.test(v)` is true */
|
/* set to `true` as soon as we see a value `v` in the source stream for which `predicate.test(v)` is true */
|
||||||
private boolean isStarted;
|
private boolean isStarted;
|
||||||
|
|
||||||
TDropWhileDoubleStream(TSimpleDoubleStreamImpl innerStream, DoublePredicate predicate) {
|
TDropWhileDoubleStream(TSimpleDoubleStreamImpl sourceStream, DoublePredicate predicate) {
|
||||||
super(innerStream);
|
this.sourceStream = sourceStream;
|
||||||
this.predicate = predicate;
|
this.predicate = predicate;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected DoublePredicate wrap(DoublePredicate consumer) {
|
public boolean next(DoublePredicate consumer) {
|
||||||
return t -> {
|
|
||||||
if (!isStarted) {
|
if (!isStarted) {
|
||||||
|
var skippingPredicate = new DoublePredicate() {
|
||||||
|
boolean consumerCanTakeMore;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean test(double t) {
|
||||||
if (predicate.test(t)) {
|
if (predicate.test(t)) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
}
|
||||||
isStarted = true;
|
isStarted = true;
|
||||||
|
consumerCanTakeMore = consumer.test(t);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return consumer.test(t);
|
|
||||||
};
|
};
|
||||||
|
var result = sourceStream.next(skippingPredicate);
|
||||||
|
if (!result) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!skippingPredicate.consumerCanTakeMore) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sourceStream.next(consumer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,28 +17,42 @@ package org.teavm.classlib.java.util.stream.impl;
|
||||||
|
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
public class TDropWhileStream<T> extends TWrappingStreamImpl<T, T> {
|
public class TDropWhileStream<T> extends TSimpleStreamImpl<T> {
|
||||||
|
private TSimpleStreamImpl<T> sourceStream;
|
||||||
private Predicate<? super T> predicate;
|
private Predicate<? super T> predicate;
|
||||||
|
|
||||||
/* set to `true` as soon as we see a value `v` in the source stream for which `predicate.test(v)` is true */
|
/* set to `true` as soon as we see a value `v` in the source stream for which `predicate.test(v)` is true */
|
||||||
private boolean isStarted;
|
private boolean isStarted;
|
||||||
|
|
||||||
TDropWhileStream(TSimpleStreamImpl<T> innerStream, Predicate<? super T> predicate) {
|
TDropWhileStream(TSimpleStreamImpl<T> sourceStream, Predicate<? super T> predicate) {
|
||||||
super(innerStream);
|
this.sourceStream = sourceStream;
|
||||||
this.predicate = predicate;
|
this.predicate = predicate;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Predicate<T> wrap(Predicate<? super T> consumer) {
|
public boolean next(Predicate<? super T> consumer) {
|
||||||
return t -> {
|
|
||||||
if (!isStarted) {
|
if (!isStarted) {
|
||||||
|
var skippingPredicate = new Predicate<T>() {
|
||||||
|
boolean consumerCanTakeMore;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean test(T t) {
|
||||||
if (predicate.test(t)) {
|
if (predicate.test(t)) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
}
|
||||||
isStarted = true;
|
isStarted = true;
|
||||||
|
consumerCanTakeMore = consumer.test(t);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return consumer.test(t);
|
|
||||||
};
|
};
|
||||||
|
var result = sourceStream.next(skippingPredicate);
|
||||||
|
if (!result) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!skippingPredicate.consumerCanTakeMore) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sourceStream.next(consumer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,28 +17,42 @@ package org.teavm.classlib.java.util.stream.intimpl;
|
||||||
|
|
||||||
import java.util.function.IntPredicate;
|
import java.util.function.IntPredicate;
|
||||||
|
|
||||||
public class TDropWhileIntStream extends TWrappingIntStreamImpl {
|
public class TDropWhileIntStream extends TSimpleIntStreamImpl {
|
||||||
|
private TSimpleIntStreamImpl sourceStream;
|
||||||
private IntPredicate predicate;
|
private IntPredicate predicate;
|
||||||
|
|
||||||
/* set to `true` as soon as we see a value `v` in the source stream for which `predicate.test(v)` is true */
|
/* set to `true` as soon as we see a value `v` in the source stream for which `predicate.test(v)` is true */
|
||||||
private boolean isStarted;
|
private boolean isStarted;
|
||||||
|
|
||||||
TDropWhileIntStream(TSimpleIntStreamImpl innerStream, IntPredicate predicate) {
|
TDropWhileIntStream(TSimpleIntStreamImpl sourceStream, IntPredicate predicate) {
|
||||||
super(innerStream);
|
this.sourceStream = sourceStream;
|
||||||
this.predicate = predicate;
|
this.predicate = predicate;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected IntPredicate wrap(IntPredicate consumer) {
|
public boolean next(IntPredicate consumer) {
|
||||||
return t -> {
|
|
||||||
if (!isStarted) {
|
if (!isStarted) {
|
||||||
|
var skippingPredicate = new IntPredicate() {
|
||||||
|
boolean consumerCanTakeMore;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean test(int t) {
|
||||||
if (predicate.test(t)) {
|
if (predicate.test(t)) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
}
|
||||||
isStarted = true;
|
isStarted = true;
|
||||||
|
consumerCanTakeMore = consumer.test(t);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return consumer.test(t);
|
|
||||||
};
|
};
|
||||||
|
var result = sourceStream.next(skippingPredicate);
|
||||||
|
if (!result) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!skippingPredicate.consumerCanTakeMore) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sourceStream.next(consumer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,28 +17,42 @@ package org.teavm.classlib.java.util.stream.longimpl;
|
||||||
|
|
||||||
import java.util.function.LongPredicate;
|
import java.util.function.LongPredicate;
|
||||||
|
|
||||||
public class TDropWhileLongStream extends TWrappingLongStreamImpl {
|
public class TDropWhileLongStream extends TSimpleLongStreamImpl {
|
||||||
|
private TSimpleLongStreamImpl sourceStream;
|
||||||
private LongPredicate predicate;
|
private LongPredicate predicate;
|
||||||
|
|
||||||
/* set to `true` as soon as we see a value `v` in the source stream for which `predicate.test(v)` is true */
|
/* set to `true` as soon as we see a value `v` in the source stream for which `predicate.test(v)` is true */
|
||||||
private boolean isStarted;
|
private boolean isStarted;
|
||||||
|
|
||||||
TDropWhileLongStream(TSimpleLongStreamImpl innerStream, LongPredicate predicate) {
|
TDropWhileLongStream(TSimpleLongStreamImpl sourceStream, LongPredicate predicate) {
|
||||||
super(innerStream);
|
this.sourceStream = sourceStream;
|
||||||
this.predicate = predicate;
|
this.predicate = predicate;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected LongPredicate wrap(LongPredicate consumer) {
|
public boolean next(LongPredicate consumer) {
|
||||||
return t -> {
|
|
||||||
if (!isStarted) {
|
if (!isStarted) {
|
||||||
|
var skippingPredicate = new LongPredicate() {
|
||||||
|
boolean consumerCanTakeMore;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean test(long t) {
|
||||||
if (predicate.test(t)) {
|
if (predicate.test(t)) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
}
|
||||||
isStarted = true;
|
isStarted = true;
|
||||||
|
consumerCanTakeMore = consumer.test(t);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return consumer.test(t);
|
|
||||||
};
|
};
|
||||||
|
var result = sourceStream.next(skippingPredicate);
|
||||||
|
if (!result) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!skippingPredicate.consumerCanTakeMore) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sourceStream.next(consumer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user