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

Commit

Permalink
remove default key value
Browse files Browse the repository at this point in the history
  • Loading branch information
mutianf committed Aug 4, 2021
1 parent 73bc7b1 commit ccddcdc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 17 deletions.
21 changes: 5 additions & 16 deletions gax/src/main/java/com/google/api/gax/rpc/ApiCallContext.java
Expand Up @@ -248,37 +248,26 @@ public interface ApiCallContext extends RetryingContext {
* Return a new ApiCallContext with additional option merged into the present instance. Any
* existing value of the key is overwritten.
*/
@BetaApi(
"The surface for api call context options is not stable yet and may change in the future.")
@BetaApi("The surface for call context options is not stable yet and may change in the future.")
<T> ApiCallContext withOption(Key<T> key, T value);

/** Return the api call context option set for this context. */
@SuppressWarnings("unchecked")
@BetaApi(
"The surface for api call context options is not stable yet and may change in the future.")
@BetaApi("The surface for call context options is not stable yet and may change in the future.")
<T> T getOption(Key<T> key);

/** Key for api call context options key-value pair. */
final class Key<T> {
private final String name;
private final T defaultValue;

private Key(String name, T defaultValue) {
private Key(String name) {
this.name = name;
this.defaultValue = defaultValue;
}

/**
* Factory method for creating instances of {@link Key}. The default value of the key is null.
*/
/** Factory method for creating instances of {@link Key}. */
public static <T> Key<T> create(String name) {
Preconditions.checkNotNull(name, "Key name cannot be null.");
return new Key<>(name, null);
}

/** Returns the user supplied default value of the key. */
public T getDefault() {
return defaultValue;
return new Key<>(name);
}
}
}
Expand Up @@ -76,7 +76,7 @@ public <T> ApiCallContextOptions withOption(Key<T> key, T value) {
public <T> T getOption(Key<T> key) {
Preconditions.checkNotNull(key);
if (!options.containsKey(key)) {
return key.getDefault();
return null;
}
return (T) options.get(key);
}
Expand Down

0 comments on commit ccddcdc

Please sign in to comment.