MCPcopy Create free account
hub / github.com/grpc/grpc-java / withOption

Method withOption

api/src/main/java/io/grpc/CallOptions.java:400–425  ·  view source on GitHub ↗

Sets a custom option. Any existing value for the key is overwritten. @param key The option key @param value The option value. @since 1.13.0

(Key<T> key, T value)

Source from the content-addressed store, hash-verified

398 * @since 1.13.0
399 */
400 public <T> CallOptions withOption(Key<T> key, T value) {
401 Preconditions.checkNotNull(key, "key");
402 Preconditions.checkNotNull(value, "value");
403
404 Builder builder = toBuilder(this);
405 int existingIdx = -1;
406 for (int i = 0; i < customOptions.length; i++) {
407 if (key.equals(customOptions[i][0])) {
408 existingIdx = i;
409 break;
410 }
411 }
412
413 builder.customOptions = new Object[customOptions.length + (existingIdx == -1 ? 1 : 0)][2];
414 System.arraycopy(customOptions, 0, builder.customOptions, 0, customOptions.length);
415
416 if (existingIdx == -1) {
417 // Add a new option
418 builder.customOptions[customOptions.length] = new Object[] {key, value};
419 } else {
420 // Replace an existing option
421 builder.customOptions[existingIdx] = new Object[] {key, value};
422 }
423
424 return builder.build();
425 }
426
427 /**
428 * Get the value for a custom option or its inherent default.

Calls 4

toBuilderMethod · 0.95
buildMethod · 0.95
checkNotNullMethod · 0.80
equalsMethod · 0.45