Skip to content

Commit

Permalink
Adding listOf templates for up to 5 items
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitor Mussatto committed Feb 22, 2022
1 parent 58af714 commit 0b6b9f4
Show file tree
Hide file tree
Showing 10 changed files with 263 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -402,5 +402,4 @@ Optional<T> after(Queue<T> queue) {

// XXX: collection.stream().noneMatch(e -> e.equals(other))
// ^ This is !collection.contains(other). Do we already rewrite variations on this?

}
Original file line number Diff line number Diff line change
Expand Up @@ -211,4 +211,52 @@ ImmutableCollection<T> after(T item) {
return ImmutableList.of(item);
}
}

static final class ImmutableListOf2<T> {
@BeforeTemplate
List<T> before(T item, T item2) {
return List.of(item, item2);
}

@AfterTemplate
ImmutableCollection<T> after(T item, T item2) {
return ImmutableList.of(item, item2);
}
}

static final class ImmutableListOf3<T> {
@BeforeTemplate
List<T> before(T i1, T i2, T i3) {
return List.of(i1, i2, i3);
}

@AfterTemplate
ImmutableCollection<T> after(T i1, T i2, T i3) {
return ImmutableList.of(i1, i2, i3);
}
}

static final class ImmutableListOf4<T> {
@BeforeTemplate
List<T> before(T i1, T i2, T i3, T i4) {
return List.of(i1, i2, i3, i4);
}

@AfterTemplate
ImmutableCollection<T> after(T i1, T i2, T i3, T i4) {
return ImmutableList.of(i1, i2, i3, i4);
}
}

static final class ImmutableListOf5<T> {
@BeforeTemplate
List<T> before(T i1, T i2, T i3, T i4, T i5) {
return List.of(i1, i2, i3, i4, i5);
}

@AfterTemplate
ImmutableCollection<T> after(T i1, T i2, T i3, T i4, T i5) {
return ImmutableList.of(i1, i2, i3, i4, i5);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,65 @@ ImmutableMap<K, V> after() {
}
}

static final class ImmutableMapOf1<K, V> {
@BeforeTemplate
Map<K, V> before(K k1, V v1) {
return Map.of(k1, v1);
}

@AfterTemplate
ImmutableMap<K, V> after(K k1, V v1) {
return ImmutableMap.of(k1, v1);
}
}

static final class ImmutableMapOf2<K, V> {
@BeforeTemplate
Map<K, V> before(K k1, V v1, K k2, V v2) {
return Map.of(k1, v1, k2, v2);
}

@AfterTemplate
ImmutableMap<K, V> after(K k1, V v1, K k2, V v2) {
return ImmutableMap.of(k1, v1, k2, v2);
}
}

static final class ImmutableMapOf3<K, V> {
@BeforeTemplate
Map<K, V> before(K k1, V v1, K k2, V v2, K k3, V v3) {
return Map.of(k1, v1, k2, v2, k3, v3);
}

@AfterTemplate
ImmutableMap<K, V> after(K k1, V v1, K k2, V v2, K k3, V v3) {
return ImmutableMap.of(k1, v1, k2, v2, k3, v3);
}
}

static final class ImmutableMapOf4<K, V> {
@BeforeTemplate
Map<K, V> before(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4) {
return Map.of(k1, v1, k2, v2, k3, v3, k4, v4);
}

@AfterTemplate
ImmutableMap<K, V> after(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4) {
return ImmutableMap.of(k1, v1, k2, v2, k3, v3, k4, v4);
}
}

static final class ImmutableMapOf5<K, V> {
@BeforeTemplate
Map<K, V> before(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5) {
return Map.of(k1, v1, k2, v2, k3, v3, k4, v4, k5, v5);
}

@AfterTemplate
ImmutableMap<K, V> after(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5) {
return ImmutableMap.of(k1, v1, k2, v2, k3, v3, k4, v4, k5, v5);
}
}
// XXX: Add a template for this:
// Maps.transformValues(streamOfEntries.collect(groupBy(fun)), ImmutableMap::copyOf)
// ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,4 +163,64 @@ ImmutableSet<T> after() {
return ImmutableSet.of();
}
}

static final class ImmutableSetOfItems1<T> {
@BeforeTemplate
Set<T> before(T e1) {
return Set.of(e1);
}

@AfterTemplate
ImmutableSet<T> after(T e1) {
return ImmutableSet.of(e1);
}
}

static final class ImmutableSetOfItems2<T> {
@BeforeTemplate
Set<T> before(T e1, T e2) {
return Set.of(e1, e2);
}

@AfterTemplate
ImmutableSet<T> after(T e1, T e2) {
return ImmutableSet.of(e1, e2);
}
}

static final class ImmutableSetOfItems3<T> {
@BeforeTemplate
Set<T> before(T e1, T e2, T e3) {
return Set.of(e1, e2, e3);
}

@AfterTemplate
ImmutableSet<T> after(T e1, T e2, T e3) {
return ImmutableSet.of(e1, e2, e3);
}
}

static final class ImmutableSetOfItems4<T> {
@BeforeTemplate
Set<T> before(T e1, T e2, T e3, T e4) {
return Set.of(e1, e2, e3, e4);
}

@AfterTemplate
ImmutableSet<T> after(T e1, T e2, T e3, T e4) {
return ImmutableSet.of(e1, e2, e3, e4);
}
}

