IterableStream<T> Class

  • java.lang.Object
    • com.azure.core.util.IterableStream<T>

Type Parameters

T

The type of value in this Iterable.

Implements

public class IterableStream
implements Iterable<T>

This class provides utility to iterate over values using standard 'for-each' style loops or to convert them into a Stream and operate in that fashion.

Code sample using Stream

// process the stream
 myIterableStream.stream().forEach(resp -> {
     if (resp.getStatusCode() == HttpURLConnection.HTTP_OK) {
         System.out.printf("Response headers are %s. Url %s%n", resp.getDeserializedHeaders(),
             resp.getRequest().getUrl());
         resp.getElements().forEach(value -> System.out.printf("Response value is %d%n", value));
     }
 });

Code sample using Iterator

// Iterate over iterator
 for (PagedResponseBase<String, Integer> resp : myIterableStream) {
     if (resp.getStatusCode() == HttpURLConnection.HTTP_OK) {
         System.out.printf("Response headers are %s. Url %s%n", resp.getDeserializedHeaders(),
             resp.getRequest().getUrl());
         resp.getElements().forEach(value -> System.out.printf("Response value is %d%n", value));
     }
 }

Code sample using Stream and filter

// process the stream
 myIterableStream.stream().filter(resp -> resp.getStatusCode() == HttpURLConnection.HTTP_OK)
     .limit(10)
     .forEach(resp -> {
         System.out.printf("Response headers are %s. Url %s%n", resp.getDeserializedHeaders(),
             resp.getRequest().getUrl());
         resp.getElements().forEach(value -> System.out.printf("Response value is %d%n", value));
     });

Constructor Summary

Constructor Description
IterableStream(Iterable<T> iterable)

Creates an instance with the given Iterable.

IterableStream(Flux<T> flux)

Creates an instance with the given Flux.

Method Summary

Modifier and Type Method and Description
static IterableStream<T> of(Iterable<T> iterable)

Creates an IterableStream<T> from an Iterable.

Iterator<T> iterator()

Utility function to provide Iterator of value T.

Stream<T> stream()

Utility function to provide Stream of value T.

Methods inherited from java.lang.Object

Constructor Details

IterableStream

public IterableStream(Iterable iterable)

Creates an instance with the given Iterable.

Parameters:

iterable - Collection of items to iterate over.

IterableStream

public IterableStream(Flux flux)

Creates an instance with the given Flux.

Parameters:

flux - Flux of items to iterate over.

Method Details

of

public static IterableStream of(Iterable iterable)

Creates an IterableStream<T> from an Iterable.

An empty IterableStream<T> will be returned if the input iterable is null.

Parameters:

iterable - Collection of items to iterate over.

Returns:

An IterableStream<T> based on the passed collection.

iterator

public Iterator iterator()

Utility function to provide Iterator of value T.

Returns:

Iterator of value T.

stream

public Stream stream()

Utility function to provide Stream of value T.

Returns:

Stream of value T.

Applies to