2013-04-17 14:39:04 -04:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2012, 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.Iterator;
|
|
|
|
import java.util.Spliterator;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Base interface for stream types such as {@link Stream}, {@link IntStream},
|
2013-07-09 10:44:49 +02:00
|
|
|
* etc. Contains methods common to all stream types.
|
2013-04-17 14:39:04 -04:00
|
|
|
*
|
|
|
|
* @param <T> type of stream elements
|
|
|
|
* @param <S> type of stream implementing {@code BaseStream}
|
|
|
|
* @since 1.8
|
|
|
|
*/
|
2013-09-03 12:16:01 -07:00
|
|
|
public interface BaseStream<T, S extends BaseStream<T, S>>
|
|
|
|
extends AutoCloseable {
|
2013-04-17 14:39:04 -04:00
|
|
|
/**
|
|
|
|
* Returns an iterator for the elements of this stream.
|
|
|
|
*
|
|
|
|
* <p>This is a <a href="package-summary.html#StreamOps">terminal
|
|
|
|
* operation</a>.
|
|
|
|
*
|
|
|
|
* @return the element iterator for this stream
|
|
|
|
*/
|
|
|
|
Iterator<T> iterator();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a spliterator for the elements of this stream.
|
|
|
|
*
|
|
|
|
* <p>This is a <a href="package-summary.html#StreamOps">terminal
|
|
|
|
* operation</a>.
|
|
|
|
*
|
|
|
|
* @return the element spliterator for this stream
|
|
|
|
*/
|
|
|
|
Spliterator<T> spliterator();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns whether this stream, when executed, would execute in parallel
|
|
|
|
* (assuming no further modification of the stream, such as appending
|
|
|
|
* further intermediate operations or changing its parallelism). Calling
|
|
|
|
* this method after invoking an intermediate or terminal stream operation
|
|
|
|
* method may yield unpredictable results.
|
|
|
|
*
|
|
|
|
* @return {@code true} if this stream would execute in parallel if executed
|
|
|
|
* without further modification otherwise {@code false}
|
|
|
|
*/
|
|
|
|
boolean isParallel();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns an equivalent stream that is sequential. May return
|
|
|
|
* itself, either because the stream was already sequential, or because
|
|
|
|
* the underlying stream state was modified to be sequential.
|
|
|
|
*
|
|
|
|
* <p>This is an <a href="package-summary.html#StreamOps">intermediate
|
|
|
|
* operation</a>.
|
|
|
|
*
|
|
|
|
* @return a sequential stream
|
|
|
|
*/
|
|
|
|
S sequential();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns an equivalent stream that is parallel. May return
|
|
|
|
* itself, either because the stream was already parallel, or because
|
|
|
|
* the underlying stream state was modified to be parallel.
|
|
|
|
*
|
|
|
|
* <p>This is an <a href="package-summary.html#StreamOps">intermediate
|
|
|
|
* operation</a>.
|
|
|
|
*
|
|
|
|
* @return a parallel stream
|
|
|
|
*/
|
|
|
|
S parallel();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns an equivalent stream that is
|
|
|
|
* <a href="package-summary.html#Ordering">unordered</a>. May return
|
|
|
|
* itself if the stream was already unordered.
|
|
|
|
*
|
|
|
|
* <p>This is an <a href="package-summary.html#StreamOps">intermediate
|
|
|
|
* operation</a>.
|
|
|
|
*
|
|
|
|
* @return an unordered stream
|
|
|
|
*/
|
|
|
|
S unordered();
|
2013-09-03 12:16:01 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns an equivalent stream with an additional close handler. Close
|
|
|
|
* handlers are run when the {@link #close()} method
|
|
|
|
* is called on the stream, and are executed in the order they were
|
|
|
|
* added. All close handlers are run, even if earlier close handlers throw
|
|
|
|
* exceptions. If any close handler throws an exception, the first
|
|
|
|
* exception thrown will be relayed to the caller of {@code close()}, with
|
|
|
|
* any remaining exceptions added to that exception as suppressed exceptions
|
|
|
|
* (unless one of the remaining exceptions is the same exception as the
|
|
|
|
* first exception, since an exception cannot suppress itself.) May
|
|
|
|
* return itself.
|
|
|
|
*
|
|
|
|
* <p>This is an <a href="package-summary.html#StreamOps">intermediate
|
|
|
|
* operation</a>.
|
|
|
|
*
|
|
|
|
* @param closeHandler A task to execute when the stream is closed
|
|
|
|
* @return a stream with a handler that is run if the stream is closed
|
|
|
|
*/
|
|
|
|
S onClose(Runnable closeHandler);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Closes this stream, causing all close handlers for this stream pipeline
|
|
|
|
* to be called.
|
|
|
|
*
|
|
|
|
* @see AutoCloseable#close()
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
void close();
|
2013-04-17 14:39:04 -04:00
|
|
|
}
|