static final class ImmutableSetOfItems5<T> {
@BeforeTemplate
Set<T> before(T e1, T e2, T e3, T e4, T e5) {
return Set.of(e1, e2, e3, e4, e5);
}

@AfterTemplate
ImmutableSet<T> after(T e1, T e2, T e3, T e4, T e5) {
return ImmutableSet.of(e1, e2, e3, e4, e5);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,23 @@ List<String> testImmutableListOfTyped() {
return Collections.emptyList();
}

ImmutableSet<Collection<String>> testImmutableList1() {
return ImmutableSet.of(List.of("1"));
Collection<String> testImmutableListOf1() {
return List.of("1");
}

Collection<String> testImmutableListOf2() {
return List.of("1", "2");
}

Collection<String> testImmutableListOf3() {
return List.of("1", "2", "3");
}

Collection<String> testImmutableListOf4() {
return List.of("1", "2", "3", "4");
}

Collection<String> testImmutableListOf5() {
return List.of("1", "2", "3", "4", "5");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,23 @@ List<String> testImmutableListOfTyped() {
return ImmutableList.of();
}

ImmutableSet<Collection<String>> testImmutableList1() {
return ImmutableSet.of(ImmutableList.of("1"));
Collection<String> testImmutableListOf1() {
return ImmutableList.of("1");
}

Collection<String> testImmutableListOf2() {
return ImmutableList.of("1", "2");
}

Collection<String> testImmutableListOf3() {
return ImmutableList.of("1", "2", "3");
}

Collection<String> testImmutableListOf4() {
return ImmutableList.of("1", "2", "3", "4");
}

Collection<String> testImmutableListOf5() {
return ImmutableList.of("1", "2", "3", "4", "5");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,17 @@ ImmutableMap<String, Integer> testImmutableMapCopyOfImmutableMap() {
return ImmutableMap.copyOf(ImmutableMap.of("foo", 1));
}

Map<?, ?> testImmutableMapOf() {
Map<String, String> testImmutableMapOfTyped() {
return Collections.emptyMap();
}

Map<String, String> testImmutableMapOfTyped() {
return Collections.emptyMap();
ImmutableSet<Map<?, ?>> testImmutableMapOfN() {
return ImmutableSet.of(
Collections.emptyMap(),
Map.of("k1", "v1"),
Map.of("k1", "v1", "k2", "v2"),
Map.of("k1", "v1", "k2", "v2", "k3", "v3"),
Map.of("k1", "v1", "k2", "v2", "k3", "v3", "k4", "v4"),
Map.of("k1", "v1", "k2", "v2", "k3", "v3", "k4", "v4", "k5", "v5"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,17 @@ ImmutableMap<String, Integer> testImmutableMapCopyOfImmutableMap() {
return ImmutableMap.of("foo", 1);
}

Map<?, ?> testImmutableMapOf() {
Map<String, String> testImmutableMapOfTyped() {
return ImmutableMap.of();
}

Map<String, String> testImmutableMapOfTyped() {
return ImmutableMap.of();
ImmutableSet<Map<?, ?>> testImmutableMapOfN() {
return ImmutableSet.of(
ImmutableMap.of(),
ImmutableMap.of("k1", "v1"),
ImmutableMap.of("k1", "v1", "k2", "v2"),
ImmutableMap.of("k1", "v1", "k2", "v2", "k3", "v3"),
ImmutableMap.of("k1", "v1", "k2", "v2", "k3", "v3", "k4", "v4"),
ImmutableMap.of("k1", "v1", "k2", "v2", "k3", "v3", "k4", "v4", "k5", "v5"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.google.common.collect.Sets;
import com.google.common.collect.Streams;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Set;
import java.util.stream.Stream;
Expand Down Expand Up @@ -74,4 +75,24 @@ Set<?> testImmutableSetOf() {
Set<String> testImmutableSetOfTyped() {
return Collections.emptySet();
}

Collection<String> testImmutableSetOfItems1() {
return Set.of("1");
}

Collection<String> testImmutableSetOfItems2() {
return Set.of("1", "2");
}

Collection<String> testImmutableSetOfItems3() {
return Set.of("1", "2", "3");
}

Collection<String> testImmutableSetOfItems4() {
return Set.of("1", "2", "3", "4");
}

Collection<String> testImmutableSetOfItems5() {
return Set.of("1", "2", "3", "4", "5");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.google.common.collect.Sets;
import com.google.common.collect.Streams;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Set;
import java.util.stream.Stream;
Expand Down Expand Up @@ -73,4 +74,24 @@ Set<?> testImmutableSetOf() {
Set<String> testImmutableSetOfTyped() {
return ImmutableSet.of();
}

Collection<String> testImmutableSetOfItems1() {
return ImmutableSet.of("1");
}

Collection<String> testImmutableSetOfItems2() {
return ImmutableSet.of("1", "2");
}

Collection<String> testImmutableSetOfItems3() {
return ImmutableSet.of("1", "2", "3");
}

Collection<String> testImmutableSetOfItems4() {
return ImmutableSet.of("1", "2", "3", "4");
}

Collection<String> testImmutableSetOfItems5() {
return ImmutableSet.of("1", "2", "3", "4", "5");
}
}

0 comments on commit 0b6b9f4

Please sign in to comment.