001    /*
002     *  This file is part of the Jikes RVM project (http://jikesrvm.org).
003     *
004     *  This file is licensed to You under the Eclipse Public License (EPL);
005     *  You may not use this file except in compliance with the License. You
006     *  may obtain a copy of the License at
007     *
008     *      http://www.opensource.org/licenses/eclipse-1.0.php
009     *
010     *  See the COPYRIGHT.txt file distributed with this work for information
011     *  regarding copyright ownership.
012     */
013    package org.jikesrvm.compilers.opt.util;
014    
015    import java.util.Iterator;
016    
017    import org.jikesrvm.util.LinkedListRVM;
018    
019    public final class Queue<T> implements Iterable<T> {
020      private final LinkedListRVM<T> elements = new LinkedListRVM<T>();
021    
022      public Queue() { }
023    
024      public Queue(T e) {
025        elements.add(e);
026      }
027    
028      public T insert(T e) {
029        elements.add(e);            // Insert at tail
030        return e;
031      }
032    
033      public T remove() {
034        return elements.remove(0);  // Remove from head
035      }
036    
037      public boolean isEmpty() {
038        return elements.isEmpty();
039      }
040    
041      @Override
042      public Iterator<T> iterator() {
043        return elements.iterator();
044      }
045    }