--- /dev/null 2013-01-19 23:30:52.572866804 -0800 +++ new/src/share/classes/java/util/stream/DelegatingStream.java 2013-01-25 23:38:55.715458085 -0800 @@ -0,0 +1,199 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package java.util.stream; + +import java.util.Comparator; +import java.util.Objects; +import java.util.Optional; +import java.util.Spliterator; +import java.util.function.BiConsumer; +import java.util.function.BiFunction; +import java.util.function.BinaryOperator; +import java.util.function.BooleanSupplier; +import java.util.function.Consumer; +import java.util.function.Function; +import java.util.function.IntFunction; +import java.util.function.Predicate; +import java.util.function.Supplier; +import java.util.function.ToDoubleFunction; +import java.util.function.ToIntFunction; +import java.util.function.ToLongFunction; + +/** + * A {@code Stream} implementation that delegate operations to another {@code + * Stream}. + * + * @since 1.8 + */ +public class DelegatingStream implements Stream { + final private Stream delegate; + + /** + * Construct a {@code Stream} that delegates operations to another {@code + * Stream}. + * + * @param delegate The {@link Stream} that actually performs the operation + * @throws NullPointerException if the delegate is null + */ + public DelegatingStream(Stream delegate) { + this.delegate = Objects.requireNonNull(delegate); + } + + // -- BaseStream methods -- + + public Spliterator spliterator() { + return delegate.spliterator(); + } + + public boolean isParallel() { + return delegate.isParallel(); + } + + public int getStreamFlags() { + return delegate.getStreamFlags(); + } + + // -- Stream methods -- + + public Stream filter(Predicate predicate) { + return delegate.filter(predicate); + } + + public Stream map(Function mapper) { + return delegate.map(mapper); + } + + public IntStream map(ToIntFunction mapper) { + return delegate.map(mapper); + } + + public LongStream map(ToLongFunction mapper) { + return delegate.map(mapper); + } + + public DoubleStream map(ToDoubleFunction mapper) { + return delegate.map(mapper); + } + + public Stream explode(BiConsumer, ? super T> exploder) { + return delegate.explode(exploder); + } + + public Stream distinct() { + return delegate.distinct(); + } + + public Stream sorted() { + return delegate.sorted(); + } + + public Stream sorted(Comparator comparator) { + return delegate.sorted(comparator); + } + + public void forEach(Consumer consumer) { + delegate.forEach(consumer); + } + + public void forEachUntil(Consumer consumer, BooleanSupplier until) { + delegate.forEachUntil(consumer, until); + } + + public Stream peek(Consumer consumer) { + return delegate.peek(consumer); + } + + public Stream limit(long maxSize) { + return delegate.limit(maxSize); + } + + public Stream substream(long startingOffset) { + return delegate.substream(startingOffset); + } + + public Stream substream(long startingOffset, long endingOffset) { + return delegate.substream(startingOffset, endingOffset); + } + + public A[] toArray(IntFunction generator) { + return delegate.toArray(generator); + } + + public T reduce(T identity, BinaryOperator reducer) { + return delegate.reduce(identity, reducer); + } + + public Optional reduce(BinaryOperator reducer) { + return delegate.reduce(reducer); + } + + public U reduce(U identity, BiFunction accumulator, + BinaryOperator reducer) { + return delegate.reduce(identity, accumulator, reducer); + } + + public R collect(Supplier resultFactory, + BiConsumer accumulator, + BiConsumer reducer) { + return delegate.collect(resultFactory, accumulator, reducer); + } + + public R collect(Collector collector) { + return delegate.collect(collector); + } + + public R collectUnordered(Collector collector) { + return delegate.collectUnordered(collector); + } + + public boolean anyMatch(Predicate predicate) { + return delegate.anyMatch(predicate); + } + + public boolean allMatch(Predicate predicate) { + return delegate.allMatch(predicate); + } + + public boolean noneMatch(Predicate predicate) { + return delegate.noneMatch(predicate); + } + + public Optional findFirst() { + return delegate.findFirst(); + } + + public Optional findAny() { + return delegate.findAny(); + } + + public Stream sequential() { + return delegate.sequential(); + } + + public Stream parallel() { + return delegate.parallel(); + } +} \ No newline at end of file