/*
 * 2006 Utah High School Programming Contest, University of Utah
 * Take-Home Problem
 *
 * UpdateQueue.java
 *
 * This file contains the implementation of the UpdateQueue class.
 */

import java.util.LinkedList;
import java.util.NoSuchElementException;

/**
 * An <code>UpdateQueue</code> is a straightforward container of
 * <code>Update</code> objects.  Updates are stored and retrieved in first-in,
 * first-out order.
 */
public class UpdateQueue {
    /**
     * The list of <code>Update</code> objects.
     */
    private final LinkedList queue;

    /*************************************************************************/

    /**
     * Creates an empty <code>UpdateQueue</code>.
     */
    public UpdateQueue() {
        queue = new LinkedList();
    }

    /**
     * Determines if the queue is empty.
     *
     * @return  true if the queue is empty, and false otherwise
     */
    public boolean isEmpty() {
        return queue.size() == 0;
    }

    /**
     * Adds an <code>Update</code> to the end of the queue.
     *
     * @param u  the <code>Update</code> to be enqueued
     */
    public void add(Update u) {
        queue.addLast(u);
    }

    /**
     * Removes the <code>Update</code> that is at the head of the queue.
     *
     * @return  the <code>Update</code> that was removed from the queue
     * @throws  NoSuchElementException if the queue is empty
     */
    public Update take() throws NoSuchElementException {
        return (Update) queue.removeFirst();
    }
}

// End of file.

