1 /*
2 * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
150 @Override
151 @SuppressWarnings("unchecked")
152 final Spliterator.OfDouble lazySpliterator(Supplier<? extends Spliterator<Double>> supplier) {
153 return new StreamSpliterators.DelegatingSpliterator.OfDouble((Supplier<Spliterator.OfDouble>) supplier);
154 }
155
156 @Override
157 final boolean forEachWithCancel(Spliterator<Double> spliterator, Sink<Double> sink) {
158 Spliterator.OfDouble spl = adapt(spliterator);
159 DoubleConsumer adaptedSink = adapt(sink);
160 boolean cancelled;
161 do { } while (!(cancelled = sink.cancellationRequested()) && spl.tryAdvance(adaptedSink));
162 return cancelled;
163 }
164
165 @Override
166 final Node.Builder<Double> makeNodeBuilder(long exactSizeIfKnown, IntFunction<Double[]> generator) {
167 return Nodes.doubleBuilder(exactSizeIfKnown);
168 }
169
170
171 // DoubleStream
172
173 @Override
174 public final PrimitiveIterator.OfDouble iterator() {
175 return Spliterators.iterator(spliterator());
176 }
177
178 @Override
179 public final Spliterator.OfDouble spliterator() {
180 return adapt(super.spliterator());
181 }
182
183 // Stateless intermediate ops from DoubleStream
184
185 @Override
186 public final Stream<Double> boxed() {
187 return mapToObj(Double::valueOf);
188 }
189
190 @Override
191 public final DoubleStream map(DoubleUnaryOperator mapper) {
192 Objects.requireNonNull(mapper);
193 return new StatelessOp<Double>(this, StreamShape.DOUBLE_VALUE,
194 StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
195 @Override
196 Sink<Double> opWrapSink(int flags, Sink<Double> sink) {
197 return new Sink.ChainedDouble<Double>(sink) {
198 @Override
199 public void accept(double t) {
200 downstream.accept(mapper.applyAsDouble(t));
201 }
202 };
203 }
204 };
205 }
206
207 @Override
208 public final <U> Stream<U> mapToObj(DoubleFunction<? extends U> mapper) {
209 Objects.requireNonNull(mapper);
210 return new ReferencePipeline.StatelessOp<Double, U>(this, StreamShape.DOUBLE_VALUE,
211 StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
212 @Override
213 Sink<Double> opWrapSink(int flags, Sink<U> sink) {
214 return new Sink.ChainedDouble<U>(sink) {
215 @Override
216 public void accept(double t) {
217 downstream.accept(mapper.apply(t));
218 }
219 };
220 }
221 };
222 }
223
224 @Override
225 public final IntStream mapToInt(DoubleToIntFunction mapper) {
226 Objects.requireNonNull(mapper);
227 return new IntPipeline.StatelessOp<Double>(this, StreamShape.DOUBLE_VALUE,
228 StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
229 @Override
230 Sink<Double> opWrapSink(int flags, Sink<Integer> sink) {
231 return new Sink.ChainedDouble<Integer>(sink) {
232 @Override
233 public void accept(double t) {
234 downstream.accept(mapper.applyAsInt(t));
235 }
236 };
237 }
238 };
239 }
240
241 @Override
|
1 /*
2 * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
150 @Override
151 @SuppressWarnings("unchecked")
152 final Spliterator.OfDouble lazySpliterator(Supplier<? extends Spliterator<Double>> supplier) {
153 return new StreamSpliterators.DelegatingSpliterator.OfDouble((Supplier<Spliterator.OfDouble>) supplier);
154 }
155
156 @Override
157 final boolean forEachWithCancel(Spliterator<Double> spliterator, Sink<Double> sink) {
158 Spliterator.OfDouble spl = adapt(spliterator);
159 DoubleConsumer adaptedSink = adapt(sink);
160 boolean cancelled;
161 do { } while (!(cancelled = sink.cancellationRequested()) && spl.tryAdvance(adaptedSink));
162 return cancelled;
163 }
164
165 @Override
166 final Node.Builder<Double> makeNodeBuilder(long exactSizeIfKnown, IntFunction<Double[]> generator) {
167 return Nodes.doubleBuilder(exactSizeIfKnown);
168 }
169
170 private final <U> Stream<U> mapToObj(DoubleFunction<? extends U> mapper, int opFlags) {
171 return new ReferencePipeline.StatelessOp<Double, U>(this, StreamShape.DOUBLE_VALUE, opFlags) {
172 @Override
173 Sink<Double> opWrapSink(int flags, Sink<U> sink) {
174 return new Sink.ChainedDouble<U>(sink) {
175 @Override
176 public void accept(double t) {
177 downstream.accept(mapper.apply(t));
178 }
179 };
180 }
181 };
182 }
183
184 // DoubleStream
185
186 @Override
187 public final PrimitiveIterator.OfDouble iterator() {
188 return Spliterators.iterator(spliterator());
189 }
190
191 @Override
192 public final Spliterator.OfDouble spliterator() {
193 return adapt(super.spliterator());
194 }
195
196 // Stateless intermediate ops from DoubleStream
197
198 @Override
199 public final Stream<Double> boxed() {
200 return mapToObj(Double::valueOf, 0);
201 }
202
203 @Override
204 public final DoubleStream map(DoubleUnaryOperator mapper) {
205 Objects.requireNonNull(mapper);
206 return new StatelessOp<Double>(this, StreamShape.DOUBLE_VALUE,
207 StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
208 @Override
209 Sink<Double> opWrapSink(int flags, Sink<Double> sink) {
210 return new Sink.ChainedDouble<Double>(sink) {
211 @Override
212 public void accept(double t) {
213 downstream.accept(mapper.applyAsDouble(t));
214 }
215 };
216 }
217 };
218 }
219
220 @Override
221 public final <U> Stream<U> mapToObj(DoubleFunction<? extends U> mapper) {
222 Objects.requireNonNull(mapper);
223 return mapToObj(mapper, StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT);
224 }
225
226 @Override
227 public final IntStream mapToInt(DoubleToIntFunction mapper) {
228 Objects.requireNonNull(mapper);
229 return new IntPipeline.StatelessOp<Double>(this, StreamShape.DOUBLE_VALUE,
230 StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
231 @Override
232 Sink<Double> opWrapSink(int flags, Sink<Integer> sink) {
233 return new Sink.ChainedDouble<Integer>(sink) {
234 @Override
235 public void accept(double t) {
236 downstream.accept(mapper.applyAsInt(t));
237 }
238 };
239 }
240 };
241 }
242
243 @Override
|