MCPcopy Create free account
hub / github.com/ReadyTalk/avian / ArrayListIterator

Class ArrayListIterator

classpath/java/util/Collections.java:462–511  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

460 }
461
462 static class ArrayListIterator<T> implements ListIterator<T> {
463 private final List<T> list;
464 private int toRemove = -1;
465 private int index;
466
467 public ArrayListIterator(List<T> list) {
468 this(list, 0);
469 }
470
471 public ArrayListIterator(List<T> list, int index) {
472 this.list = list;
473 this.index = index - 1;
474 }
475
476 public boolean hasPrevious() {
477 return index >= 0;
478 }
479
480 public T previous() {
481 if (hasPrevious()) {
482 toRemove = index;
483 return list.get(index--);
484 } else {
485 throw new NoSuchElementException();
486 }
487 }
488
489 public T next() {
490 if (hasNext()) {
491 toRemove = ++index;
492 return list.get(index);
493 } else {
494 throw new NoSuchElementException();
495 }
496 }
497
498 public boolean hasNext() {
499 return index + 1 < list.size();
500 }
501
502 public void remove() {
503 if (toRemove != -1) {
504 list.remove(toRemove);
505 index = toRemove - 1;
506 toRemove = -1;
507 } else {
508 throw new IllegalStateException();
509 }
510 }
511 }
512
513 public static <T> List<T> unmodifiableList(List<T> list) {
514 return new UnmodifiableList<T>(list);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected