CartesianProductIterable implements Iterable<Pair<T, T>> { public static <T> CartesianProductIterable<T> of(Iterable<T> source) { return new CartesianProductIterable<T>(source); } private  CartesianProductIterable(Iterable<T> source); static CartesianProductIterable<T> of(Iterable<T> source); @Override Iterator<Pair<T, T>> iterator();  }
@Test public void testIteratorTwo() { assertThat(CartesianProductIterable.of(limit(source, 2)), contains( Pair.of("A", "B") )); }
@Test public void testIteratorThree() { CartesianProductIterable<String> set = CartesianProductIterable.of(source.subList(0, 3)); assertThat(set, contains( Pair.of("A", "B"), Pair.of("A", "C"), Pair.of("B", "C") )); assertEquals(3, Iterables.size(set)); }
@SuppressWarnings("unchecked") @Test public void testIteratorFour() { assertThat(CartesianProductIterable.of(limit(source, 4)), contains( Pair.of("A", "B"), Pair.of("A", "C"), Pair.of("A", "D"), Pair.of("B", "C"), Pair.of("B", "D"), Pair.of("C", "D") )); }