@Test
 public void testForEachWithIndexToArrayUsingArrayList() {
   Integer[] array = new Integer[200];
   List<Integer> list = new ArrayList<>(Interval.oneTo(200));
   Assert.assertTrue(ArrayIterate.allSatisfy(array, Predicates.isNull()));
   ParallelIterate.forEachWithIndex(list, (each, index) -> array[index] = each, 10, 10);
   Assert.assertArrayEquals(array, list.toArray(new Integer[] {}));
 }
 @Test
 public void testForEachWithIndexToArrayUsingFixedArrayList() {
   Integer[] array = new Integer[10];
   List<Integer> list = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
   Assert.assertTrue(ArrayIterate.allSatisfy(array, Predicates.isNull()));
   ParallelIterate.forEachWithIndex(list, (each, index) -> array[index] = each, 1, 2);
   Assert.assertArrayEquals(array, list.toArray(new Integer[list.size()]));
 }
 @Test
 public void valuesCollection_toArray_withLargeTarget() {
   MutableMap<Integer, String> map = this.newMapWithKeysValues(1, "One", 2, "Two");
   String[] target = new String[3];
   target[2] = "yow!";
   String[] values = map.values().toArray(target);
   ArrayIterate.sort(
       values, values.length, Comparators.safeNullsHigh(Comparators.<String>naturalOrder()));
   Assert.assertArrayEquals(new String[] {"One", "Two", null}, values);
 }
 @Test
 public void keySet_ToArray_withLargeTarget() {
   MutableMap<Integer, String> map =
       this.newMapWithKeysValues(1, "One", 2, "Two", 3, "Three", 4, "Four");
   Integer[] target = new Integer[6]; // deliberately large to force the extra to be set to null
   target[4] = 42;
   target[5] = 42;
   Integer[] result = map.keySet().toArray(target);
   ArrayIterate.sort(
       result, result.length, Comparators.safeNullsHigh(Comparators.<Integer>naturalOrder()));
   Assert.assertArrayEquals(new Integer[] {1, 2, 3, 4, 42, null}, result);
 }
  @Override
  @Test
  public void toArray() {
    super.toArray();

    int size = COLLISIONS.size();
    for (int i = 1; i < size; i++) {
      MutableSet<Integer> set =
          UnifiedSetWithHashingStrategy.newSet(INTEGER_HASHING_STRATEGY, SIZE)
              .withAll(COLLISIONS.subList(0, i));
      Object[] objects = set.toArray();
      Assert.assertEquals(set, UnifiedSet.newSetWith(objects));
    }

    MutableSet<Integer> deepChain =
        UnifiedSetWithHashingStrategy.newSetWith(
            INTEGER_HASHING_STRATEGY,
            COLLISION_1,
            COLLISION_2,
            COLLISION_3,
            COLLISION_4,
            COLLISION_5,
            COLLISION_6);
    Assert.assertArrayEquals(
        new Integer[] {
          COLLISION_1, COLLISION_2, COLLISION_3, COLLISION_4, COLLISION_5, COLLISION_6
        },
        deepChain.toArray());

    MutableSet<Integer> minimumChain =
        UnifiedSetWithHashingStrategy.newSetWith(
            INTEGER_HASHING_STRATEGY, COLLISION_1, COLLISION_2);
    minimumChain.remove(COLLISION_2);
    Assert.assertArrayEquals(new Integer[] {COLLISION_1}, minimumChain.toArray());

    MutableSet<Integer> set =
        UnifiedSetWithHashingStrategy.newSetWith(
            INTEGER_HASHING_STRATEGY, COLLISION_1, COLLISION_2, COLLISION_3, COLLISION_4);
    Integer[] target = {
      Integer.valueOf(1),
      Integer.valueOf(1),
      Integer.valueOf(1),
      Integer.valueOf(1),
      Integer.valueOf(1),
      Integer.valueOf(1)
    };
    Integer[] actual = set.toArray(target);
    ArrayIterate.sort(actual, actual.length, Comparators.safeNullsHigh(Integer::compareTo));
    Assert.assertArrayEquals(
        new Integer[] {COLLISION_1, 1, COLLISION_2, COLLISION_3, COLLISION_4, null}, actual);
  }
  @Test
  public void keySet_copyKeys() {
    // a map with a null key
    MutableMap<Integer, Integer> map1 = this.newMapWithKeyValue(null, 0);
    Assert.assertArrayEquals(new Object[] {null}, map1.keySet().toArray());

    // a map with a chain containing empty slots
    MutableMap<Integer, Integer> map2 = this.mapWithCollisionsOfSize(5);
    Assert.assertArrayEquals(new Object[] {0, 17, 34, 51, 68}, map2.keySet().toArray());

    // a map with a chain containing empty slots and null key
    MutableMap<Integer, Integer> map3 = this.mapWithCollisionsOfSize(5);
    map3.put(null, 42);
    Integer[] array = map3.keySet().toArray(new Integer[map3.size()]);
    ArrayIterate.sort(
        array, array.length, Comparators.safeNullsHigh(Comparators.<Integer>naturalOrder()));
    Assert.assertArrayEquals(new Object[] {0, 17, 34, 51, 68, null}, array);
  }
 public boolean containsAllArguments(Object... elements) {
   return ArrayIterate.allSatisfyWith(elements, Predicates2.in(), this);
 }
 @Override
 public <V extends Comparable<? super V>> T maxBy(Function<? super T, ? extends V> function) {
   return ArrayIterate.maxBy(this.items, function);
 }
 public void forEach(Procedure<? super T> procedure) {
   ArrayIterate.forEach(this.items, procedure);
 }
 @Override
 public boolean isEmpty() {
   return ArrayIterate.isEmpty(this.items);
 }
 @Override
 public <IV> IV injectInto(
     IV injectedValue, Function2<? super IV, ? super T, ? extends IV> function) {
   return ArrayIterate.injectInto(injectedValue, this.items, function);
 }
 @Override
 public boolean noneSatisfy(Predicate<? super T> predicate) {
   return ArrayIterate.noneSatisfy(this.items, predicate);
 }
 @Override
 public int count(Predicate<? super T> predicate) {
   return ArrayIterate.count(this.items, predicate);
 }
 @Override
 public T detect(Predicate<? super T> predicate) {
   return ArrayIterate.detect(this.items, predicate);
 }
 @Override
 public void forEachWithIndex(ObjectIntProcedure<? super T> objectIntProcedure) {
   ArrayIterate.forEachWithIndex(this.items, objectIntProcedure);
 }
 @Override
 public int indexOf(Object item) {
   return ArrayIterate.indexOf(this.items, item);
 }
 @Override
 public T getLast() {
   return ArrayIterate.getLast(this.items);
 }