avalon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Eung-ju Park" <co...@apache.org>
Subject Re: cvs commit: jakarta-avalon-excalibur/src/java/org/apache/avalon/excalibur/collections BufferOverflowException.java BufferUnderflowException.java FixedSizeBuffer.java VariableSizeBuffer.java CircularBuffer.java AvalonBuffer.java
Date Fri, 21 Dec 2001 01:56:27 GMT
Buffer.java is not committed. ;-)

----- Original Message -----
From: <bloritsch@apache.org>
To: <jakarta-avalon-excalibur-cvs@apache.org>
Sent: Friday, December 21, 2001 3:28 AM
Subject: cvs commit:
jakarta-avalon-excalibur/src/java/org/apache/avalon/excalibur/collections
BufferOverflowException.java BufferUnderflowException.java
FixedSizeBuffer.java VariableSizeBuffer.java CircularBuffer.java
AvalonBuffer.java


> bloritsch    01/12/20 10:28:33
>
>   Modified:    src/java/org/apache/avalon/excalibur/collections
>                         CircularBuffer.java
>   Added:       src/java/org/apache/avalon/excalibur/collections
>                         BufferOverflowException.java
>                         BufferUnderflowException.java FixedSizeBuffer.java
>                         VariableSizeBuffer.java
>   Removed:     src/java/org/apache/avalon/excalibur/collections
>                         AvalonBuffer.java
>   Log:
>   Update new buffer code with more formal interface and runtime exceptions
>
>   Revision  Changes    Path
>   1.5       +2 -2
jakarta-avalon-excalibur/src/java/org/apache/avalon/excalibur/collections/Ci
rcularBuffer.java
>
>   Index: CircularBuffer.java
>   ===================================================================
>   RCS file:
/home/cvs/jakarta-avalon-excalibur/src/java/org/apache/avalon/excalibur/coll
ections/CircularBuffer.java,v
>   retrieving revision 1.4
>   retrieving revision 1.5
>   diff -u -r1.4 -r1.5
>   --- CircularBuffer.java 2001/12/19 22:29:43 1.4
>   +++ CircularBuffer.java 2001/12/20 18:28:33 1.5
>   @@ -8,10 +8,10 @@
>    package org.apache.avalon.excalibur.collections;
>
>    /**
>   - * @deprecated use AvalonBuffer instead.
>   + * @deprecated use one of the Buffer implementations instead.
>     *
>     * @author  Federico Barbieri <fede@apache.org>
>   - * @version CVS $Revision: 1.4 $ $Date: 2001/12/19 22:29:43 $
>   + * @version CVS $Revision: 1.5 $ $Date: 2001/12/20 18:28:33 $
>     * @since 4.0
>     */
>    public class CircularBuffer
>
>
>
>   1.1
jakarta-avalon-excalibur/src/java/org/apache/avalon/excalibur/collections/Bu
fferOverflowException.java
>
>   Index: BufferOverflowException.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;
>
>   import org.apache.avalon.framework.CascadingRuntimeException;
>
>   /**
>    * The BufferOverflowException is used when the buffer's capacity has
been
>    * exceeded.
>    *
>    * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
>    */
>   public class BufferOverflowException extends CascadingRuntimeException
>   {
>
>       public BufferOverflowException( String message )
>       {
>           super( message, null );
>       }
>
>       public BufferOverflowException( String message, Throwable
exception )
>       {
>           super( message, exception );
>       }
>   }
>
>
>   1.1
jakarta-avalon-excalibur/src/java/org/apache/avalon/excalibur/collections/Bu
fferUnderflowException.java
>
>   Index: BufferUnderflowException.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;
>
>   import org.apache.avalon.framework.CascadingRuntimeException;
>
>   /**
>    * The BufferOverflowException is used when the buffer is already empty
>    *
>    * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
>    */
>   public class BufferUnderflowException extends CascadingRuntimeException
>   {
>
>       public BufferUnderflowException( String message )
>       {
>           super( message, null );
>       }
>
>       public BufferUnderflowException( String message, Throwable
exception )
>       {
>           super( message, exception );
>       }
>   }
>
>
>   1.1
jakarta-avalon-excalibur/src/java/org/apache/avalon/excalibur/collections/Fi
xedSizeBuffer.java
>
>   Index: FixedSizeBuffer.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;
>
>   /**
>    * The FixedSizeBuffer is a <strong>very</strong> efficient
implementation of
>    * Buffer that does not alter the size of the buffer at runtime.
>    *
>    * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
>    */
>   public final class FixedSizeBuffer implements Buffer
>   {
>       private final Object[] m_elements;
>       private       int       m_start = 0;
>       private       int       m_end = 0;
>
>       public FixedSizeBuffer( int size )
>       {
>           m_elements = new Object[ size + 1 ];
>       }
>
>       public FixedSizeBuffer()
>       {
>           this( 32 );
>       }
>
>       public final int size()
>       {
>           int size = 0;
>
>           if ( m_end < m_start )
>           {
>               size = m_elements.length - m_start + m_end;
>           }
>           else
>           {
>               size = m_end - m_start;
>           }
>
>           return size;
>       }
>
>       public final boolean isEmpty()
>       {
>           return size() == 0;
>       }
>
>       public final void add( Object element )
>       {
>           if ( size() > m_elements.length )
>           {
>               throw new BufferOverflowException( "The buffer cannot hold
more than "
>                                                  + m_elements.length + "
objects." );
>           }
>
>           m_elements[ m_end ] = element;
>
>           m_end++;
>           if ( m_end >= m_elements.length )
>           {
>               m_end = 0;
>           }
>       }
>
>       public final Object remove()
>       {
>           if ( isEmpty() )
>           {
>               throw new BufferUnderflowException( "The buffer is already
empty" );
>           }
>
>           Object element = m_elements[ m_start ];
>
>           if ( null != element )
>           {
>               m_elements[ m_start ] = null;
>
>               m_start++;
>               if ( m_start >= m_elements.length )
>               {
>                   m_start = 0;
>               }
>           }
>
>           return element;
>       }
>   }
>
>
>   1.1
jakarta-avalon-excalibur/src/java/org/apache/avalon/excalibur/collections/Va
riableSizeBuffer.java
>
>   Index: VariableSizeBuffer.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;
>
>   /**
>    * VariableSizeBuffer 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/20 18:28:33 $
>    * @since 4.0
>    */
>   public final class VariableSizeBuffer implements Buffer
>   {
>       protected Object[]   m_buffer;
>       protected int        m_bufferSize;
>       protected int        m_contentSize;
>       protected int        m_head;
>       protected int        m_tail;
>
>       /**
>        * Initialize the VariableSizeBuffer with the specified number of
elements.  The
>        * integer must be a positive integer.
>        */
>       public VariableSizeBuffer( int size )
>       {
>           m_buffer = new Object[size];
>           m_bufferSize = size;
>           m_contentSize = 0;
>           m_head = 0;
>           m_tail = 0;
>       }
>
>       /**
>        * Initialize the VariableSizeBuffer with the default number of
elements.  It is
>        * exactly the same as performing the following:
>        *
>        * <pre>
>        *   new VariableSizeBuffer( 32 );
>        * </pre>
>        */
>       public VariableSizeBuffer()
>       {
>           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 ( isEmpty() )
>           {
>               throw new BufferUnderflowException( "The buffer is already
empty" );
>           }
>
>           Object o = m_buffer[ m_tail ];
>           m_tail++;
>           m_tail %= m_bufferSize;
>           m_contentSize--;
>           return o;
>       }
>   }
>
>
>
>
>
> --
> To unsubscribe, e-mail:
<mailto:avalon-cvs-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail:
<mailto:avalon-cvs-help@jakarta.apache.org>
>
>


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


Mime
View raw message