aima.core.util.datastructure.FIFOQueue Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of aima-core Show documentation
Show all versions of aima-core Show documentation
AIMA-Java Core Algorithms from the book Artificial Intelligence a Modern Approach 3rd Ed.
package aima.core.util.datastructure;
import java.util.Collection;
import java.util.LinkedList;
/**
* Artificial Intelligence A Modern Approach (3rd Edition): pg 80.
*
* First-in, first-out or FIFO queue, which pops the oldest element of the
* queue;
*
* @author Ravi Mohan
* @author Ciaran O'Reilly
*/
public class FIFOQueue extends LinkedList implements Queue {
private static final long serialVersionUID = 1;
public FIFOQueue() {
super();
}
public FIFOQueue(Collection extends E> c) {
super(c);
}
//
// START-Queue
public boolean isEmpty() {
return 0 == size();
}
public E pop() {
return poll();
}
public void push(E element) {
this.addLast(element);
}
public Queue insert(E element) {
if (offer(element)) {
return this;
}
return null;
}
// END-Queue
//
}