예제 #1
0
 @Override
 public void forEachWithIndex(ObjectIntProcedure<? super T> objectIntProcedure) {
   objectIntProcedure.value(this.element1, 0);
   objectIntProcedure.value(this.element2, 1);
   objectIntProcedure.value(this.element3, 2);
   objectIntProcedure.value(this.element4, 3);
   objectIntProcedure.value(this.element5, 4);
   objectIntProcedure.value(this.element6, 5);
 }
예제 #2
0
  public static <T> void forEachWithIndex(
      List<T> iterable, int from, int to, ObjectIntProcedure<? super T> objectIntProcedure) {
    if (from < 0 || to < 0) {
      throw new IllegalArgumentException("Neither from nor to may be negative.");
    }

    Iterator<T> iterator = IteratorIterate.advanceIteratorTo(iterable.iterator(), from);
    int i = from;
    while (iterator.hasNext() && i <= to) {
      objectIntProcedure.value(iterator.next(), i++);
    }
  }