Skip to content

Commit

Permalink
Suggestion: move
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephan202 committed Nov 8, 2022
1 parent b359bd5 commit e05e367
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,19 @@ static final class MapGetOrNull<K, V, T> {
}
}

/** Prefer {@link Map#isEmpty()} over more contrived alternatives. */
static final class MapIsEmpty<K, V> {
@BeforeTemplate
boolean before(Map<K, V> map) {
return Refaster.anyOf(map.keySet(), map.values(), map.entrySet()).isEmpty();
}

@AfterTemplate
boolean after(Map<K, V> map) {
return map.isEmpty();
}
}

/** Prefer {@link Map#size()} over more contrived alternatives. */
static final class MapSize<K, V> {
@BeforeTemplate
Expand Down Expand Up @@ -105,17 +118,4 @@ Stream<V> after(Map<K, V> map) {
return map.values().stream();
}
}

/** Prefer {@link Map#isEmpty()} over more contrived alternatives. */
static final class MapIsEmpty<K, V> {
@BeforeTemplate
boolean before(Map<K, V> map) {
return Refaster.anyOf(map.keySet(), map.values(), map.entrySet()).isEmpty();
}

@AfterTemplate
boolean after(Map<K, V> map) {
return map.isEmpty();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ String testMapGetOrNull() {
return ImmutableMap.of(1, "foo").getOrDefault("bar", null);
}

ImmutableSet<Boolean> testMapIsEmpty() {
return ImmutableSet.of(
ImmutableMap.of("foo", 1).keySet().isEmpty(),
ImmutableMap.of("bar", 2).values().isEmpty(),
ImmutableMap.of("baz", 3).entrySet().isEmpty());
}

ImmutableSet<Integer> testMapSize() {
return ImmutableSet.of(
ImmutableMap.of("foo", 1).keySet().size(),
Expand All @@ -44,11 +51,4 @@ Stream<String> testMapKeyStream() {
Stream<Integer> testMapValueStream() {
return ImmutableMap.of("foo", 1).entrySet().stream().map(Map.Entry::getValue);
}

ImmutableSet<Boolean> testMapIsEmpty() {
return ImmutableSet.of(
ImmutableMap.of("foo", 1).keySet().isEmpty(),
ImmutableMap.of("bar", 2).values().isEmpty(),
ImmutableMap.of("baz", 3).entrySet().isEmpty());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ String testMapGetOrNull() {
return ImmutableMap.of(1, "foo").get("bar");
}

ImmutableSet<Boolean> testMapIsEmpty() {
return ImmutableSet.of(
ImmutableMap.of("foo", 1).isEmpty(),
ImmutableMap.of("bar", 2).isEmpty(),
ImmutableMap.of("baz", 3).isEmpty());
}

ImmutableSet<Integer> testMapSize() {
return ImmutableSet.of(
ImmutableMap.of("foo", 1).size(),
Expand All @@ -45,11 +52,4 @@ Stream<String> testMapKeyStream() {
Stream<Integer> testMapValueStream() {
return ImmutableMap.of("foo", 1).values().stream();
}

ImmutableSet<Boolean> testMapIsEmpty() {
return ImmutableSet.of(
ImmutableMap.of("foo", 1).isEmpty(),
ImmutableMap.of("bar", 2).isEmpty(),
ImmutableMap.of("baz", 3).isEmpty());
}
}

0 comments on commit e05e367

Please sign in to comment.