2003/10/31 09:50:10
[org.ibex.core.git] / src / org / xwt / util / Queue.java
index 7ed4850..a6f0a92 100644 (file)
@@ -38,7 +38,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;