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/java/org/apache/avalon/excalibur/collections FixedSizeBuffer.java
Date Mon, 25 Feb 2002 19:18:56 GMT
bloritsch    02/02/25 11:18:56

  Modified:    src/java/org/apache/avalon/excalibur/collections
                        FixedSizeBuffer.java
  Log:
  Fix FixedSizeBuffer with patch from Marcus Crafter
  
  Revision  Changes    Path
  1.2       +21 -6     jakarta-avalon-excalibur/src/java/org/apache/avalon/excalibur/collections/FixedSizeBuffer.java
  
  Index: FixedSizeBuffer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/src/java/org/apache/avalon/excalibur/collections/FixedSizeBuffer.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- FixedSizeBuffer.java	20 Dec 2001 18:28:33 -0000	1.1
  +++ FixedSizeBuffer.java	25 Feb 2002 19:18:56 -0000	1.2
  @@ -18,10 +18,11 @@
       private final Object[] m_elements;
       private       int       m_start = 0;
       private       int       m_end = 0;
  +    private       boolean   m_full = false;
   
       public FixedSizeBuffer( int size )
       {
  -        m_elements = new Object[ size + 1 ];
  +        m_elements = new Object[ size ];
       }
   
       public FixedSizeBuffer()
  @@ -37,6 +38,10 @@
           {
               size = m_elements.length - m_start + m_end;
           }
  +        else if ( m_end == m_start )
  +        {
  +            size = ( m_full ? m_elements.length : 0 );
  +        }
           else
           {
               size = m_end - m_start;
  @@ -52,19 +57,28 @@
   
       public final void add( Object element )
       {
  -        if ( size() > m_elements.length )
  +        if ( null == element )
  +        {
  +            throw new NullPointerException("Attempted to add null object to buffer");
  +        }
  +
  +        if ( m_full )
           {
               throw new BufferOverflowException( "The buffer cannot hold more than "
                                                  + m_elements.length + " objects." );
           }
   
  -        m_elements[ m_end ] = element;
  +        m_elements[ m_end++ ] = element;
   
  -        m_end++;
           if ( m_end >= m_elements.length )
           {
               m_end = 0;
           }
  +
  +        if ( m_end == m_start )
  +        {
  +            m_full = true;
  +        }
       }
   
       public final Object remove()
  @@ -78,13 +92,14 @@
   
           if ( null != element )
           {
  -            m_elements[ m_start ] = null;
  +            m_elements[ m_start++ ] = null;
   
  -            m_start++;
               if ( m_start >= m_elements.length )
               {
                   m_start = 0;
               }
  +
  +            m_full = false;
           }
   
           return element;
  
  
  

--
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