You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by bl...@apache.org on 2002/02/25 20:18:56 UTC
cvs commit: jakarta-avalon-excalibur/src/java/org/apache/avalon/excalibur/collections FixedSizeBuffer.java
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: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>