Skip to content

Commit

Permalink
Add supplier variant for Observation.Context.getOrDefault()
Browse files Browse the repository at this point in the history
  • Loading branch information
izeye committed Mar 22, 2023
1 parent dfa43ef commit 0602b39
Showing 1 changed file with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1294,6 +1294,18 @@ interface ContextView {
*/
<T> T getOrDefault(Object key, T defaultObject);

/**
* Returns an element or default if not present.
* @param key key
* @param defaultObjectSupplier supplier for default object to return
* @param <T> value type
* @return object or default if not present
*/
default <T> T getOrDefault(Object key, Supplier<T> defaultObjectSupplier) {
T value = get(key);
return value != null ? value : defaultObjectSupplier.get();
}

/**
* Returns low cardinality key values.
* @return low cardinality key values
Expand Down

0 comments on commit 0602b39

Please sign in to comment.