Skip to content
This repository was archived by the owner on Sep 26, 2023. It is now read-only.

Commit 91c968e

Browse files
Renaming 'create' methods to 'of' (#393)
1 parent 050c852 commit 91c968e

38 files changed

Lines changed: 191 additions & 102 deletions

gax-grpc/src/main/java/com/google/api/gax/grpc/GrpcLongRunningClient.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public GrpcLongRunningClient(OperationsStub operationsStub) {
5555

5656
@Override
5757
public UnaryCallable<String, OperationSnapshot> getOperationCallable() {
58-
return TranslatingUnaryCallable.create(
58+
return TranslatingUnaryCallable.of(
5959
operationsStub.getOperationCallable(),
6060
new ApiFunction<String, GetOperationRequest>() {
6161
@Override
@@ -66,14 +66,14 @@ public GetOperationRequest apply(String request) {
6666
new ApiFunction<Operation, OperationSnapshot>() {
6767
@Override
6868
public OperationSnapshot apply(Operation operation) {
69-
return GrpcOperationSnapshot.create(operation);
69+
return GrpcOperationSnapshot.of(operation);
7070
}
7171
});
7272
}
7373

7474
@Override
7575
public UnaryCallable<String, Void> cancelOperationCallable() {
76-
return TranslatingUnaryCallable.create(
76+
return TranslatingUnaryCallable.of(
7777
operationsStub.cancelOperationCallable(),
7878
new ApiFunction<String, CancelOperationRequest>() {
7979
@Override
@@ -91,7 +91,7 @@ public Void apply(Empty empty) {
9191

9292
@Override
9393
public UnaryCallable<String, Void> deleteOperationCallable() {
94-
return TranslatingUnaryCallable.create(
94+
return TranslatingUnaryCallable.of(
9595
operationsStub.deleteOperationCallable(),
9696
new ApiFunction<String, DeleteOperationRequest>() {
9797
@Override
@@ -107,7 +107,7 @@ public Void apply(Empty empty) {
107107
});
108108
}
109109

110-
public static GrpcLongRunningClient create(OperationsStub operationsStub) {
110+
public static GrpcLongRunningClient of(OperationsStub operationsStub) {
111111
return new GrpcLongRunningClient(operationsStub);
112112
}
113113
}

gax-grpc/src/main/java/com/google/api/gax/grpc/GrpcOperationSnapshot.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public StatusCode getErrorCode() {
7272
return GrpcStatusCode.of(Status.fromCodeValue(operation.getError().getCode()).getCode());
7373
}
7474

75-
public static GrpcOperationSnapshot create(Operation operation) {
75+
public static GrpcOperationSnapshot of(Operation operation) {
7676
return new GrpcOperationSnapshot(operation);
7777
}
7878
}

gax-grpc/src/main/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProvider.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public boolean needsExecutor() {
8585

8686
@Override
8787
public TransportChannelProvider withExecutor(ScheduledExecutorService executor) {
88-
return toBuilder().setExecutorProvider(FixedExecutorProvider.create(executor)).build();
88+
return toBuilder().setExecutorProvider(FixedExecutorProvider.of(executor)).build();
8989
}
9090

9191
@Override
@@ -95,7 +95,7 @@ public boolean needsHeaders() {
9595

9696
@Override
9797
public TransportChannelProvider withHeaders(Map<String, String> headers) {
98-
return toBuilder().setHeaderProvider(FixedHeaderProvider.create(headers)).build();
98+
return toBuilder().setHeaderProvider(FixedHeaderProvider.of(headers)).build();
9999
}
100100

101101
@Override

gax-grpc/src/main/java/com/google/longrunning/OperationsClient.java

Lines changed: 42 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
*
5757
* <pre>
5858
* <code>
59-
* try (OperationsClient operationsClient = OperationsClient.create()) {
59+
* try (OperationsClient operationsClient = OperationsClient.of()) {
6060
* String name = "";
6161
* Operation response = operationsClient.getOperation(name);
6262
* }
@@ -86,17 +86,17 @@
8686
* these names, this class includes a format method for each type of name, and additionally a parse
8787
* method to extract the individual identifiers contained within names that are returned.
8888
*
89-
* <p>This class can be customized by passing in a custom instance of OperationsSettings to
90-
* create(). For example:
89+
* <p>This class can be customized by passing in a custom instance of OperationsSettings to {@link
90+
* #of(OperationsSettings)}. For example:
9191
*
9292
* <pre>
9393
* <code>
9494
* OperationsSettings operationsSettings =
9595
* OperationsSettings.newBuilder()
96-
* .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
96+
* .setCredentialsProvider(FixedCredentialsProvider.of(myCredentials))
9797
* .build();
9898
* OperationsClient operationsClient =
99-
* OperationsClient.create(operationsSettings);
99+
* OperationsClient.of(operationsSettings);
100100
* </code>
101101
* </pre>
102102
*/
@@ -109,16 +109,39 @@ public class OperationsClient implements BackgroundResource {
109109
/**
110110
* Constructs an instance of OperationsClient, using the given settings. The channels are created
111111
* based on the settings passed in, or defaults for any settings that are not set.
112+
*
113+
* @deprecated Use {@link #of(OperationsSettings)} instead.
112114
*/
115+
@Deprecated
113116
public static final OperationsClient create(OperationsSettings settings) throws IOException {
114-
return new OperationsClient(settings);
117+
return of(settings);
115118
}
116119

117120
/**
118121
* Constructs an instance of OperationsClient, using the given stub for making calls. This is for
119122
* advanced usage - prefer to use OperationsSettings}.
123+
*
124+
* @deprecated Use {@link #of(OperationsStub)} instead.
120125
*/
126+
@Deprecated
121127
public static final OperationsClient create(OperationsStub stub) {
128+
return of(stub);
129+
}
130+
131+
/**
132+
* Constructs an instance of OperationsClient, using the given settings. The channels are created
133+
* based on the settings passed in, or defaults for any settings that are not set.
134+
*/
135+
public static final OperationsClient of(OperationsSettings settings) throws IOException {
136+
return new OperationsClient(settings);
137+
}
138+
139+
/**
140+
* Constructs an instance of OperationsClient, using the given stub for making calls. This is for
141+
* advanced usage - prefer to use OperationsSettings}.
142+
*/
143+
@BetaApi
144+
public static final OperationsClient of(OperationsStub stub) {
122145
return new OperationsClient(stub);
123146
}
124147

@@ -152,7 +175,7 @@ public OperationsStub getStub() {
152175
* <p>Sample code:
153176
*
154177
* <pre><code>
155-
* try (OperationsClient operationsClient = OperationsClient.create()) {
178+
* try (OperationsClient operationsClient = OperationsClient.of()) {
156179
* String name = "";
157180
* Operation response = operationsClient.getOperation(name);
158181
* }
@@ -175,7 +198,7 @@ public final Operation getOperation(String name) {
175198
* <p>Sample code:
176199
*
177200
* <pre><code>
178-
* try (OperationsClient operationsClient = OperationsClient.create()) {
201+
* try (OperationsClient operationsClient = OperationsClient.of()) {
179202
* String name = "";
180203
* GetOperationRequest request = GetOperationRequest.newBuilder()
181204
* .setName(name)
@@ -199,7 +222,7 @@ private final Operation getOperation(GetOperationRequest request) {
199222
* <p>Sample code:
200223
*
201224
* <pre><code>
202-
* try (OperationsClient operationsClient = OperationsClient.create()) {
225+
* try (OperationsClient operationsClient = OperationsClient.of()) {
203226
* String name = "";
204227
* GetOperationRequest request = GetOperationRequest.newBuilder()
205228
* .setName(name)
@@ -225,7 +248,7 @@ public final UnaryCallable<GetOperationRequest, Operation> getOperationCallable(
225248
* <p>Sample code:
226249
*
227250
* <pre><code>
228-
* try (OperationsClient operationsClient = OperationsClient.create()) {
251+
* try (OperationsClient operationsClient = OperationsClient.of()) {
229252
* String name = "";
230253
* String filter = "";
231254
* for (Operation element : operationsClient.listOperations(name, filter).iterateAll()) {
@@ -255,7 +278,7 @@ public final ListOperationsPagedResponse listOperations(String name, String filt
255278
* <p>Sample code:
256279
*
257280
* <pre><code>
258-
* try (OperationsClient operationsClient = OperationsClient.create()) {
281+
* try (OperationsClient operationsClient = OperationsClient.of()) {
259282
* String name = "";
260283
* String filter = "";
261284
* ListOperationsRequest request = ListOperationsRequest.newBuilder()
@@ -286,7 +309,7 @@ public final ListOperationsPagedResponse listOperations(ListOperationsRequest re
286309
* <p>Sample code:
287310
*
288311
* <pre><code>
289-
* try (OperationsClient operationsClient = OperationsClient.create()) {
312+
* try (OperationsClient operationsClient = OperationsClient.of()) {
290313
* String name = "";
291314
* String filter = "";
292315
* ListOperationsRequest request = ListOperationsRequest.newBuilder()
@@ -317,7 +340,7 @@ public final ListOperationsPagedResponse listOperations(ListOperationsRequest re
317340
* <p>Sample code:
318341
*
319342
* <pre><code>
320-
* try (OperationsClient operationsClient = OperationsClient.create()) {
343+
* try (OperationsClient operationsClient = OperationsClient.of()) {
321344
* String name = "";
322345
* String filter = "";
323346
* ListOperationsRequest request = ListOperationsRequest.newBuilder()
@@ -358,7 +381,7 @@ public final ListOperationsPagedResponse listOperations(ListOperationsRequest re
358381
* <p>Sample code:
359382
*
360383
* <pre><code>
361-
* try (OperationsClient operationsClient = OperationsClient.create()) {
384+
* try (OperationsClient operationsClient = OperationsClient.of()) {
362385
* String name = "";
363386
* operationsClient.cancelOperation(name);
364387
* }
@@ -387,7 +410,7 @@ public final void cancelOperation(String name) {
387410
* <p>Sample code:
388411
*
389412
* <pre><code>
390-
* try (OperationsClient operationsClient = OperationsClient.create()) {
413+
* try (OperationsClient operationsClient = OperationsClient.of()) {
391414
* String name = "";
392415
* CancelOperationRequest request = CancelOperationRequest.newBuilder()
393416
* .setName(name)
@@ -417,7 +440,7 @@ private final void cancelOperation(CancelOperationRequest request) {
417440
* <p>Sample code:
418441
*
419442
* <pre><code>
420-
* try (OperationsClient operationsClient = OperationsClient.create()) {
443+
* try (OperationsClient operationsClient = OperationsClient.of()) {
421444
* String name = "";
422445
* CancelOperationRequest request = CancelOperationRequest.newBuilder()
423446
* .setName(name)
@@ -441,7 +464,7 @@ public final UnaryCallable<CancelOperationRequest, Empty> cancelOperationCallabl
441464
* <p>Sample code:
442465
*
443466
* <pre><code>
444-
* try (OperationsClient operationsClient = OperationsClient.create()) {
467+
* try (OperationsClient operationsClient = OperationsClient.of()) {
445468
* String name = "";
446469
* operationsClient.deleteOperation(name);
447470
* }
@@ -465,7 +488,7 @@ public final void deleteOperation(String name) {
465488
* <p>Sample code:
466489
*
467490
* <pre><code>
468-
* try (OperationsClient operationsClient = OperationsClient.create()) {
491+
* try (OperationsClient operationsClient = OperationsClient.of()) {
469492
* String name = "";
470493
* DeleteOperationRequest request = DeleteOperationRequest.newBuilder()
471494
* .setName(name)
@@ -490,7 +513,7 @@ private final void deleteOperation(DeleteOperationRequest request) {
490513
* <p>Sample code:
491514
*
492515
* <pre><code>
493-
* try (OperationsClient operationsClient = OperationsClient.create()) {
516+
* try (OperationsClient operationsClient = OperationsClient.of()) {
494517
* String name = "";
495518
* DeleteOperationRequest request = DeleteOperationRequest.newBuilder()
496519
* .setName(name)

gax-grpc/src/main/java/com/google/longrunning/OperationsSettings.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public OperationsStub createStub() throws IOException {
113113
if (getTransportChannelProvider()
114114
.getTransportName()
115115
.equals(GrpcTransportChannel.getGrpcTransportName())) {
116-
return GrpcOperationsStub.create(this);
116+
return GrpcOperationsStub.of(this);
117117
} else {
118118
throw new UnsupportedOperationException(
119119
"Transport not supported: " + getTransportChannelProvider().getTransportName());
@@ -238,7 +238,7 @@ public ApiFuture<ListOperationsPagedResponse> getFuturePagedResponse(
238238
ApiCallContext context,
239239
ApiFuture<ListOperationsResponse> futureResponse) {
240240
PageContext<ListOperationsRequest, ListOperationsResponse, Operation> pageContext =
241-
PageContext.create(callable, LIST_OPERATIONS_PAGE_STR_DESC, request, context);
241+
PageContext.of(callable, LIST_OPERATIONS_PAGE_STR_DESC, request, context);
242242
return ListOperationsPagedResponse.createAsync(pageContext, futureResponse);
243243
}
244244
};

gax-grpc/src/main/java/com/google/longrunning/stub/GrpcOperationsStub.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,23 @@ public class GrpcOperationsStub extends OperationsStub {
102102
private final UnaryCallable<CancelOperationRequest, Empty> cancelOperationCallable;
103103
private final UnaryCallable<DeleteOperationRequest, Empty> deleteOperationCallable;
104104

105+
/** @deprecated Use {@link #of(OperationsSettings)} instead. */
106+
@Deprecated
105107
public static final GrpcOperationsStub create(OperationsSettings settings) throws IOException {
106-
return new GrpcOperationsStub(settings, ClientContext.create(settings));
108+
return of(settings);
107109
}
108110

111+
/** @deprecated Use {@link #of(ClientContext)} instead. */
112+
@Deprecated
109113
public static final GrpcOperationsStub create(ClientContext clientContext) throws IOException {
114+
return of(clientContext);
115+
}
116+
117+
public static final GrpcOperationsStub of(OperationsSettings settings) throws IOException {
118+
return new GrpcOperationsStub(settings, ClientContext.of(settings));
119+
}
120+
121+
public static final GrpcOperationsStub of(ClientContext clientContext) throws IOException {
110122
return new GrpcOperationsStub(OperationsSettings.newBuilder().build(), clientContext);
111123
}
112124

gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcHeaderInterceptorTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public class GrpcHeaderInterceptorTest {
6262

6363
@Mock private ClientCall<String, Integer> call;
6464

65-
private static final MethodDescriptor<String, Integer> method = FakeMethodDescriptor.create();
65+
private static final MethodDescriptor<String, Integer> method = FakeMethodDescriptor.of();
6666

6767
/** Sets up mocks. */
6868
@Before

gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcLongRunningTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ public void setUp() throws IOException {
103103
when(operationsChannelProvider.getTransportChannel()).thenReturn(transportChannel);
104104

105105
clock = new FakeApiClock(0L);
106-
executor = RecordingScheduler.create(clock);
107-
pollingAlgorithm = OperationTimedPollAlgorithm.create(FAST_RETRY_SETTINGS, clock);
106+
executor = RecordingScheduler.of(clock);
107+
pollingAlgorithm = OperationTimedPollAlgorithm.of(FAST_RETRY_SETTINGS, clock);
108108

109109
OperationsSettings.Builder settingsBuilder = OperationsSettings.newBuilder();
110110
settingsBuilder
@@ -114,7 +114,7 @@ public void setUp() throws IOException {
114114
OperationsSettings.newBuilder()
115115
.setTransportChannelProvider(operationsChannelProvider)
116116
.build();
117-
operationsStub = GrpcOperationsStub.create(settings);
117+
operationsStub = GrpcOperationsStub.of(settings);
118118

119119
UnaryCallSettings<Integer, OperationSnapshot> initialCallSettings =
120120
UnaryCallSettings.<Integer, OperationSnapshot>newUnaryCallSettingsBuilder()
@@ -228,6 +228,6 @@ private void mockResponse(ManagedChannel channel, Code statusCode, Object... res
228228
}
229229

230230
private GrpcCallSettings<Integer, Operation> createGrpcSettings() {
231-
return GrpcCallSettings.of(FakeMethodDescriptor.<Integer, Operation>create());
231+
return GrpcCallSettings.of(FakeMethodDescriptor.<Integer, Operation>of());
232232
}
233233
}

gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcOperationTransformersTest.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ public void testResponseTransformer() {
5656
ResponseTransformer<Money> transformer = ResponseTransformer.of(Money.class);
5757
Money inputMoney = Money.newBuilder().setCurrencyCode("USD").build();
5858
OperationSnapshot operationSnapshot =
59-
GrpcOperationSnapshot.create(
60-
Operation.newBuilder().setResponse(Any.pack(inputMoney)).build());
59+
GrpcOperationSnapshot.of(Operation.newBuilder().setResponse(Any.pack(inputMoney)).build());
6160
Truth.assertThat(transformer.apply(operationSnapshot)).isEqualTo(inputMoney);
6261
}
6362

@@ -68,7 +67,7 @@ public void testResponseTransformer_exception() {
6867
Money inputMoney = Money.newBuilder().setCurrencyCode("USD").build();
6968
Status status = Status.newBuilder().setCode(Code.UNAVAILABLE.value()).build();
7069
OperationSnapshot operationSnapshot =
71-
GrpcOperationSnapshot.create(
70+
GrpcOperationSnapshot.of(
7271
Operation.newBuilder().setResponse(Any.pack(inputMoney)).setError(status).build());
7372
Truth.assertThat(transformer.apply(operationSnapshot)).isEqualTo(inputMoney);
7473
}
@@ -81,7 +80,7 @@ public void testResponseTransformer_mismatchedTypes() {
8180
Money inputMoney = Money.newBuilder().setCurrencyCode("USD").build();
8281
Status status = Status.newBuilder().setCode(Code.OK.value()).build();
8382
OperationSnapshot operationSnapshot =
84-
GrpcOperationSnapshot.create(
83+
GrpcOperationSnapshot.of(
8584
Operation.newBuilder()
8685
.setResponse(Any.pack(Color.getDefaultInstance()))
8786
.setError(status)
@@ -94,8 +93,7 @@ public void testMetadataTransformer() {
9493
MetadataTransformer<Money> transformer = MetadataTransformer.of(Money.class);
9594
Money inputMoney = Money.newBuilder().setCurrencyCode("USD").build();
9695
OperationSnapshot operationSnapshot =
97-
GrpcOperationSnapshot.create(
98-
Operation.newBuilder().setMetadata(Any.pack(inputMoney)).build());
96+
GrpcOperationSnapshot.of(Operation.newBuilder().setMetadata(Any.pack(inputMoney)).build());
9997
Truth.assertThat(transformer.apply(operationSnapshot)).isEqualTo(inputMoney);
10098
}
10199

@@ -107,7 +105,7 @@ public void testMetadataTransformer_mismatchedTypes() {
107105
Money inputMoney = Money.newBuilder().setCurrencyCode("USD").build();
108106
Status status = Status.newBuilder().setCode(Code.OK.value()).build();
109107
OperationSnapshot operationSnapshot =
110-
GrpcOperationSnapshot.create(
108+
GrpcOperationSnapshot.of(
111109
Operation.newBuilder()
112110
.setMetadata(Any.pack(Color.getDefaultInstance()))
113111
.setError(status)

0 commit comments

Comments
 (0)