@Test
 public void rejectToTarget() {
   ImmutableBag<String> strings = this.newBag();
   Assert.assertEquals(
       strings, strings.reject(Predicates.lessThan("0"), FastList.<String>newList()).toBag());
   Verify.assertEmpty(strings.reject(Predicates.greaterThan("0"), FastList.<String>newList()));
 }
 @Test
 public void injectInto() {
   ImmutableBag<Integer> integers = this.newBag().collect(Integer::valueOf);
   Integer result = integers.injectInto(0, AddFunction.INTEGER);
   Assert.assertEquals(
       FastList.newList(integers).injectInto(0, AddFunction.INTEGER_TO_INT), result.intValue());
   String result1 = this.newBag().injectInto("0", String::concat);
   Assert.assertEquals(FastList.newList(this.newBag()).injectInto("0", String::concat), result1);
 }
 @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 makeString() {
   Assert.assertEquals(
       FastList.newList(this.classUnderTest()).toString(),
       '[' + this.classUnderTest().makeString() + ']');
   Assert.assertEquals(
       FastList.newList(this.classUnderTest()).toString(),
       '[' + this.classUnderTest().makeString(", ") + ']');
   Assert.assertEquals(
       FastList.newList(this.classUnderTest()).toString(),
       this.classUnderTest().makeString("[", ", ", "]"));
 }
 public <V> MutableList<V> collect(BooleanToObjectFunction<? extends V> function) {
   FastList<V> target = FastList.newList(this.size);
   for (int i = 0; i < this.size; i++) {
     target.add(function.valueOf(this.items.get(i)));
   }
   return target;
 }
 @Benchmark
 public void gsc() {
   MutableList<Integer> result = FastList.newList();
   for (int i = 0; i < 1000; i++) {
     result.addAll(this.integersGSC);
   }
 }
 @Test
 public void rejectWith() {
   Assert.assertEquals(
       FastList.newListWith(3, 4, 5, 6, 7),
       this.lazyIterable.rejectWith(
           Predicates2.<Integer>lessThan(), 3, FastList.<Integer>newList()));
 }
 @Test
 public void selectWith() {
   Assert.assertEquals(
       FastList.newListWith(1, 2),
       this.lazyIterable.selectWith(
           Predicates2.<Integer>lessThan(), 3, FastList.<Integer>newList()));
 }
 @Test
 public void sumDouble() {
   ImmutableBag<Integer> integers = this.newBag().collect(Integer::valueOf);
   double result = integers.sumOfDouble(Integer::doubleValue);
   double expected = FastList.newList(integers).injectInto(0, AddFunction.INTEGER_TO_DOUBLE);
   Assert.assertEquals(expected, result, 0.001);
 }
 @Test
 public void testRejectWith() {
   Verify.assertSize(
       3,
       this.unmodifiableStackString.rejectWith(
           Predicates2.equal(), 3, FastList.<String>newList()));
 }
  @Override
  @Test
  public void retainAllFromEntrySet() {
    super.retainAllFromEntrySet();

    for (int i = 1; i < COLLISIONS.size(); i++) {
      MutableMap<Integer, Integer> map = this.mapWithCollisionsOfSize(i);

      Assert.assertFalse(
          map.entrySet()
              .retainAll(
                  FastList.newList(map.entrySet())
                      .with(ImmutableEntry.of(COLLISION_10, COLLISION_10))));

      Assert.assertTrue(map.entrySet().retainAll(this.mapWithCollisionsOfSize(i - 1).entrySet()));
      Assert.assertEquals(this.mapWithCollisionsOfSize(i - 1), map);
    }

    // simple map, collection to retain contains non-entry element
    MutableMap<Integer, String> map4 = this.newMapWithKeysValues(1, "One", 2, "Two");
    FastList<Object> toRetain =
        FastList.<Object>newListWith(
            ImmutableEntry.of(1, "One"), "explosion!", ImmutableEntry.of(2, "Two"));
    Assert.assertFalse(map4.entrySet().retainAll(toRetain));
  }
  @Test
  public void appendString() {
    Appendable builder1 = new StringBuilder();
    this.classUnderTest().appendString(builder1);
    Assert.assertEquals(
        FastList.newList(this.classUnderTest()).toString(), '[' + builder1.toString() + ']');

    Appendable builder2 = new StringBuilder();
    this.classUnderTest().appendString(builder2, ", ");
    Assert.assertEquals(
        FastList.newList(this.classUnderTest()).toString(), '[' + builder2.toString() + ']');

    Appendable builder3 = new StringBuilder();
    this.classUnderTest().appendString(builder3, "[", ", ", "]");
    Assert.assertEquals(FastList.newList(this.classUnderTest()).toString(), builder3.toString());
  }
 @Test
 public void injectInto() {
   ImmutableCollection<Integer> integers = this.classUnderTest();
   Integer result = integers.injectInto(0, AddFunction.INTEGER);
   Assert.assertEquals(
       FastList.newList(integers).injectInto(0, AddFunction.INTEGER_TO_INT), result.intValue());
 }
 @Test
 public void sumFloat() {
   ImmutableBag<Integer> integers = this.newBag().collect(Integer::valueOf);
   double result = integers.sumOfFloat(Integer::floatValue);
   float expected = FastList.newList(integers).injectInto(0, AddFunction.INTEGER_TO_FLOAT);
   Assert.assertEquals(expected, result, 0.001);
 }
 @Test
 public void sumLong() {
   ImmutableBag<Integer> integers = this.newBag().collect(Integer::valueOf);
   long result = integers.sumOfLong(Integer::longValue);
   long expected = FastList.newList(integers).injectInto(0, AddFunction.INTEGER_TO_LONG);
   Assert.assertEquals(expected, result);
 }
 @Test
 public void injectIntoLong() {
   ImmutableBag<Integer> integers = this.newBag().collect(Integer::valueOf);
   long result = integers.injectInto(0, AddFunction.INTEGER_TO_LONG);
   Assert.assertEquals(
       FastList.newList(integers).injectInto(0, AddFunction.INTEGER_TO_INT), result);
 }
 @Test
 public void testSelectWith() {
   Verify.assertSize(
       1,
       this.unmodifiableStackString.selectWith(
           Predicates2.equal(), "2", FastList.<String>newList()));
 }
  @Test
  public void appendString() {
    ImmutableBag<String> bag = this.newBag();

    Appendable builder = new StringBuilder();
    bag.appendString(builder);
    Assert.assertEquals(FastList.newList(bag).makeString(), builder.toString());
  }
 public <V> MutableList<V> collect(BooleanToObjectFunction<? extends V> function) {
   MutableList<V> results = FastList.newList(BooleanArrayList.this.size);
   BooleanIterator iterator = this.booleanIterator();
   while (iterator.hasNext()) {
     results.add(function.valueOf(iterator.next()));
   }
   return results;
 }
 @Test
 public void makeString() {
   ImmutableBag<String> bag = this.newBag();
   Assert.assertEquals(FastList.newList(bag).makeString(), bag.makeString());
   Assert.assertEquals(bag.toString(), '[' + bag.makeString() + ']');
   Assert.assertEquals(bag.toString(), '[' + bag.makeString(", ") + ']');
   Assert.assertEquals(bag.toString(), bag.makeString("[", ", ", "]"));
 }
  @Test
  public void testForEachImmutableList() {
    IntegerSum sum1 = new IntegerSum(0);
    ImmutableList<Integer> list1 =
        Lists.immutable.ofAll(ParallelIterateAcceptanceTest.createIntegerList(16));
    ParallelIterate.forEach(
        list1, new SumProcedure(sum1), new SumCombiner(sum1), 1, list1.size() / 2);
    Assert.assertEquals(16, sum1.getSum());

    IntegerSum sum2 = new IntegerSum(0);
    ImmutableList<Integer> list2 =
        Lists.immutable.ofAll(ParallelIterateAcceptanceTest.createIntegerList(7));
    ParallelIterate.forEach(list2, new SumProcedure(sum2), new SumCombiner(sum2));
    Assert.assertEquals(7, sum2.getSum());

    IntegerSum sum3 = new IntegerSum(0);
    ImmutableList<Integer> list3 =
        Lists.immutable.ofAll(ParallelIterateAcceptanceTest.createIntegerList(15));
    ParallelIterate.forEach(
        list3, new SumProcedure(sum3), new SumCombiner(sum3), 1, list3.size() / 2);
    Assert.assertEquals(15, sum3.getSum());

    IntegerSum sum4 = new IntegerSum(0);
    ImmutableList<Integer> list4 =
        Lists.immutable.ofAll(ParallelIterateAcceptanceTest.createIntegerList(35));
    ParallelIterate.forEach(list4, new SumProcedure(sum4), new SumCombiner(sum4));
    Assert.assertEquals(35, sum4.getSum());

    IntegerSum sum5 = new IntegerSum(0);
    ImmutableList<Integer> list5 = FastList.newList(list4).toImmutable();
    ParallelIterate.forEach(list5, new SumProcedure(sum5), new SumCombiner(sum5));
    Assert.assertEquals(35, sum5.getSum());

    IntegerSum sum6 = new IntegerSum(0);
    ImmutableList<Integer> list6 =
        Lists.immutable.ofAll(ParallelIterateAcceptanceTest.createIntegerList(40));
    ParallelIterate.forEach(
        list6, new SumProcedure(sum6), new SumCombiner(sum6), 1, list6.size() / 2);
    Assert.assertEquals(40, sum6.getSum());

    IntegerSum sum7 = new IntegerSum(0);
    ImmutableList<Integer> list7 = FastList.newList(list6).toImmutable();
    ParallelIterate.forEach(
        list7, new SumProcedure(sum7), new SumCombiner(sum7), 1, list6.size() / 2);
    Assert.assertEquals(40, sum7.getSum());
  }
 @Test
 public void select() {
   ImmutableBag<String> strings = this.newBag();
   Verify.assertContainsAll(
       FastList.newList(strings.select(Predicates.greaterThan("0"))), strings.toArray());
   Verify.assertIterableEmpty(strings.select(Predicates.lessThan("0")));
   Verify.assertIterableSize(strings.size() - 1, strings.select(Predicates.greaterThan("1")));
 }
 @Test
 public void toArray() {
   ImmutableCollection<Integer> integers = this.classUnderTest();
   MutableList<Integer> copy = FastList.newList(integers);
   Assert.assertArrayEquals(integers.toArray(), copy.toArray());
   Assert.assertArrayEquals(
       integers.toArray(new Integer[integers.size()]), copy.toArray(new Integer[integers.size()]));
 }
 @Test
 public void forEachOver100() {
   ArrayList<Integer> list = new ArrayList<Integer>(Interval.oneTo(101));
   Iterate.sortThis(list);
   FastList<Integer> result = FastList.newList(101);
   ArrayListIterate.forEach(list, CollectionAddProcedure.<Integer>on(result));
   Verify.assertListsEqual(list, result);
 }
 @Before
 public void setUp() {
   this.dropIterable = new DropIterable<>(Interval.oneTo(5), 2);
   this.emptyListDropIterable = new DropIterable<>(FastList.<Integer>newList(), 2);
   this.zeroCountDropIterable = new DropIterable<>(Interval.oneTo(5), 0);
   this.nearCountDropIterable = new DropIterable<>(Interval.oneTo(5), 4);
   this.sameCountDropIterable = new DropIterable<>(Interval.oneTo(5), 5);
   this.higherCountDropIterable = new DropIterable<>(Interval.oneTo(5), 6);
 }
 @Test
 public void toSortedList() {
   ImmutableCollection<Integer> integers = this.classUnderTest();
   MutableList<Integer> copy = FastList.newList(integers);
   MutableList<Integer> list = integers.toSortedList(Collections.<Integer>reverseOrder());
   Assert.assertEquals(copy.sortThis(Collections.<Integer>reverseOrder()), list);
   MutableList<Integer> list2 = integers.toSortedList();
   Assert.assertEquals(copy.sortThis(), list2);
 }
 @Test
 public void toSortedList() {
   ImmutableBag<String> strings = this.newBag();
   MutableList<String> copy = FastList.newList(strings);
   MutableList<String> list = strings.toSortedList(Collections.<String>reverseOrder());
   Assert.assertEquals(copy.sortThis(Collections.<String>reverseOrder()), list);
   MutableList<String> list2 = strings.toSortedList();
   Assert.assertEquals(copy.sortThis(), list2);
 }
 @Test
 public void equalsAndHashCode() {
   ImmutableBag<String> immutable = this.newBag();
   MutableBag<String> mutable = HashBag.newBag(immutable);
   Verify.assertEqualsAndHashCode(immutable, mutable);
   Assert.assertNotEquals(immutable, FastList.newList(mutable));
   Assert.assertEquals(this.newBag().toMapOfItemToCount().hashCode(), this.newBag().hashCode());
   Assert.assertNotEquals(immutable, mutable.with("5").without("1"));
 }
 @Test
 public void testSelect() {
   Assert.assertEquals(
       ArrayStack.newStackFromTopToBottom(2, 3),
       this.unmodifiableStack.select(Predicates.greaterThan(1)));
   Verify.assertSize(
       3,
       this.unmodifiableStackString.select(Predicates.alwaysTrue(), FastList.<String>newList()));
 }