avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From blorit...@apache.org
Subject cvs commit: jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/event DefaultQueue.java
Date Wed, 19 Dec 2001 22:29:44 GMT
bloritsch    01/12/19 14:29:43

  Modified:    src/java/org/apache/avalon/excalibur/collections
                        CircularBuffer.java
               src/scratchpad/org/apache/avalon/excalibur/event
                        DefaultQueue.java
  Added:       src/java/org/apache/avalon/excalibur/collections
                        AvalonBuffer.java
  Log:
  update to new Buffer api
  
  Revision  Changes    Path
  1.4       +2 -1      jakarta-avalon-excalibur/src/java/org/apache/avalon/excalibur/collections/CircularBuffer.java
  
  Index: CircularBuffer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/src/java/org/apache/avalon/excalibur/collections/CircularBuffer.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- CircularBuffer.java	2001/12/11 09:53:27	1.3
  +++ CircularBuffer.java	2001/12/19 22:29:43	1.4
  @@ -8,9 +8,10 @@
   package org.apache.avalon.excalibur.collections;
   
   /**
  + * @deprecated use AvalonBuffer instead.
    *
    * @author  Federico Barbieri <fede@apache.org>
  - * @version CVS $Revision: 1.3 $ $Date: 2001/12/11 09:53:27 $
  + * @version CVS $Revision: 1.4 $ $Date: 2001/12/19 22:29:43 $
    * @since 4.0
    */
   public class CircularBuffer
  
  
  
  1.1                  jakarta-avalon-excalibur/src/java/org/apache/avalon/excalibur/collections/AvalonBuffer.java
  
  Index: AvalonBuffer.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.avalon.excalibur.collections;
  
  /**
   * AvalonBuffer is a <strong>very</strong> efficient buffer implementation.
   * According to performance testing, it exhibits a linear access time, but it
   * also outperforms ArrayList when used for the same purpose.
   *
   * @author  <a href="fede@apache.org">Federico Barbieri</a>
   * @author  <a href="bloritsch@apache.org">Berin Loritsch</a>
   * @version CVS $Revision: 1.1 $ $Date: 2001/12/19 22:29:43 $
   * @since 4.0
   */
  public final class AvalonBuffer
  {
      protected Object[]   m_buffer;
      protected int        m_bufferSize;
      protected int        m_contentSize;
      protected int        m_head;
      protected int        m_tail;
  
      /**
       * Initialize the AvalonBuffer with the specified number of elements.  The
       * integer must be a positive integer.
       */
      public AvalonBuffer( int size )
      {
          m_buffer = new Object[size];
          m_bufferSize = size;
          m_contentSize = 0;
          m_head = 0;
          m_tail = 0;
      }
  
      /**
       * Initialize the AvalonBuffer with the default number of elements.  It is
       * exactly the same as performing the following:
       *
       * <pre>
       *   new AvalonBuffer( 32 );
       * </pre>
       */
      public AvalonBuffer()
      {
          this( 32 );
      }
  
      /**
       * Tests to see if the CircularBuffer is empty.
       */
      public boolean isEmpty()
      {
          return (m_contentSize == 0);
      }
  
      /**
       * Returns the number of elements stored in the buffer.
       */
      public int size()
      {
          return m_contentSize;
      }
  
      /**
       * Add an object into the buffer
       */
      public void add( final Object o )
      {
          if( m_contentSize >= m_bufferSize )
          {
              int j = 0;
              int i = m_tail;
              Object[] tmp = new Object[ m_bufferSize * 2 ];
  
              while( m_contentSize > 0 )
              {
                  i++;
                  i %= m_bufferSize;
                  j++;
                  m_contentSize--;
                  tmp[ j ] = m_buffer[ i ];
              }
              m_buffer = tmp;
              m_tail = 0;
              m_head = j;
              m_contentSize = j;
              m_bufferSize *= 2;
          }
  
          m_buffer[ m_head ] = o;
          m_head++;
          m_head %= m_bufferSize;
          m_contentSize++;
      }
  
      /**
       * Removes the next object from the buffer
       */
      public Object remove()
      {
          if( m_contentSize <= 0 )
          {
              return null;
          }
  
          Object o = m_buffer[ m_tail ];
          m_tail++;
          m_tail %= m_bufferSize;
          m_contentSize--;
          return o;
      }
  }
  
  
  
  
  1.6       +11 -11    jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/event/DefaultQueue.java
  
  Index: DefaultQueue.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/event/DefaultQueue.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- DefaultQueue.java	2001/12/19 21:00:03	1.5
  +++ DefaultQueue.java	2001/12/19 22:29:43	1.6
  @@ -7,7 +7,7 @@
    */
   package org.apache.avalon.excalibur.event;
   
  -import org.apache.avalon.excalibur.collections.CircularBuffer;
  +import org.apache.avalon.excalibur.collections.AvalonBuffer;
   import org.apache.avalon.excalibur.concurrent.Mutex;
   
   /**
  @@ -18,7 +18,7 @@
    */
   public final class DefaultQueue extends AbstractQueue
   {
  -    private final CircularBuffer m_elements;
  +    private final AvalonBuffer m_elements;
       private final Mutex     m_mutex;
       private       int       m_reserve;
       private final int       m_maxSize;
  @@ -29,12 +29,12 @@
   
           if ( size > 0 )
           {
  -            m_elements = new CircularBuffer( size );
  +            m_elements = new AvalonBuffer( size );
               maxSize = size;
           }
           else
           {
  -            m_elements = new CircularBuffer();
  +            m_elements = new AvalonBuffer();
               maxSize = -1;
           }
   
  @@ -50,7 +50,7 @@
   
       public int size()
       {
  -        return m_elements.getContentSize();
  +        return m_elements.size();
       }
   
       public int maxSize()
  @@ -98,7 +98,7 @@
                   return false;
               }
   
  -            m_elements.append( element );
  +            m_elements.add( element );
               success = true;
           }
           catch ( InterruptedException ie )
  @@ -127,7 +127,7 @@
   
               for ( int i = 0; i < len; i++ )
               {
  -                m_elements.append( elements[i] );
  +                m_elements.add( elements[i] );
               }
           }
           catch ( InterruptedException ie )
  @@ -150,7 +150,7 @@
                   throw new SourceFullException("Not enough room to enqueue these elements.");
               }
   
  -            m_elements.append( element );
  +            m_elements.add( element );
           }
           catch ( InterruptedException ie )
           {
  @@ -185,7 +185,7 @@
   
               for ( int i = 0; i < arraySize; i++ )
               {
  -                elements[i] = (QueueElement) m_elements.get();
  +                elements[i] = (QueueElement) m_elements.remove();
               }
           }
           catch ( InterruptedException ie )
  @@ -211,7 +211,7 @@
   
               for ( int i = 0; i < elements.length; i++ )
               {
  -                elements[i] = (QueueElement) m_elements.get();
  +                elements[i] = (QueueElement) m_elements.remove();
               }
           }
           catch ( InterruptedException ie )
  @@ -235,7 +235,7 @@
   
               if ( size() > 0 )
               {
  -                element = (QueueElement) m_elements.get();
  +                element = (QueueElement) m_elements.remove();
               }
           }
           catch ( InterruptedException ie )
  
  
  

--
To unsubscribe, e-mail:   <mailto:avalon-cvs-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:avalon-cvs-help@jakarta.apache.org>


Mime
View raw message