Hi Berin (& all),

        What do you think about the (untested) attachment. I'm wondering if
        the increase in code reuse yields too high a performance hit in
        comparison to the previous implementation ?

        Too slow ?

        Cheers,

        Marcus
-- 
        .....
     ,,$$$$$$$$$,      Marcus Crafter
    ;$'      '$$$$:    Computer Systems Engineer
    $:         $$$$:   ManageSoft GmbH
     $       o_)$$$:   82-84 Mainzer Landstrasse
     ;$,    _/\ &&:'   60327 Frankfurt Germany
       '     /( &&&
           \_&&&&'
          &&&&.
    &&&&&&&:
/*
* 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;

/**
 * Trial implementation of VariableSizeBuffer using FixedBuffers objects.
 *
 * @author  <a href="[EMAIL PROTECTED]">Marcus Crafter</a>
 * @version CVS $Revision: 1.3 $ $Date: 2002/02/25 19:21:49 $
 * @since 4.0
 */
public final class VBuffer implements Buffer
{
	protected Buffer m_buffer;

	/**
	 * Initialize the VariableSizeBuffer with the specified number of elements.
	 * The integer must be a positive integer.
	 */
	public VBuffer( int size )
	{
		m_buffer = new FixedSizeBuffer( size );
	}

	/**
	 * Initialize the VariableSizeBuffer with the default number of elements.
	 * It is exactly the same as performing the following:
	 *
	 * <pre>
	 *   new VariableSizeBuffer( 32 );
	 * </pre>
	 */
	public VBuffer()
	{
		this( 32 );
	}

	/**
	 * Tests to see if the CircularBuffer is empty.
	 */
	public final boolean isEmpty()
	{
		return m_buffer.isEmpty();
	}

	/**
	 * Returns the number of elements stored in the buffer.
	 */
	public final int size()
	{
		return m_buffer.size();
	}

	/**
	 * Add an object into the buffer
	 */
	public final void add( final Object o )
	{
		try
		{
			m_buffer.add( o );
		}
		catch ( BufferOverflowException e )
		{
			Buffer newbuff = new FixedSizeBuffer( m_buffer.size() * 2 );

			while ( !m_buffer.isEmpty() )
			{
				newbuff.add( m_buffer.remove() );
			}

			newbuff.add( o );
			m_buffer = newbuff;
		}
	}

	/**
	 * Removes the next object from the buffer
	 */
	public Object remove()
	{
		return m_buffer.remove();
	}
}


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to