Skip to content

Commit

Permalink
Suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephan202 authored and benhalasi committed Jan 5, 2023
1 parent b8d61a7 commit 7229ade
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,17 @@ V after(Map<K, V> map, T key) {
}
}

/**
* Prefer {@link Map#getOrDefault(Object, Object)} over more contrived alternatives. Note that
* this method may return null instead of throwing a NPE.
*/
/** Prefer {@link Map#getOrDefault(Object, Object)} over more contrived alternatives. */
// Note that
// XXX: `requireNonNullElse` throws an NPE if the second argument is `null`, while the alternative
// does not.
static final class MapGetOrDefault<K, V, T> {
@BeforeTemplate
V before(Map<K, V> map, T key, V defaultValue) {
return requireNonNullElse(map.get(key), defaultValue);
}

@AfterTemplate
@Nullable
V after(Map<K, V> map, T key, V defaultValue) {
return map.getOrDefault(key, defaultValue);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
final class MapRulesTest implements RefasterRuleCollectionTestCase {
@Override
public ImmutableSet<?> elidedTypesAndStaticImports() {
return ImmutableSet.of(HashMap.class, requireNonNullElse("foo", "bar"));
return ImmutableSet.of(HashMap.class, requireNonNullElse(null, null));
}

Map<RoundingMode, String> testCreateEnumMap() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
final class MapRulesTest implements RefasterRuleCollectionTestCase {
@Override
public ImmutableSet<?> elidedTypesAndStaticImports() {
return ImmutableSet.of(HashMap.class, requireNonNullElse("foo", "bar"));
return ImmutableSet.of(HashMap.class, requireNonNullElse(null, null));
}

Map<RoundingMode, String> testCreateEnumMap() {
Expand Down

0 comments on commit 7229ade

Please sign in to comment.