コード例 #1
0
  @Test
  public void zip() {
    List<Object> nulls = Collections.nCopies(this.lazyIterable.size(), null);
    List<Object> nullsPlusOne = Collections.nCopies(this.lazyIterable.size() + 1, null);
    List<Object> nullsMinusOne = Collections.nCopies(this.lazyIterable.size() - 1, null);

    LazyIterable<Pair<Integer, Object>> pairs = this.lazyIterable.zip(nulls);
    Assert.assertEquals(
        this.lazyIterable.toSet(), pairs.collect(Functions.<Integer>firstOfPair()).toSet());
    Assert.assertEquals(nulls, pairs.collect(Functions.<Object>secondOfPair(), Lists.mutable.of()));

    LazyIterable<Pair<Integer, Object>> pairsPlusOne = this.lazyIterable.zip(nullsPlusOne);
    Assert.assertEquals(
        this.lazyIterable.toSet(), pairsPlusOne.collect(Functions.<Integer>firstOfPair()).toSet());
    Assert.assertEquals(
        nulls, pairsPlusOne.collect(Functions.<Object>secondOfPair(), Lists.mutable.of()));

    LazyIterable<Pair<Integer, Object>> pairsMinusOne = this.lazyIterable.zip(nullsMinusOne);
    Assert.assertEquals(this.lazyIterable.size() - 1, pairsMinusOne.size());
    Assert.assertTrue(
        this.lazyIterable.containsAllIterable(
            pairsMinusOne.collect(Functions.<Integer>firstOfPair())));

    Assert.assertEquals(
        this.lazyIterable.zip(nulls).toSet(),
        this.lazyIterable.zip(nulls, UnifiedSet.<Pair<Integer, Object>>newSet()));
  }
コード例 #2
0
 @Test
 public void keysWithMultiValuesView() {
   Multimap<Integer, String> multimap = this.newMultimapWithKeysValues(1, "1", 2, "2", 3, "3");
   Assert.assertEquals(
       Bags.mutable.of(1, 2, 3), multimap.keyMultiValuePairsView().collect(Pair::getOne).toBag());
   Assert.assertEquals(
       Bags.mutable.of("1", "2", "3"),
       multimap.keyMultiValuePairsView().flatCollect(Functions.secondOfPair()).toBag());
 }
コード例 #3
0
  @Test
  public void zipWithIndex() {
    LazyIterable<Pair<Integer, Integer>> pairs = this.lazyIterable.zipWithIndex();

    Assert.assertEquals(
        this.lazyIterable.toSet(), pairs.collect(Functions.<Integer>firstOfPair()).toSet());
    Assert.assertEquals(
        Interval.zeroTo(this.lazyIterable.size() - 1).toSet(),
        pairs.collect(Functions.<Integer>secondOfPair(), UnifiedSet.<Integer>newSet()));

    Assert.assertEquals(
        this.lazyIterable.zipWithIndex().toSet(),
        this.lazyIterable.zipWithIndex(UnifiedSet.<Pair<Integer, Integer>>newSet()));
  }