From 56dc993cd64dbf8a6c7cd0a0134d47de3d76e42f Mon Sep 17 00:00:00 2001 From: Jonathan Giles Date: Fri, 16 Aug 2019 13:20:41 +1200 Subject: [PATCH] Renaming IterableResponse to IterableStream (#5002) --- .../azure/core/http/rest/PagedIterable.java | 8 +++-- .../IterableStream.java} | 15 ++++---- .../IterableStreamJavaDocCodeSnippets.java} | 36 +++++++++---------- .../core/http/rest/IterableResponseTest.java | 9 ++--- .../messaging/eventhubs/EventHubClient.java | 6 ++-- .../messaging/eventhubs/EventHubConsumer.java | 10 +++--- .../EventHubClientIntegrationTest.java | 4 +-- 7 files changed, 46 insertions(+), 42 deletions(-) rename sdk/core/azure-core/src/main/java/com/azure/core/{http/rest/IterableResponse.java => util/IterableStream.java} (68%) rename sdk/core/azure-core/src/samples/java/com/azure/core/{http/rest/IterableResponseJavaDocCodeSnippets.java => util/IterableStreamJavaDocCodeSnippets.java} (74%) diff --git a/sdk/core/azure-core/src/main/java/com/azure/core/http/rest/PagedIterable.java b/sdk/core/azure-core/src/main/java/com/azure/core/http/rest/PagedIterable.java index cac6c353efae3..82414af3f8983 100644 --- a/sdk/core/azure-core/src/main/java/com/azure/core/http/rest/PagedIterable.java +++ b/sdk/core/azure-core/src/main/java/com/azure/core/http/rest/PagedIterable.java @@ -3,6 +3,8 @@ package com.azure.core.http.rest; +import com.azure.core.util.IterableStream; + import java.util.stream.Stream; /** @@ -20,11 +22,11 @@ * * {@codesnippet com.azure.core.http.rest.pagedIterable.iterableByPage.while} * - * @param The type of value contained in this {@link IterableResponse}. + * @param The type of value contained in this {@link IterableStream}. * @see PagedResponse - * @see IterableResponse + * @see IterableStream */ -public class PagedIterable extends IterableResponse { +public class PagedIterable extends IterableStream { private final PagedFlux pagedFlux; /** diff --git a/sdk/core/azure-core/src/main/java/com/azure/core/http/rest/IterableResponse.java b/sdk/core/azure-core/src/main/java/com/azure/core/util/IterableStream.java similarity index 68% rename from sdk/core/azure-core/src/main/java/com/azure/core/http/rest/IterableResponse.java rename to sdk/core/azure-core/src/main/java/com/azure/core/util/IterableStream.java index abdb328a556ce..7c7d68551b501 100644 --- a/sdk/core/azure-core/src/main/java/com/azure/core/http/rest/IterableResponse.java +++ b/sdk/core/azure-core/src/main/java/com/azure/core/util/IterableStream.java @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -package com.azure.core.http.rest; +package com.azure.core.util; import reactor.core.publisher.Flux; @@ -9,31 +9,32 @@ import java.util.stream.Stream; /** - * This class provides utility to iterate over values. All the values are preserved even if they are traversed multiple times. + * 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. All the values are preserved even if they are traversed multiple times. * *

Code sample using Stream

* - * {@codesnippet com.azure.core.http.rest.iterableResponse.stream} + * {@codesnippet com.azure.core.util.iterableStream.stream} * *

Code sample using Iterator

* - * {@codesnippet com.azure.core.http.rest.iterableResponse.iterator.while} + * {@codesnippet com.azure.core.util.iterableStream.iterator.while} * *

Code sample using Stream and filter

* - * {@codesnippet com.azure.core.http.rest.iterableResponse.stream.filter} + * {@codesnippet com.azure.core.util.iterableStream.stream.filter} * * @param The type of value in this {@link Iterable}. * @see Iterable */ -public class IterableResponse implements Iterable { +public class IterableStream implements Iterable { private final Flux flux; /** * Creates instance given {@link Flux}. * @param flux to iterate over */ - public IterableResponse(Flux flux) { + public IterableStream(Flux flux) { this.flux = flux; } diff --git a/sdk/core/azure-core/src/samples/java/com/azure/core/http/rest/IterableResponseJavaDocCodeSnippets.java b/sdk/core/azure-core/src/samples/java/com/azure/core/util/IterableStreamJavaDocCodeSnippets.java similarity index 74% rename from sdk/core/azure-core/src/samples/java/com/azure/core/http/rest/IterableResponseJavaDocCodeSnippets.java rename to sdk/core/azure-core/src/samples/java/com/azure/core/util/IterableStreamJavaDocCodeSnippets.java index 9ccdd4157ed4a..d348faf109514 100644 --- a/sdk/core/azure-core/src/samples/java/com/azure/core/http/rest/IterableResponseJavaDocCodeSnippets.java +++ b/sdk/core/azure-core/src/samples/java/com/azure/core/util/IterableStreamJavaDocCodeSnippets.java @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -package com.azure.core.http.rest; +package com.azure.core.util; import com.azure.core.http.HttpHeaders; import com.azure.core.http.HttpMethod; @@ -18,9 +18,9 @@ import java.util.stream.IntStream; /** - * Code snippets for {@link IterableResponse} + * Code snippets for {@link IterableStream} */ -public class IterableResponseJavaDocCodeSnippets { +public class IterableStreamJavaDocCodeSnippets { /** * Iterate over {@link java.util.stream.Stream} @@ -33,12 +33,12 @@ public void streamSnippet() throws MalformedURLException { String deserializedHeaders = "header1,value1,header2,value2"; - IterableResponse> myIterableResponse = - new IterableResponse<>(Flux.just(createPagedResponse(httpRequest, httpHeaders, deserializedHeaders, 1, 3))); + IterableStream> myIterableStream = + new IterableStream<>(Flux.just(createPagedResponse(httpRequest, httpHeaders, deserializedHeaders, 1, 3))); - // BEGIN: com.azure.core.http.rest.iterableResponse.stream + // BEGIN: com.azure.core.util.iterableStream.stream // process the stream - myIterableResponse.stream().forEach(resp -> { + myIterableStream.stream().forEach(resp -> { if (resp.statusCode() == HttpURLConnection.HTTP_OK) { System.out.printf("Response headers are %s. Url %s%n", resp.deserializedHeaders(), resp.request().url()); resp.items().forEach(value -> { @@ -46,7 +46,7 @@ public void streamSnippet() throws MalformedURLException { }); } }); - // END: com.azure.core.http.rest.iterableResponse.stream + // END: com.azure.core.util.iterableStream.stream } /** @@ -60,12 +60,12 @@ public void iteratorwhileSnippet() throws MalformedURLException { String deserializedHeaders = "header1,value1,header2,value2"; - IterableResponse> myIterableResponse = - new IterableResponse<>(Flux.just(createPagedResponse(httpRequest, httpHeaders, deserializedHeaders, 1, 3))); + IterableStream> myIterableStream = + new IterableStream<>(Flux.just(createPagedResponse(httpRequest, httpHeaders, deserializedHeaders, 1, 3))); - // BEGIN: com.azure.core.http.rest.iterableResponse.iterator.while + // BEGIN: com.azure.core.util.iterableStream.iterator.while // Iterate over iterator - Iterator> ite = myIterableResponse.iterator(); + Iterator> ite = myIterableStream.iterator(); while (ite.hasNext()) { PagedResponseBase resp = ite.next(); if (resp.statusCode() == HttpURLConnection.HTTP_OK) { @@ -75,7 +75,7 @@ public void iteratorwhileSnippet() throws MalformedURLException { }); } } - // END: com.azure.core.http.rest.iterableResponse.iterator.while + // END: com.azure.core.util.iterableStream.iterator.while } /** @@ -89,12 +89,12 @@ public void iteratorStreamFilterSnippet() throws MalformedURLException { String deserializedHeaders = "header1,value1,header2,value2"; - IterableResponse> myIterableResponse = - new IterableResponse<>(Flux.just(createPagedResponse(httpRequest, httpHeaders, deserializedHeaders, 1, 3))); + IterableStream> myIterableStream = + new IterableStream<>(Flux.just(createPagedResponse(httpRequest, httpHeaders, deserializedHeaders, 1, 3))); - // BEGIN: com.azure.core.http.rest.iterableResponse.stream.filter + // BEGIN: com.azure.core.util.iterableStream.stream.filter // process the stream - myIterableResponse.stream().filter(resp -> resp.statusCode() == HttpURLConnection.HTTP_OK) + myIterableStream.stream().filter(resp -> resp.statusCode() == HttpURLConnection.HTTP_OK) .limit(10) .forEach(resp -> { System.out.printf("Response headers are %s. Url %s%n", resp.deserializedHeaders(), resp.request().url()); @@ -102,7 +102,7 @@ public void iteratorStreamFilterSnippet() throws MalformedURLException { System.out.printf("Response value is %d%n", value); }); }); - // END: com.azure.core.http.rest.iterableResponse.stream.filter + // END: com.azure.core.util.iterableStream.stream.filter } private PagedResponseBase createPagedResponse(HttpRequest httpRequest, HttpHeaders httpHeaders, diff --git a/sdk/core/azure-core/src/test/java/com/azure/core/http/rest/IterableResponseTest.java b/sdk/core/azure-core/src/test/java/com/azure/core/http/rest/IterableResponseTest.java index e74104f1a6b6c..a5b05348eee7a 100644 --- a/sdk/core/azure-core/src/test/java/com/azure/core/http/rest/IterableResponseTest.java +++ b/sdk/core/azure-core/src/test/java/com/azure/core/http/rest/IterableResponseTest.java @@ -8,6 +8,7 @@ import java.util.List; import java.util.stream.Collectors; +import com.azure.core.util.IterableStream; import org.junit.Assert; import org.junit.Before; import org.junit.Rule; @@ -30,7 +31,7 @@ public void setup() { /*Ensure that if we call stream multiple times, it always returns same values and they are same as original list of values.*/ @Test public void testIterableResponseStreamFromStart() { - IterableResponse iterableResponse = getIntegerIterableResponse(2, 5); + IterableStream iterableResponse = getIntegerIterableResponse(2, 5); Assert.assertEquals(iterableResponse.stream().collect(Collectors.toList()).size(), iterableResponse.stream().collect(Collectors.toList()).size()); // ensure original list of values are same after calling iterator() @@ -41,7 +42,7 @@ public void testIterableResponseStreamFromStart() { /*Ensure that if we call iterator multiple times, it always returns same values and they are same as original list of values.*/ @Test public void testIterableResponseIteratorFromStart() { - IterableResponse iterableResponse = getIntegerIterableResponse(2, 5); + IterableStream iterableResponse = getIntegerIterableResponse(2, 5); List actualNumberValues1 = new ArrayList<>(); List actualNumberValues2 = new ArrayList<>(); iterableResponse.iterator().forEachRemaining(number -> actualNumberValues1.add(number)); @@ -53,8 +54,8 @@ public void testIterableResponseIteratorFromStart() { iterableResponse.iterator().forEachRemaining(number -> Assert.assertTrue(originalIntegerList.contains(number))); } - private IterableResponse getIntegerIterableResponse(int startNumber, int noOfValues) { + private IterableStream getIntegerIterableResponse(int startNumber, int noOfValues) { Flux integerFlux = Flux.range(startNumber, noOfValues); - return new IterableResponse<>(integerFlux); + return new IterableStream<>(integerFlux); } } diff --git a/sdk/eventhubs/azure-messaging-eventhubs/src/main/java/com/azure/messaging/eventhubs/EventHubClient.java b/sdk/eventhubs/azure-messaging-eventhubs/src/main/java/com/azure/messaging/eventhubs/EventHubClient.java index 0311132951878..69203b190f7de 100644 --- a/sdk/eventhubs/azure-messaging-eventhubs/src/main/java/com/azure/messaging/eventhubs/EventHubClient.java +++ b/sdk/eventhubs/azure-messaging-eventhubs/src/main/java/com/azure/messaging/eventhubs/EventHubClient.java @@ -4,7 +4,7 @@ package com.azure.messaging.eventhubs; import com.azure.core.amqp.RetryOptions; -import com.azure.core.http.rest.IterableResponse; +import com.azure.core.util.IterableStream; import com.azure.core.implementation.annotation.ReturnType; import com.azure.core.implementation.annotation.ServiceClient; import com.azure.core.implementation.annotation.ServiceMethod; @@ -67,8 +67,8 @@ public EventHubProperties getProperties() { * @return The identifiers for all partitions of an Event Hub. */ @ServiceMethod(returns = ReturnType.COLLECTION) - public IterableResponse getPartitionIds() { - return new IterableResponse<>(client.getPartitionIds()); + public IterableStream getPartitionIds() { + return new IterableStream<>(client.getPartitionIds()); } /** diff --git a/sdk/eventhubs/azure-messaging-eventhubs/src/main/java/com/azure/messaging/eventhubs/EventHubConsumer.java b/sdk/eventhubs/azure-messaging-eventhubs/src/main/java/com/azure/messaging/eventhubs/EventHubConsumer.java index 7650df110601e..c06e94a6de666 100644 --- a/sdk/eventhubs/azure-messaging-eventhubs/src/main/java/com/azure/messaging/eventhubs/EventHubConsumer.java +++ b/sdk/eventhubs/azure-messaging-eventhubs/src/main/java/com/azure/messaging/eventhubs/EventHubConsumer.java @@ -3,7 +3,7 @@ package com.azure.messaging.eventhubs; -import com.azure.core.http.rest.IterableResponse; +import com.azure.core.util.IterableStream; import com.azure.messaging.eventhubs.models.EventHubConsumerOptions; import com.azure.messaging.eventhubs.models.EventPosition; import reactor.core.publisher.Flux; @@ -48,8 +48,8 @@ public class EventHubConsumer implements Closeable { * @return A set of {@link EventData} that was received. The iterable contains up to {@code maximumMessageCount} * events. */ - public IterableResponse receive(int maximumMessageCount) { - return new IterableResponse<>(Flux.empty()); + public IterableStream receive(int maximumMessageCount) { + return new IterableStream<>(Flux.empty()); } /** @@ -61,8 +61,8 @@ public IterableResponse receive(int maximumMessageCount) { * @return A set of {@link EventData} that was received. The iterable contains up to {@code maximumMessageCount} * events. */ - public IterableResponse receive(int maximumMessageCount, Duration maximumWaitTime) { - return new IterableResponse<>(Flux.empty()); + public IterableStream receive(int maximumMessageCount, Duration maximumWaitTime) { + return new IterableStream<>(Flux.empty()); } /** diff --git a/sdk/eventhubs/azure-messaging-eventhubs/src/test/java/com/azure/messaging/eventhubs/EventHubClientIntegrationTest.java b/sdk/eventhubs/azure-messaging-eventhubs/src/test/java/com/azure/messaging/eventhubs/EventHubClientIntegrationTest.java index db8edc51cc50d..31fbc407153a4 100644 --- a/sdk/eventhubs/azure-messaging-eventhubs/src/test/java/com/azure/messaging/eventhubs/EventHubClientIntegrationTest.java +++ b/sdk/eventhubs/azure-messaging-eventhubs/src/test/java/com/azure/messaging/eventhubs/EventHubClientIntegrationTest.java @@ -3,7 +3,7 @@ package com.azure.messaging.eventhubs; -import com.azure.core.http.rest.IterableResponse; +import com.azure.core.util.IterableStream; import com.azure.core.util.logging.ClientLogger; import com.azure.messaging.eventhubs.implementation.ApiTestBase; import com.azure.messaging.eventhubs.implementation.ConnectionStringProperties; @@ -52,7 +52,7 @@ protected void afterTest() { @Test public void getPartitionIds() { // Act - final IterableResponse response = client.getPartitionIds(); + final IterableStream response = client.getPartitionIds(); // Assert Assert.assertNotNull(response);