2 // FORESTER -- software libraries and applications
3 // for evolutionary biology research and applications.
5 // Copyright (C) 2008-2009 Christian M. Zmasek
6 // Copyright (C) 2008-2009 Burnham Institute for Medical Research
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU Lesser General Public
11 // License as published by the Free Software Foundation; either
12 // version 2.1 of the License, or (at your option) any later version.
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 // Lesser General Public License for more details.
19 // You should have received a copy of the GNU Lesser General Public
20 // License along with this library; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 // Contact: phylosoft @ gmail . com
24 // WWW: https://sites.google.com/site/cmzmasek/home/software/forester
26 package org.forester.datastructures;
28 import java.util.LinkedList;
29 import java.util.NoSuchElementException;
32 * A simple Queue data structure. Created: 10/23/2005 by Christian M. Zmasek.
33 * Last modified: 10/23/2005 by Christian M. Zmasek.
35 * @author Christian M. Zmasek
43 private final LinkedList<Object> _data;
48 * This created a new, empty Queue object.
51 _data = new LinkedList<Object>();
55 * Removes all elements from this queue.
62 * Dequeues one element from this queue.
64 * @return the dequeued object
65 * @throws NoSuchElementException
66 * if this queue is empty
68 public Object dequeue() throws NoSuchElementException {
70 throw new NoSuchElementException( "Attempt to dequeue from an empty Queue." );
72 return getData().removeFirst();
78 * Adds Object element to thisqueue.
81 * the Object to be enqueued
83 public void enqueue( final Object element ) {
84 getData().add( element );
90 * Returns the LinkedList upon which this queue is based.
92 * @return the LinkedList upon which this queue is based
94 private LinkedList<Object> getData() {
99 * Returns whether or not this queue is empty.
101 * @return true if this queue is empty, false otherwise
103 public boolean isEmpty() {
104 return getData().isEmpty();
106 } // end of class Queue.