@Test
 public void updateValue() {
   MutableMapIterable<Integer, Integer> map = this.newMap();
   Iterate.forEach(
       Interval.oneTo(1000), each -> map.updateValue(each % 10, () -> 0, integer -> integer + 1));
   Assert.assertEquals(Interval.zeroTo(9).toSet(), map.keySet());
   Assert.assertEquals(
       FastList.newList(Collections.nCopies(10, 100)), FastList.newList(map.values()));
 }
 @Test
 public void updateValue_collisions() {
   MutableMapIterable<Integer, Integer> map = this.newMap();
   MutableList<Integer> list = Interval.oneTo(2000).toList();
   Collections.shuffle(list);
   Iterate.forEach(list, each -> map.updateValue(each % 1000, () -> 0, integer -> integer + 1));
   Assert.assertEquals(Interval.zeroTo(999).toSet(), map.keySet());
   Assert.assertEquals(
       HashBag.newBag(map.values()).toStringOfItemToCount(),
       FastList.newList(Collections.nCopies(1000, 2)),
       FastList.newList(map.values()));
 }
  @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()));
  }
Exemplo n.º 4
0
  @Test
  public void zipWithIndex() {
    ImmutableBag<String> immutableBag = this.newBag();
    ImmutableSet<Pair<String, Integer>> pairs = immutableBag.zipWithIndex();

    Assert.assertEquals(
        immutableBag,
        pairs.collect((Function<Pair<String, ?>, String>) Pair::getOne, HashBag.<String>newBag()));
    Assert.assertEquals(
        Interval.zeroTo(immutableBag.size() - 1).toSet(),
        pairs.collect((Function<Pair<?, Integer>, Integer>) Pair::getTwo));

    Assert.assertEquals(
        immutableBag.zipWithIndex(),
        immutableBag.zipWithIndex(UnifiedSet.<Pair<String, Integer>>newSet()));
  }
  @Test
  public void zipWithIndex() {
    MutableMap<String, String> map = this.classUnderTest();

    RichIterable<Pair<String, Integer>> pairs = map.zipWithIndex();

    Assert.assertEquals(
        map.toSet(), pairs.collect((Function<Pair<String, ?>, String>) Pair::getOne).toSet());
    if (map.notEmpty()) {
      Assert.assertEquals(
          Interval.zeroTo(map.size() - 1).toSet(),
          pairs.collect(
              (Function<Pair<?, Integer>, Integer>) Pair::getTwo, UnifiedSet.<Integer>newSet()));
    }

    Assert.assertEquals(
        map.zipWithIndex().toSet(), map.zipWithIndex(UnifiedSet.<Pair<String, Integer>>newSet()));
  }
 @Test
 public void updateValueWith() {
   MutableMapIterable<Integer, Integer> map = this.newMap();
   Iterate.forEach(
       Interval.oneTo(1000),
       each ->
           map.updateValueWith(
               each % 10,
               () -> 0,
               (integer, parameter) -> {
                 Assert.assertEquals("test", parameter);
                 return integer + 1;
               },
               "test"));
   Assert.assertEquals(Interval.zeroTo(9).toSet(), map.keySet());
   Assert.assertEquals(
       FastList.newList(Collections.nCopies(10, 100)), FastList.newList(map.values()));
 }
  @Test
  public void zipWithIndex() {
    ImmutableMap<String, String> map =
        this.newMapWithKeysValues("1", "One", "2", "Two", "3", "Three", "4", "Four");

    RichIterable<Pair<String, Integer>> pairs = map.zipWithIndex();

    Assert.assertEquals(
        map.toSet(), pairs.collect((Function<Pair<String, ?>, String>) Pair::getOne).toSet());
    if (map.notEmpty()) {
      Assert.assertEquals(
          Interval.zeroTo(map.size() - 1).toSet(),
          pairs.collect(
              (Function<Pair<?, Integer>, Integer>) Pair::getTwo, UnifiedSet.<Integer>newSet()));
    }

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