Java Code Examples for java.util.stream.StreamSupport

Following code examples demonstrate how to use java.util.stream.StreamSupportfrom android. These examples are extracted from various highly rated open source projects. You can directly use these code snippets or view their entire linked source code. These snippets are extracted to provide contextual information about how to use this class in the real world. These samples also let you understand some good practices on how to use java.util.stream.StreamSupportand various code implementation of this class.

    public static <E> Stream<E> reverseStream(Deque<E> linkedList) {
        final Spliterator<E> spliterator = Spliterators.spliteratorUnknownSize(linkedList.descendingIterator(), 0);
        return StreamSupport.stream(spliterator, false);
    } 


    public static void step1_stream(Iterable<String> things, PrintWriter writer) throws IOException {
        Stream<String> stream = StreamSupport.stream(things.spliterator(), false);
        Iterable<String> iterable = stream::iterator;
        for (String thing : iterable) {
            writer.write(thing);
        }
    } 

    @Test
    public default void verifyGenericType()
    throws Exception {
        final Class<SUT> sut = createNewSUT();
        assertTrue("This j8unit test interface is used with a generic type that is illegaly not assignable to StreamSupport.class!",
                   StreamSupport.class.isAssignableFrom(sut));
    } 

    public static <T> Stream<List<T>> partition(Stream<T> stream, int size) {
        Iterable<List<T>> iterable = () -> Iterators.partition(stream.iterator(), size);
        return StreamSupport.stream(iterable.spliterator(), false);
    } 

    public Optional<EntityMapper<? extends ExternalServiceResource, ? extends DiscoverableEntity>> find(ExternalServiceResource resource) {
        return StreamSupport.stream(getMapperPool().spliterator(), false)
            .filter(mapper -> mapper.canMap(resource))
            .findFirst();
    } 

    public static <T> Stream<T> of(Iterator<T> iterator) {
        Iterable<T> iterable = () -> iterator;
        return StreamSupport.stream(iterable.spliterator(), false);
    } 

Advertisement
Javadoc
Low-level utility methods for creating and manipulating streams.

This class is mostly for

library writers presenting stream views of data structures; most static stream methods intended for end users are in the various Stream classes. @since 1.8

Read More
Advertisement