2003/12/07 09:57:15
[org.ibex.core.git] / src / org / xwt / util / Queue.java
index f923db3..e2559e1 100644 (file)
@@ -1,4 +1,10 @@
-// Copyright 2002 Adam Megacz, see the COPYING file for licensing [GPL]
+// Copyright (C) 2003 Adam Megacz <adam@xwt.org> all rights reserved.
+//
+// You may modify, copy, and redistribute this code under the terms of
+// the GNU Library Public License version 2.1, with the exception of
+// the portion of clause 6a after the semicolon (aka the "obnoxious
+// relink clause")
+
 package org.xwt.util;
 
 /** A simple synchronized queue, implemented as an array */
@@ -38,7 +44,17 @@ public class Queue {
         for(int i=0; i<vec.length; i++) vec[i] = null;
     }
 
-    /** Add an element to the queue */
+    /** Add an element to the front of the queue */
+    public synchronized void prepend(Object o) {
+        if (size == vec.length) grow(vec.length * 2);
+        first--;
+        if (first < 0) first += vec.length;
+        vec[first] = o;
+        size++;
+        if (size == 1) notify();
+    }
+    
+    /** Add an element to the back of the queue */
     public synchronized void append(Object o) {
         if (size == vec.length) grow(vec.length * 2);
         if (first + size >= vec.length) vec[first + size - vec.length] = o;