Skip to content
This repository has been archived by the owner on Oct 3, 2023. It is now read-only.

feat: generate sample code in the Java microgenerator #41

Merged
merged 1 commit into from Feb 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -42,6 +42,14 @@
* <p>This class provides the ability to make remote calls to the backing service through method
* calls that map to API methods. Sample code to get started:
*
* <pre>{@code
* try (CatalogServiceClient catalogServiceClient = CatalogServiceClient.create()) {
* Catalog catalog = Catalog.newBuilder().build();
* FieldMask updateMask = FieldMask.newBuilder().build();
* Catalog response = catalogServiceClient.updateCatalog(catalog, updateMask);
* }
* }</pre>
*
* <p>Note: close() needs to be called on the CatalogServiceClient object to clean up resources such
* as threads. In the example above, try-with-resources is used, which automatically calls close().
*
Expand Down Expand Up @@ -145,6 +153,17 @@ public CatalogServiceStub getStub() {
/**
* Lists all the [Catalog][google.cloud.retail.v2.Catalog]s associated with the project.
*
* <p>Sample code:
*
* <pre>{@code
* try (CatalogServiceClient catalogServiceClient = CatalogServiceClient.create()) {
* LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
* for (Catalog element : catalogServiceClient.listCatalogs(parent).iterateAll()) {
* // doThingsWith(element);
* }
* }
* }</pre>
*
* @param parent Required. The account resource name with an associated location.
* <p>If the caller does not have permission to list
* [Catalog][google.cloud.retail.v2.Catalog]s under this location, regardless of whether or
Expand All @@ -163,6 +182,17 @@ public final ListCatalogsPagedResponse listCatalogs(LocationName parent) {
/**
* Lists all the [Catalog][google.cloud.retail.v2.Catalog]s associated with the project.
*
* <p>Sample code:
*
* <pre>{@code
* try (CatalogServiceClient catalogServiceClient = CatalogServiceClient.create()) {
* String parent = LocationName.of("[PROJECT]", "[LOCATION]").toString();
* for (Catalog element : catalogServiceClient.listCatalogs(parent).iterateAll()) {
* // doThingsWith(element);
* }
* }
* }</pre>
*
* @param parent Required. The account resource name with an associated location.
* <p>If the caller does not have permission to list
* [Catalog][google.cloud.retail.v2.Catalog]s under this location, regardless of whether or
Expand All @@ -178,6 +208,22 @@ public final ListCatalogsPagedResponse listCatalogs(String parent) {
/**
* Lists all the [Catalog][google.cloud.retail.v2.Catalog]s associated with the project.
*
* <p>Sample code:
*
* <pre>{@code
* try (CatalogServiceClient catalogServiceClient = CatalogServiceClient.create()) {
* ListCatalogsRequest request =
* ListCatalogsRequest.newBuilder()
* .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString())
* .setPageSize(883849137)
* .setPageToken("pageToken873572522")
* .build();
* for (Catalog element : catalogServiceClient.listCatalogs(request).iterateAll()) {
* // doThingsWith(element);
* }
* }
* }</pre>
*
* @param request The request object containing all of the parameters for the API call.
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
*/
Expand All @@ -190,6 +236,23 @@ public final ListCatalogsPagedResponse listCatalogs(ListCatalogsRequest request)
* Lists all the [Catalog][google.cloud.retail.v2.Catalog]s associated with the project.
*
* <p>Sample code:
*
* <pre>{@code
* try (CatalogServiceClient catalogServiceClient = CatalogServiceClient.create()) {
* ListCatalogsRequest request =
* ListCatalogsRequest.newBuilder()
* .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString())
* .setPageSize(883849137)
* .setPageToken("pageToken873572522")
* .build();
* ApiFuture<Catalog> future =
* catalogServiceClient.listCatalogsPagedCallable().futureCall(request);
* // Do something.
* for (Catalog element : future.get().iterateAll()) {
* // doThingsWith(element);
* }
* }
* }</pre>
*/
public final UnaryCallable<ListCatalogsRequest, ListCatalogsPagedResponse>
listCatalogsPagedCallable() {
Expand All @@ -201,6 +264,23 @@ public final ListCatalogsPagedResponse listCatalogs(ListCatalogsRequest request)
* Lists all the [Catalog][google.cloud.retail.v2.Catalog]s associated with the project.
*
* <p>Sample code:
*
* <pre>{@code
* try (CatalogServiceClient catalogServiceClient = CatalogServiceClient.create()) {
* while (true) {
* ListCatalogsResponse response = catalogServiceClient.listCatalogsCallable().call(request);
* for (Catalog element : response.getResponsesList()) {
* // doThingsWith(element);
* }
* String nextPageToken = response.getNextPageToken();
* if (!Strings.isNullOrEmpty(nextPageToken)) {
* request = request.toBuilder().setPageToken(nextPageToken).build();
* } else {
* break;
* }
* }
* }
* }</pre>
*/
public final UnaryCallable<ListCatalogsRequest, ListCatalogsResponse> listCatalogsCallable() {
return stub.listCatalogsCallable();
Expand All @@ -210,6 +290,16 @@ public final UnaryCallable<ListCatalogsRequest, ListCatalogsResponse> listCatalo
/**
* Updates the [Catalog][google.cloud.retail.v2.Catalog]s.
*
* <p>Sample code:
*
* <pre>{@code
* try (CatalogServiceClient catalogServiceClient = CatalogServiceClient.create()) {
* Catalog catalog = Catalog.newBuilder().build();
* FieldMask updateMask = FieldMask.newBuilder().build();
* Catalog response = catalogServiceClient.updateCatalog(catalog, updateMask);
* }
* }</pre>
*
* @param catalog Required. The [Catalog][google.cloud.retail.v2.Catalog] to update.
* <p>If the caller does not have permission to update the
* [Catalog][google.cloud.retail.v2.Catalog], regardless of whether or not it exists, a
Expand All @@ -233,6 +323,19 @@ public final Catalog updateCatalog(Catalog catalog, FieldMask updateMask) {
/**
* Updates the [Catalog][google.cloud.retail.v2.Catalog]s.
*
* <p>Sample code:
*
* <pre>{@code
* try (CatalogServiceClient catalogServiceClient = CatalogServiceClient.create()) {
* UpdateCatalogRequest request =
* UpdateCatalogRequest.newBuilder()
* .setCatalog(Catalog.newBuilder().build())
* .setUpdateMask(FieldMask.newBuilder().build())
* .build();
* Catalog response = catalogServiceClient.updateCatalog(request);
* }
* }</pre>
*
* @param request The request object containing all of the parameters for the API call.
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
*/
Expand All @@ -245,6 +348,19 @@ public final Catalog updateCatalog(UpdateCatalogRequest request) {
* Updates the [Catalog][google.cloud.retail.v2.Catalog]s.
*
* <p>Sample code:
*
* <pre>{@code
* try (CatalogServiceClient catalogServiceClient = CatalogServiceClient.create()) {
* UpdateCatalogRequest request =
* UpdateCatalogRequest.newBuilder()
* .setCatalog(Catalog.newBuilder().build())
* .setUpdateMask(FieldMask.newBuilder().build())
* .build();
* ApiFuture<Catalog> future = catalogServiceClient.updateCatalogCallable().futureCall(request);
* // Do something.
* Catalog response = future.get();
* }
* }</pre>
*/
public final UnaryCallable<UpdateCatalogRequest, Catalog> updateCatalogCallable() {
return stub.updateCatalogCallable();
Expand Down
Expand Up @@ -32,6 +32,23 @@
* <p>This class provides the ability to make remote calls to the backing service through method
* calls that map to API methods. Sample code to get started:
*
* <pre>{@code
* try (PredictionServiceClient predictionServiceClient = PredictionServiceClient.create()) {
* PredictRequest request =
* PredictRequest.newBuilder()
* .setPlacement("placement1792938725")
* .setUserEvent(UserEvent.newBuilder().build())
* .setPageSize(883849137)
* .setPageToken("pageToken873572522")
* .setFilter("filter-1274492040")
* .setValidateOnly(true)
* .putAllParams(new HashMap<String, Value>())
* .putAllLabels(new HashMap<String, String>())
* .build();
* PredictResponse response = predictionServiceClient.predict(request);
* }
* }</pre>
*
* <p>Note: close() needs to be called on the PredictionServiceClient object to clean up resources
* such as threads. In the example above, try-with-resources is used, which automatically calls
* close().
Expand Down Expand Up @@ -138,6 +155,25 @@ public PredictionServiceStub getStub() {
/**
* Makes a recommendation prediction.
*
* <p>Sample code:
*
* <pre>{@code
* try (PredictionServiceClient predictionServiceClient = PredictionServiceClient.create()) {
* PredictRequest request =
* PredictRequest.newBuilder()
* .setPlacement("placement1792938725")
* .setUserEvent(UserEvent.newBuilder().build())
* .setPageSize(883849137)
* .setPageToken("pageToken873572522")
* .setFilter("filter-1274492040")
* .setValidateOnly(true)
* .putAllParams(new HashMap<String, Value>())
* .putAllLabels(new HashMap<String, String>())
* .build();
* PredictResponse response = predictionServiceClient.predict(request);
* }
* }</pre>
*
* @param request The request object containing all of the parameters for the API call.
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
*/
Expand All @@ -150,6 +186,26 @@ public final PredictResponse predict(PredictRequest request) {
* Makes a recommendation prediction.
*
* <p>Sample code:
*
* <pre>{@code
* try (PredictionServiceClient predictionServiceClient = PredictionServiceClient.create()) {
* PredictRequest request =
* PredictRequest.newBuilder()
* .setPlacement("placement1792938725")
* .setUserEvent(UserEvent.newBuilder().build())
* .setPageSize(883849137)
* .setPageToken("pageToken873572522")
* .setFilter("filter-1274492040")
* .setValidateOnly(true)
* .putAllParams(new HashMap<String, Value>())
* .putAllLabels(new HashMap<String, String>())
* .build();
* ApiFuture<PredictResponse> future =
* predictionServiceClient.predictCallable().futureCall(request);
* // Do something.
* PredictResponse response = future.get();
* }
* }</pre>
*/
public final UnaryCallable<PredictRequest, PredictResponse> predictCallable() {
return stub.predictCallable();
Expand Down