FIFO Queue
package dataStructures;
public interface Queue {
public void enqueue(Object value);
public Object dequeue() throws EmptyQueueException;
public void clear();
public int size();
public boolean isEmpty();
}
package dataStructures;
public class ListFifoQueue implements Queue {
private final List _list;
public ListFifoQueue(List list) {
assert list != null : "list can’t be null";
_list = list;
}
public ListFifoQueue() {
this(new LinkedList());
}
public void enqueue(Object value) {
_list.add(value);
}
public Object dequeue() throws EmptyQueueException {
if (isEmpty()) {
throw new EmptyQueueException();
}
return _list.delete(0);
}
public void clear() {
_list.clear();
}
public int size() {
return _list.size();
}
public boolean isEmpty() {
return _list.isEmpty();
}
}