下面列出了java.util.Spliterator# OfDouble ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public Spliterator.OfDouble trySplit() {
splits++;
Spliterator.OfDouble prefix = psp.trySplit();
if (prefix != null)
prefixSplits++;
return prefix;
}
@Override
public Spliterator.OfDouble trySplit() {
splits++;
Spliterator.OfDouble prefix = psp.trySplit();
if (prefix != null)
prefixSplits++;
return prefix;
}
/**
* Adapt a {@code Spliterator<Double>} to a {@code Spliterator.OfDouble}.
*
* @implNote
* The implementation attempts to cast to a Spliterator.OfDouble, and throws
* an exception if this cast is not possible.
*/
private static Spliterator.OfDouble adapt(Spliterator<Double> s) {
if (s instanceof Spliterator.OfDouble) {
return (Spliterator.OfDouble) s;
} else {
if (Tripwire.ENABLED)
Tripwire.trip(AbstractPipeline.class,
"using DoubleStream.adapt(Spliterator<Double> s)");
throw new UnsupportedOperationException("DoubleStream.adapt(Spliterator<Double> s)");
}
}
OfDouble(Spliterator.OfDouble s,
long sliceOrigin, long sliceFence, long origin, long fence) {
super(s, sliceOrigin, sliceFence, origin, fence);
}
@Test(dataProvider = "Spliterator.OfDouble")
public void testDoubleSplitOnce(String description, Collection<Double> exp, Supplier<Spliterator.OfDouble> s) {
testSplitOnce(exp, s, doubleBoxingConsumer());
}
Dropping(Spliterator.OfDouble s, UnorderedWhileSpliterator.OfDouble parent) {
super(s, parent);
}
@Override
protected Spliterator.OfDouble makeSpliterator(Spliterator.OfDouble s) {
return new UnorderedSliceSpliterator.OfDouble(s, this);
}
@Override
Spliterator.OfDouble spliterator();
Taking(Spliterator.OfDouble s, boolean noSplitting, DoublePredicate p) {
super(s, noSplitting, p);
}
@Override
public Spliterator.OfDouble spliterator() {
assert !building : "during building";
return super.spliterator();
}
OfDouble(Spliterator.OfDouble s,
long sliceOrigin, long sliceFence, long origin, long fence) {
super(s, sliceOrigin, sliceFence, origin, fence);
}
@Test(dataProvider = "Spliterator.OfDouble")
public void testDoubleNullPointerException(String description, Collection<Double> exp, Supplier<Spliterator.OfDouble> s) {
executeAndCatch(NullPointerException.class, () -> s.get().forEachRemaining((DoubleConsumer) null));
executeAndCatch(NullPointerException.class, () -> s.get().tryAdvance((DoubleConsumer) null));
}
@Override
Spliterator.OfDouble spliterator();
@Override
public Spliterator.OfDouble spliterator() {
return Arrays.spliterator(array, 0, curSize);
}
@Override
public final DoubleStream flatMapToDouble(Function<? super P_OUT, ? extends DoubleStream> mapper) {
Objects.requireNonNull(mapper);
return new DoublePipeline.StatelessOp<P_OUT>(this, StreamShape.REFERENCE,
StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT | StreamOpFlag.NOT_SIZED) {
@Override
Sink<P_OUT> opWrapSink(int flags, Sink<Double> sink) {
return new Sink.ChainedReference<P_OUT, Double>(sink) {
// true if cancellationRequested() has been called
boolean cancellationRequestedCalled;
// cache the consumer to avoid creation on every accepted element
DoubleConsumer downstreamAsDouble = downstream::accept;
@Override
public void begin(long size) {
downstream.begin(-1);
}
@Override
public void accept(P_OUT u) {
try (DoubleStream result = mapper.apply(u)) {
if (result != null) {
if (!cancellationRequestedCalled) {
result.sequential().forEach(downstreamAsDouble);
}
else {
Spliterator.OfDouble s = result.sequential().spliterator();
do { } while (!downstream.cancellationRequested() && s.tryAdvance(downstreamAsDouble));
}
}
}
}
@Override
public boolean cancellationRequested() {
cancellationRequestedCalled = true;
return downstream.cancellationRequested();
}
};
}
};
}
@Override
final void forEachWithCancel(Spliterator<Double> spliterator, Sink<Double> sink) {
Spliterator.OfDouble spl = adapt(spliterator);
DoubleConsumer adaptedSink = adapt(sink);
do { } while (!sink.cancellationRequested() && spl.tryAdvance(adaptedSink));
}
@Override
public Spliterator.OfDouble spliterator() {
return Arrays.spliterator(array, 0, curSize);
}
@Test(dataProvider = "Spliterator.OfDouble")
public void testDoubleSplitSixDeep(String description, Collection<Double> exp, Supplier<Spliterator.OfDouble> s) {
testSplitSixDeep(exp, s, doubleBoxingConsumer());
}
/**
* Creates a new sequential or parallel {@code DoubleStream} from a
* {@code Spliterator.OfDouble}.
*
* <p>The spliterator is only traversed, split, or queried for estimated size
* after the terminal operation of the stream pipeline commences.
*
* <p>It is strongly recommended the spliterator report a characteristic of
* {@code IMMUTABLE} or {@code CONCURRENT}, or be
* <a href="../Spliterator.html#binding">late-binding</a>. Otherwise,
* {@link #doubleStream(java.util.function.Supplier, int, boolean)} should
* be used to reduce the scope of potential interference with the source. See
* <a href="package-summary.html#NonInterference">Non-Interference</a> for
* more details.
*
* @param spliterator A {@code Spliterator.OfDouble} describing the stream elements
* @param parallel if {@code true} then the returned stream is a parallel
* stream; if {@code false} the returned stream is a sequential
* stream.
* @return a new sequential or parallel {@code DoubleStream}
*/
public static DoubleStream doubleStream(Spliterator.OfDouble spliterator,
boolean parallel) {
return new DoublePipeline.Head<>(spliterator,
StreamOpFlag.fromCharacteristics(spliterator),
parallel);
}
/**
* Creates a lazily concatenated stream whose elements are all the
* elements of the first stream followed by all the elements of the
* second stream. The resulting stream is ordered if both
* of the input streams are ordered, and parallel if either of the input
* streams is parallel. When the resulting stream is closed, the close
* handlers for both input streams are invoked.
*
* @implNote
* Use caution when constructing streams from repeated concatenation.
* Accessing an element of a deeply concatenated stream can result in deep
* call chains, or even {@code StackOverflowError}.
*
* @param a the first stream
* @param b the second stream
* @return the concatenation of the two input streams
*/
public static DoubleStream concat(DoubleStream a, DoubleStream b) {
Objects.requireNonNull(a);
Objects.requireNonNull(b);
Spliterator.OfDouble split = new Streams.ConcatSpliterator.OfDouble(
a.spliterator(), b.spliterator());
DoubleStream stream = StreamSupport.doubleStream(split, a.isParallel() || b.isParallel());
return stream.onClose(Streams.composedClose(a, b));
}