本文整理汇总了Java中java.util.stream.StreamSupport.stream方法的典型用法代码示例。如果您正苦于以下问题:Java StreamSupport.stream方法的具体用法?Java StreamSupport.stream怎么用?Java StreamSupport.stream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.stream.StreamSupport
的用法示例。
在下文中一共展示了StreamSupport.stream方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: intersperse
import java.util.stream.StreamSupport; //导入方法依赖的package包/类
public static <T> Stream<T> intersperse(Stream<T> s, T e) {
final Iterator<T> inner = s.iterator();
final AtomicBoolean returnE = new AtomicBoolean(false);
final Iterator<T> it = new Iterator<T>() {
@Override
public boolean hasNext() {
return inner.hasNext();
}
@Override
public T next() {
final T ret = returnE.get() ? e : inner.next();
returnE.set(!returnE.get());
return ret;
}
};
return StreamSupport.stream(
Spliterators.spliteratorUnknownSize(it, Spliterator.ORDERED),
false);
}
示例2: toStream
import java.util.stream.StreamSupport; //导入方法依赖的package包/类
private static <T> Stream<T> toStream(final Iterable<T> iterable) {
return StreamSupport.stream(
Spliterators.spliteratorUnknownSize(
iterable.iterator(),
Spliterator.ORDERED
),
false
);
}
示例3: stream
import java.util.stream.StreamSupport; //导入方法依赖的package包/类
@Override
public Stream<JarEntry> stream() {
return StreamSupport.stream(Spliterators.spliterator(
new JarEntryIterator(), size(),
Spliterator.ORDERED | Spliterator.DISTINCT |
Spliterator.IMMUTABLE | Spliterator.NONNULL), false);
}
示例4: of
import java.util.stream.StreamSupport; //导入方法依赖的package包/类
public static <T> Stream<T> of(Iterator<T> iterator) {
return StreamSupport.stream(Spliterators.spliterator(iterator, 0, Spliterator.ORDERED), false);
}
示例5: stream
import java.util.stream.StreamSupport; //导入方法依赖的package包/类
public Stream<T> stream() {
return StreamSupport.stream(this.spliterator(), false);
}
示例6: stream
import java.util.stream.StreamSupport; //导入方法依赖的package包/类
/** TODO: Implement {@link Collection} interface so this is an override */
public Stream<KdbDict> stream() {
Iterable<KdbDict> iterable = () -> iterator();
return StreamSupport.stream(iterable.spliterator(), false);
}
示例7: stream
import java.util.stream.StreamSupport; //导入方法依赖的package包/类
static Stream<DoubleMultiPoint> stream(List<DoubleTimeSeries> timeSeriesList) {
return StreamSupport.stream(Spliterators.spliteratorUnknownSize(
iterator(timeSeriesList),
Spliterator.ORDERED | Spliterator.IMMUTABLE), false);
}
示例8: getContent
import java.util.stream.StreamSupport; //导入方法依赖的package包/类
@Override
public final Stream<String> getContent(String path) {
Spliterator<String> iter = new IteratorFromReader(getStream.apply(path));
return StreamSupport.stream(iter, false);
}
示例9: deleteAll
import java.util.stream.StreamSupport; //导入方法依赖的package包/类
@Override
public long deleteAll() {
final Iterator<ViewRow> grantingTicketsIt = getViewResultIteratorForPrefixedTickets(TicketGrantingTicket.PREFIX + '-').iterator();
final Iterator<ViewRow> serviceTicketsIt = getViewResultIteratorForPrefixedTickets(ServiceTicket.PREFIX + '-').iterator();
final Iterator<ViewRow> proxyTicketsIt = getViewResultIteratorForPrefixedTickets(ProxyTicket.PREFIX + '-').iterator();
final Iterator<ViewRow> proxyGrantingTicketsIt = getViewResultIteratorForPrefixedTickets(ProxyGrantingTicket.PREFIX + '-').iterator();
final Iterator<ViewRow> accessTokenIt = getViewResultIteratorForPrefixedTickets(AccessToken.PREFIX + '-').iterator();
final Iterator<ViewRow> oauthcodeIt = getViewResultIteratorForPrefixedTickets(OAuthCode.PREFIX + '-').iterator();
final Iterator<ViewRow> refreshTokenIt = getViewResultIteratorForPrefixedTickets(RefreshToken.PREFIX + '-').iterator();
final int count = getViewRowCountFromViewResultIterator(grantingTicketsIt)
+ getViewRowCountFromViewResultIterator(serviceTicketsIt)
+ getViewRowCountFromViewResultIterator(proxyTicketsIt)
+ getViewRowCountFromViewResultIterator(proxyGrantingTicketsIt)
+ getViewRowCountFromViewResultIterator(accessTokenIt)
+ getViewRowCountFromViewResultIterator(oauthcodeIt)
+ getViewRowCountFromViewResultIterator(refreshTokenIt);
Stream<ViewRow> tickets = StreamSupport.stream(Spliterators.spliteratorUnknownSize(grantingTicketsIt, Spliterator.ORDERED), true);
tickets.forEach(t -> this.couchbase.bucket().remove(t.document()));
tickets = StreamSupport.stream(Spliterators.spliteratorUnknownSize(serviceTicketsIt, Spliterator.ORDERED), true);
tickets.forEach(t -> this.couchbase.bucket().remove(t.document()));
tickets = StreamSupport.stream(Spliterators.spliteratorUnknownSize(proxyTicketsIt, Spliterator.ORDERED), true);
tickets.forEach(t -> this.couchbase.bucket().remove(t.document()));
tickets = StreamSupport.stream(Spliterators.spliteratorUnknownSize(proxyGrantingTicketsIt, Spliterator.ORDERED), true);
tickets.forEach(t -> this.couchbase.bucket().remove(t.document()));
tickets = StreamSupport.stream(Spliterators.spliteratorUnknownSize(accessTokenIt, Spliterator.ORDERED), true);
tickets.forEach(t -> this.couchbase.bucket().remove(t.document()));
tickets = StreamSupport.stream(Spliterators.spliteratorUnknownSize(oauthcodeIt, Spliterator.ORDERED), true);
tickets.forEach(t -> this.couchbase.bucket().remove(t.document()));
tickets = StreamSupport.stream(Spliterators.spliteratorUnknownSize(refreshTokenIt, Spliterator.ORDERED), true);
tickets.forEach(t -> this.couchbase.bucket().remove(t.document()));
return count;
}
示例10: recordStream
import java.util.stream.StreamSupport; //导入方法依赖的package包/类
private static <K, V> Stream<ConsumerRecord<K, V>> recordStream(ConsumerRecords<K, V> records) {
return StreamSupport.stream(records.spliterator(), false);
}
示例11: stream
import java.util.stream.StreamSupport; //导入方法依赖的package包/类
/**
* Return an ordered {@code Stream} over the ZIP file entries.
* Entries appear in the {@code Stream} in the order they appear in
* the central directory of the ZIP file.
*
* @return an ordered {@code Stream} of entries in this ZIP file
* @throws IllegalStateException if the zip file has been closed
* @since 1.8
*/
public Stream<? extends ZipEntry> stream() {
return StreamSupport.stream(Spliterators.spliterator(
new ZipEntryIterator(), size(),
Spliterator.ORDERED | Spliterator.DISTINCT |
Spliterator.IMMUTABLE | Spliterator.NONNULL), false);
}
示例12: findAll
import java.util.stream.StreamSupport; //导入方法依赖的package包/类
/**
* Returns a stream of match results from this scanner. The stream
* contains the same results in the same order that would be returned by
* calling {@code findWithinHorizon(pattern, 0)} and then {@link #match}
* successively as long as {@link #findWithinHorizon findWithinHorizon()}
* finds matches.
*
* <p>The resulting stream is sequential and ordered. All stream elements are
* non-null.
*
* <p>Scanning starts upon initiation of the terminal stream operation, using the
* current state of this scanner. Subsequent calls to any methods on this scanner
* other than {@link #close} and {@link #ioException} may return undefined results
* or may cause undefined effects on the returned stream. The returned stream's source
* {@code Spliterator} is <em>fail-fast</em> and will, on a best-effort basis, throw a
* {@link java.util.ConcurrentModificationException} if any such calls are detected
* during stream pipeline execution.
*
* <p>After stream pipeline execution completes, this scanner is left in an indeterminate
* state and cannot be reused.
*
* <p>If this scanner contains a resource that must be released, this scanner
* should be closed, either by calling its {@link #close} method, or by
* closing the returned stream. Closing the stream will close the underlying scanner.
* {@code IllegalStateException} is thrown if the scanner has been closed when this
* method is called, or if this scanner is closed during stream pipeline execution.
*
* <p>As with the {@link #findWithinHorizon findWithinHorizon()} methods, this method
* might block waiting for additional input, and it might buffer an unbounded amount of
* input searching for a match.
*
* @apiNote
* For example, the following code will read a file and return a list
* of all sequences of characters consisting of seven or more Latin capital
* letters:
*
* <pre>{@code
* try (Scanner sc = new Scanner(Paths.get("input.txt"))) {
* Pattern pat = Pattern.compile("[A-Z]{7,}");
* List<String> capWords = sc.findAll(pat)
* .map(MatchResult::group)
* .collect(Collectors.toList());
* }
* }</pre>
*
* @param pattern the pattern to be matched
* @return a sequential stream of match results
* @throws NullPointerException if pattern is null
* @throws IllegalStateException if this scanner is closed
* @since 9
*/
public Stream<MatchResult> findAll(Pattern pattern) {
Objects.requireNonNull(pattern);
ensureOpen();
Stream<MatchResult> stream = StreamSupport.stream(new FindSpliterator(pattern), false);
return stream.onClose(this::close);
}
示例13: stream
import java.util.stream.StreamSupport; //导入方法依赖的package包/类
/**
* Returns a sequential {@code Stream} with this collection as its source.
*
* <p>This method should be overridden when the {@link #spliterator()}
* method cannot return a spliterator that is {@code IMMUTABLE},
* {@code CONCURRENT}, or <em>late-binding</em>. (See {@link #spliterator()}
* for details.)
*
* @implSpec
* The default implementation creates a sequential {@code Stream} from the
* collection's {@code Spliterator}.
*
* @return a sequential {@code Stream} over the elements in this collection
* @since 1.8
*/
default Stream<E> stream() {
return StreamSupport.stream(spliterator(), false);
}
示例14: parallelStream
import java.util.stream.StreamSupport; //导入方法依赖的package包/类
/**
* Returns a possibly parallel {@code Stream} with this collection as its
* source. It is allowable for this method to return a sequential stream.
*
* <p>This method should be overridden when the {@link #spliterator()}
* method cannot return a spliterator that is {@code IMMUTABLE},
* {@code CONCURRENT}, or <em>late-binding</em>. (See {@link #spliterator()}
* for details.)
*
* @implSpec
* The default implementation creates a parallel {@code Stream} from the
* collection's {@code Spliterator}.
*
* @return a possibly parallel {@code Stream} over the elements in this
* collection
* @since 1.8
*/
default Stream<E> parallelStream() {
return StreamSupport.stream(spliterator(), true);
}
示例15: stream
import java.util.stream.StreamSupport; //导入方法依赖的package包/类
/**
* Returns a sequential {@link Stream} with the specified range of the
* specified array as its source.
*
* @param <T> the type of the array elements
* @param array the array, assumed to be unmodified during use
* @param startInclusive the first index to cover, inclusive
* @param endExclusive index immediately past the last index to cover
* @return a {@code Stream} for the array range
* @throws ArrayIndexOutOfBoundsException if {@code startInclusive} is
* negative, {@code endExclusive} is less than
* {@code startInclusive}, or {@code endExclusive} is greater than
* the array size
* @since 1.8
*/
public static <T> Stream<T> stream(T[] array, int startInclusive, int endExclusive) {
return StreamSupport.stream(spliterator(array, startInclusive, endExclusive), false);
}