Skip to content

Commit fa85f42

Browse files
kevinoconnor7Google Java Core Libraries
authored andcommitted
Override ImmutableMap#getOrDefault for GWT/J2CL
This accomplishes two things: Slight optimization as we don't need to check for key presence (ImmutableMap does not allow null values). This allows the Checker Framework stubs to be applied. RELNOTES=n/a PiperOrigin-RevId: 861755893
1 parent 70dc581 commit fa85f42

File tree

1 file changed

+11
-0
lines changed
  • guava-gwt/src-super/com/google/common/collect/super/com/google/common/collect

1 file changed

+11
-0
lines changed

guava-gwt/src-super/com/google/common/collect/super/com/google/common/collect/ImmutableMap.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,17 @@ public boolean containsValue(@Nullable Object value) {
435435
return values().contains(value);
436436
}
437437

438+
@Override
439+
public final @Nullable V getOrDefault(@Nullable Object key, @Nullable V defaultValue) {
440+
V result = get(key);
441+
// TODO(b/192579700): Use a ternary once it no longer confuses our nullness checker.
442+
if (result != null) {
443+
return result;
444+
} else {
445+
return defaultValue;
446+
}
447+
}
448+
438449
private transient @Nullable ImmutableSet<Entry<K, V>> cachedEntrySet = null;
439450

440451
@Override

0 commit comments

Comments
 (0)