org.apache.avalon.excalibur.collections
Class VariableSizeBuffer

java.lang.Object
  |
  +--org.apache.avalon.excalibur.collections.VariableSizeBuffer
All Implemented Interfaces:
Buffer

public final class VariableSizeBuffer
extends java.lang.Object
implements Buffer

VariableSizeBuffer is a very efficient buffer implementation. According to performance testing, it exhibits a constant access time, but it also outperforms ArrayList when used for the same purpose.

Since:
4.0
Version:
CVS $Revision: 1.2 $ $Date: 2002/01/08 18:06:07 $
Author:
Federico Barbieri, Berin Loritsch

Field Summary
protected  java.lang.Object[] m_buffer
           
protected  int m_head
           
protected  int m_tail
           
 
Constructor Summary
VariableSizeBuffer()
          Initialize the VariableSizeBuffer with the default number of elements.
VariableSizeBuffer(int size)
          Initialize the VariableSizeBuffer with the specified number of elements.
 
Method Summary
 void add(java.lang.Object o)
          Add an object into the buffer
 boolean isEmpty()
          Tests to see if the CircularBuffer is empty.
 java.lang.Object remove()
          Removes the next object from the buffer
 int size()
          Returns the number of elements stored in the buffer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_buffer

protected java.lang.Object[] m_buffer

m_head

protected int m_head

m_tail

protected int m_tail
Constructor Detail

VariableSizeBuffer

public VariableSizeBuffer(int size)
Initialize the VariableSizeBuffer with the specified number of elements. The integer must be a positive integer.

VariableSizeBuffer

public VariableSizeBuffer()
Initialize the VariableSizeBuffer with the default number of elements. It is exactly the same as performing the following:
   new VariableSizeBuffer( 32 );
 
Method Detail

isEmpty

public final boolean isEmpty()
Tests to see if the CircularBuffer is empty.
Specified by:
isEmpty in interface Buffer

size

public final int size()
Returns the number of elements stored in the buffer.
Specified by:
size in interface Buffer

add

public final void add(java.lang.Object o)
Add an object into the buffer
Specified by:
add in interface Buffer
Following copied from interface: org.apache.avalon.excalibur.collections.Buffer
Throws:
BufferOverflowException - if adding this element exceeds the buffer's capacity.

remove

public java.lang.Object remove()
Removes the next object from the buffer
Specified by:
remove in interface Buffer
Following copied from interface: org.apache.avalon.excalibur.collections.Buffer
Throws:
BufferUnderflowException - if the buffer is already empty


Copyright © 2001 Apache Jakarta Project. All Rights Reserved.