NiceListIterator.java

jmud-0.11/src/util/nice/NiceListIterator.java · 1.0 KB

From the archive jmud-0_11.tgz

Download the archive   « Back to the archive contents

package util.nice;

import java.util.NoSuchElementException;

public class NiceListIterator implements NiceIterator {

  private NiceList     myList = null;
  private NiceListLink cursor = null;

  NiceListIterator(NiceList aList) {
    myList = aList;
    start();
  }

  public void start() {
    cursor = myList.getHead();
  }

  public boolean cont() {
    return cursor != null;
  }

  public void next() {
    cursor = cursor.getNext();
  }

  public Niceable getCurrent() {
    return cursor.getInfo();
  }

  public Niceable getNext() throws NoSuchElementException {
    if (!hasNext())
      throw new NoSuchElementException();
    
    return cursor.getNext().getInfo();
  }

  public boolean hasNext() {
    return (cont() && cursor.getNext() != null);
  }

  public void insertNext(Niceable info) {
    cursor.setNext(new NiceListLink(info, cursor.getNext()));
  }

  public void removeNext() throws NoSuchElementException {
    if (!hasNext())
      throw new NoSuchElementException();

    cursor.setNext(cursor.getNext().getNext());
  }
}

Site Stats

Snippets: 1791
Codebases: 571