MapRules
SUGGESTION
Simplification
Suppression
Disable all rules by adding
-XepOpt:Refaster:NamePattern=^(?!MapRules\$).*
as compiler argument.
Table of contents
CreateEnumMap
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("CreateEnumMap")
to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!MapRules\$CreateEnumMap).*
as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
Map<RoundingMode, String> testCreateEnumMap() {
- return new HashMap<>();
+ return new EnumMap<>(RoundingMode.class);
}
MapGetOrNull
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("MapGetOrNull")
to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!MapRules\$MapGetOrNull).*
as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
String testMapGetOrNull() {
- return ImmutableMap.of(1, "foo").getOrDefault("bar", null);
+ return ImmutableMap.of(1, "foo").get("bar");
}
MapGetOrDefault
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("MapGetOrDefault")
to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!MapRules\$MapGetOrDefault).*
as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
String testMapGetOrDefault() {
- return requireNonNullElse(ImmutableMap.of(1, "foo").get("bar"), "baz");
+ return ImmutableMap.of(1, "foo").getOrDefault("bar", "baz");
}
MapIsEmpty
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("MapIsEmpty")
to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!MapRules\$MapIsEmpty).*
as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
ImmutableSet<Boolean> testMapIsEmpty() {
return ImmutableSet.of(
- ImmutableMap.of("foo", 1).keySet().isEmpty(),
- ImmutableMap.of("bar", 2).values().isEmpty(),
- ImmutableMap.of("baz", 3).entrySet().isEmpty());
+ ImmutableMap.of("foo", 1).isEmpty(),
+ ImmutableMap.of("bar", 2).isEmpty(),
+ ImmutableMap.of("baz", 3).isEmpty());
}
MapSize
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("MapSize")
to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!MapRules\$MapSize).*
as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
ImmutableSet<Integer> testMapSize() {
return ImmutableSet.of(
- ImmutableMap.of("foo", 1).keySet().size(),
- ImmutableMap.of("bar", 2).values().size(),
- ImmutableMap.of("baz", 3).entrySet().size());
+ ImmutableMap.of("foo", 1).size(),
+ ImmutableMap.of("bar", 2).size(),
+ ImmutableMap.of("baz", 3).size());
}
MapContainsKey
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("MapContainsKey")
to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!MapRules\$MapContainsKey).*
as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
boolean testMapContainsKey() {
- return ImmutableMap.of("foo", 1).keySet().contains("bar");
+ return ImmutableMap.of("foo", 1).containsKey("bar");
}
MapContainsValue
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("MapContainsValue")
to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!MapRules\$MapContainsValue).*
as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
boolean testMapContainsValue() {
- return ImmutableMap.of("foo", 1).values().contains(2);
+ return ImmutableMap.of("foo", 1).containsValue(2);
}
MapKeyStream
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("MapKeyStream")
to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!MapRules\$MapKeyStream).*
as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
Stream<String> testMapKeyStream() {
- return ImmutableMap.of("foo", 1).entrySet().stream().map(Map.Entry::getKey);
+ return ImmutableMap.of("foo", 1).keySet().stream();
}
MapValueStream
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("MapValueStream")
to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!MapRules\$MapValueStream).*
as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
Stream<Integer> testMapValueStream() {
- return ImmutableMap.of("foo", 1).entrySet().stream().map(Map.Entry::getValue);
+ return ImmutableMap.of("foo", 1).values().stream();
}