jmud-0.11/
jmud-0.11/bin/
jmud-0.11/doc/
jmud-0.11/rec/
jmud-0.11/rec/mun/
jmud-0.11/rec/mun/grecia/
jmud-0.11/rec/mun/gunnar/
jmud-0.11/rec/qua/
jmud-0.11/src/bool/
jmud-0.11/src/clone/
jmud-0.11/src/integer/
jmud-0.11/src/misc/
jmud-0.11/src/string/
jmud-0.11/src/util/bit/
jmud-0.11/src/util/color/
jmud-0.11/src/util/file/
jmud-0.11/src/util/jgp/adaptor/
jmud-0.11/src/util/jgp/algorithm/
jmud-0.11/src/util/jgp/container/
jmud-0.11/src/util/jgp/functor/
jmud-0.11/src/util/jgp/interfaces/
jmud-0.11/src/util/jgp/predicate/
jmud-0.11/src/util/log/
jmud-0.11/src/util/state/
jmud-0.11/trash/
package util.nice;

import java.util.NoSuchElementException;

public class NiceQueueIterator implements NiceIterator {

  private NiceQueue    myQueue = null;
  private NiceListLink cursor  = null;

  NiceQueueIterator(NiceQueue aQueue) {
    myQueue = aQueue;
    start();
  }

  public void start() {
    cursor = myQueue.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()));

    NiceListLink last = myQueue.getTail().getNext();

    if (last != null)
      myQueue.setTail(last);
  }

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

    NiceListLink next = cursor.getNext();

    if (myQueue.getTail() == next)
      myQueue.setTail(cursor);

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