Package org.rsbot.script.internal.wrappers

Source Code of org.rsbot.script.internal.wrappers.Queue

package org.rsbot.script.internal.wrappers;

import org.rsbot.client.NodeSub;
import org.rsbot.client.NodeSubQueue;

@SuppressWarnings("unchecked")
public class Queue<N extends NodeSub> {
  private final NodeSubQueue nodeSubQueue;
  private NodeSub current;

  public Queue(final NodeSubQueue nodeSubQueue) {
    this.nodeSubQueue = nodeSubQueue;
  }

  public int size() {
    int size = 0;
    NodeSub node = nodeSubQueue.getTail().getPrevSub();
    while (node != nodeSubQueue.getTail()) {
      node = node.getPrevSub();
      size++;
    }
    return size;
  }

  public N getHead() {
    final NodeSub node = nodeSubQueue.getTail().getNextSub();
    if (node == nodeSubQueue.getTail()) {
      current = null;
      return null;
    }
    current = node.getNextSub();
    return (N) node;
  }

  public N getNext() {
    final NodeSub node = current;
    if (node == nodeSubQueue.getTail()) {
      current = null;
      return null;
    }
    current = node.getNextSub();
    return (N) node;
  }
}
TOP

Related Classes of org.rsbot.script.internal.wrappers.Queue

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.