Hi Berin,

Berin Loritsch wrote:

> The FixedSizeQueue needs to be changed to use the FixedSizeBuffer, but
> I don't think it would be worth it to make VariableSizeBuffer extend
> FixedSizeBuffer.

        FixedSizeQueue patch attached.

        Cheers,

        Marcus

-- 
        .....
     ,,$$$$$$$$$,      Marcus Crafter
    ;$'      '$$$$:    Computer Systems Engineer
    $:         $$$$:   ManageSoft GmbH
     $       o_)$$$:   82-84 Mainzer Landstrasse
     ;$,    _/\ &&:'   60327 Frankfurt Germany
       '     /( &&&
           \_&&&&'
          &&&&.
    &&&&&&&:
Index: FixedSizeQueue.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/event/FixedSizeQueue.java,v
retrieving revision 1.3
diff -u -r1.3 FixedSizeQueue.java
--- FixedSizeQueue.java 4 Feb 2002 18:21:50 -0000       1.3
+++ FixedSizeQueue.java 7 Mar 2002 16:57:30 -0000
@@ -7,48 +7,38 @@
  */
 package org.apache.avalon.excalibur.event;
 
-import java.util.ArrayList;
 import org.apache.avalon.excalibur.concurrent.Mutex;
+import org.apache.avalon.excalibur.collections.Buffer;
+import org.apache.avalon.excalibur.collections.FixedSizeBuffer;
 
 /**
- * The default queue implementation is a variabl size queue.  This queue is
- * ThreadSafe, however the overhead in synchronization costs a few extra millis.
+ * Fixed size queue implementation. This queue is ThreadSafe, however the
+ * overhead in synchronization costs a few extra millis.
  *
  * @author <a href="mailto:[EMAIL PROTECTED]";>Berin Loritsch</a>
  */
 public final class FixedSizeQueue extends AbstractQueue
 {
-    private final QueueElement[] m_elements;
+    private final Buffer    m_elements;
     private final Mutex     m_mutex;
-    private       int       m_start = 0;
-    private       int       m_end = 0;
+    private final int       m_capacity;
     private       int       m_reserve = 0;
 
     public FixedSizeQueue( int size )
     {
-        m_elements = new QueueElement[ size + 1 ];
+        m_elements = new FixedSizeBuffer( size );
+        m_capacity = size;
         m_mutex = new Mutex();
     }
 
     public int size()
     {
-        int size = 0;
-
-        if ( m_end < m_start )
-        {
-            size = maxSize() - m_start + m_end;
-        }
-        else
-        {
-            size = m_end - m_start;
-        }
-
-        return size;
+        return m_elements.size();
     }
 
     public int maxSize()
     {
-        return m_elements.length;
+        return m_capacity;
     }
 
     public PreparedEnqueue prepareEnqueue( final QueueElement[] elements )
@@ -194,31 +184,12 @@
 
     private final void addElement( QueueElement element )
     {
-        m_elements[ m_end ] = element;
-
-        m_end++;
-        if ( m_end >= maxSize() )
-        {
-            m_end = 0;
-        }
+        m_elements.add( element );
     }
 
     private final QueueElement removeElement()
     {
-        QueueElement element = m_elements[ m_start ];
-
-        if ( null != element )
-        {
-            m_elements[ m_start ] = null;
-
-            m_start++;
-            if ( m_start >= maxSize() )
-            {
-                m_start = 0;
-            }
-        }
-
-        return element;
+        return (QueueElement) m_elements.remove();
     }
 
     public QueueElement[] dequeueAll()
@@ -313,4 +284,4 @@
             m_elements = null;
         }
     }
-}
\ No newline at end of file
+}

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to