MapRules
SUGGESTION
Simplification
Suppression
Disable all rules by adding
-XepOpt:Refaster:NamePattern=^(?!MapRules\$).*as compiler argument.
Table of contents
NewEnumMapClass
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("NewEnumMapClass")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!MapRules\$NewEnumMapClass).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
Map<RoundingMode, String> testNewEnumMapClass() {
- return new HashMap<>();
+ return new EnumMap<>(RoundingMode.class);
}MapGet
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("MapGet")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!MapRules\$MapGet).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
String testMapGet() {
- 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);
}MapKeySetStream
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("MapKeySetStream")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!MapRules\$MapKeySetStream).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
Stream<String> testMapKeySetStream() {
- return ImmutableMap.of("foo", 1).entrySet().stream().map(Map.Entry::getKey);
+ return ImmutableMap.of("foo", 1).keySet().stream();
}MapValuesStream
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("MapValuesStream")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!MapRules\$MapValuesStream).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
ImmutableSet<Stream<Integer>> testMapValuesStream() {
return ImmutableSet.of(
- ImmutableMap.of("foo", 1).keySet().stream().map(ImmutableMap.of("foo", 1)::get),
- ImmutableMap.of("bar", 2).entrySet().stream().map(Map.Entry::getValue));
+ ImmutableMap.of("foo", 1).values().stream(), ImmutableMap.of("bar", 2).values().stream());
}