Package org.apache.commons.collections

Examples of org.apache.commons.collections.Buffer


        return false;
    }
   
    public void testBufferRemove() {
        resetEmpty();
        Buffer buffer = (Buffer) collection;
        try {
            buffer.remove();
            fail();
        } catch (UnsupportedOperationException ex) {}
    }
View Full Code Here


        return BoundedBuffer.decorate(new UnboundedFifoBuffer(), 1);
    }

    //-----------------------------------------------------------------------
    public void testMaxSize() {
        final Buffer bounded = BoundedBuffer.decorate(new UnboundedFifoBuffer(), 2, 500);
        BoundedCollection bc = (BoundedCollection) bounded;
        assertEquals(2, bc.maxSize());
        assertEquals(false, bc.isFull());
        bounded.add("A");
        assertEquals(false, bc.isFull());
        bounded.add("B");
        assertEquals(true, bc.isFull());
        bounded.remove();
        assertEquals(false, bc.isFull());
        try {
            BoundedBuffer.decorate(new UnboundedFifoBuffer(), 0);
            fail();
        } catch (IllegalArgumentException ex) {}
View Full Code Here

            fail();
        } catch (IllegalArgumentException ex) {}
    }

    public void testAddToFullBufferNoTimeout() {
        final Buffer bounded = BoundedBuffer.decorate(new UnboundedFifoBuffer(), 1);
        bounded.add( "Hello" );
        try {
            bounded.add("World");
            fail();
        } catch (BufferOverflowException e) {
        }
    }
View Full Code Here

        } catch (BufferOverflowException e) {
        }
    }

    public void testAddAllToFullBufferNoTimeout() {
        final Buffer bounded = BoundedBuffer.decorate(new UnboundedFifoBuffer(), 1);
        bounded.add( "Hello" );
        try {
            bounded.addAll(Collections.singleton("World"));
            fail();
        } catch (BufferOverflowException e) {
        }
    }
View Full Code Here

        } catch (BufferOverflowException e) {
        }
    }

    public void testAddAllToEmptyBufferExceedMaxSizeNoTimeout() {
        final Buffer bounded = BoundedBuffer.decorate(new UnboundedFifoBuffer(), 1);
        try {
            bounded.addAll(Collections.nCopies(2, "test"));
            fail();
        } catch (BufferOverflowException e) {
        }
    }
View Full Code Here

        } catch (BufferOverflowException e) {
        }
    }

    public void testAddToFullBufferRemoveViaIterator() {
        final Buffer bounded = BoundedBuffer.decorate(new UnboundedFifoBuffer(), 1, 500);
        bounded.add( "Hello" );
        new DelayedIteratorRemove( bounded, 200 ).start();
        bounded.add( "World" );
        assertEquals( 1, bounded.size() );
        assertEquals( "World", bounded.get() );

    }
View Full Code Here

    }

    //----------------------------------------------------------------------- 
    public void testBufferEmpty() {
        resetEmpty();
        Buffer buffer = (Buffer) collection;

        assertEquals(0, buffer.size());
        assertEquals(true, buffer.isEmpty());
        try {
            buffer.get();
            fail();
        } catch (BufferUnderflowException ex) {}

        try {
            buffer.remove();
            fail();
        } catch (BufferUnderflowException ex) {}
    }
View Full Code Here

    public Collection makeCollection() {
        return SynchronizedBuffer.decorate(new UnboundedFifoBuffer());
    }
   
    public Collection makeFullCollection() {
        Buffer buffer = new UnboundedFifoBuffer();
        buffer.addAll(Arrays.asList(getFullElements()));
        return SynchronizedBuffer.decorate(buffer);
    }
View Full Code Here

        assertEquals( "World", bounded.get() );

    }

    public void testAddAllToFullBufferRemoveViaIterator() {
        final Buffer bounded = BoundedBuffer.decorate(new UnboundedFifoBuffer(), 2, 500);
        bounded.add( "Hello" );
        bounded.add( "World" );
        new DelayedIteratorRemove( bounded, 200, 2 ).start();
        bounded.addAll( Arrays.asList( new String[] { "Foo", "Bar" } ) );
        assertEquals( 2, bounded.size() );
        assertEquals( "Foo", bounded.remove() );
        assertEquals( "Bar", bounded.remove() );
    }
View Full Code Here

        assertEquals( "Foo", bounded.remove() );
        assertEquals( "Bar", bounded.remove() );
    }

    public void testAddToFullBufferWithTimeout() {
        final Buffer bounded = BoundedBuffer.decorate(new UnboundedFifoBuffer(), 1, 500);
        bounded.add( "Hello" );
        new DelayedRemove( bounded, 200 ).start();
        bounded.add( "World" );
        assertEquals( 1, bounded.size() );
        assertEquals( "World", bounded.get() );
        try {
            bounded.add( "!" );
            fail();
        }
        catch( BufferOverflowException e ) {
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.commons.collections.Buffer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.