commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sebb <seb...@gmail.com>
Subject Re: svn commit: r1351852 - in /commons/proper/collections/trunk/src: main/java/org/apache/commons/collections/buffer/ test/java/org/apache/commons/collections/buffer/
Date Tue, 19 Jun 2012 22:19:44 GMT
On 19 June 2012 22:05,  <tn@apache.org> wrote:
> Author: tn
> Date: Tue Jun 19 21:05:48 2012
> New Revision: 1351852
>
> URL: http://svn.apache.org/viewvc?rev=1351852&view=rev
> Log:
> [COLLECTIONS-399] Added get(index) method to BoundedFifoBuffer.
>
> Modified:
>    commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/buffer/BoundedFifoBuffer.java
>    commons/proper/collections/trunk/src/test/java/org/apache/commons/collections/buffer/TestBoundedFifoBuffer.java
>    commons/proper/collections/trunk/src/test/java/org/apache/commons/collections/buffer/TestCircularFifoBuffer.java
>
> Modified: commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/buffer/BoundedFifoBuffer.java
> URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/buffer/BoundedFifoBuffer.java?rev=1351852&r1=1351851&r2=1351852&view=diff
> ==============================================================================
> --- commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/buffer/BoundedFifoBuffer.java
(original)
> +++ commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/buffer/BoundedFifoBuffer.java
Tue Jun 19 21:05:48 2012
> @@ -131,7 +131,7 @@ public class BoundedFifoBuffer<E> extend
>      * Write the buffer out using a custom routine.
>      *
>      * @param out  the output stream
> -     * @throws IOException
> +     * @throws IOException if an I/O error occurs while writing to the output stream
>      */
>     private void writeObject(ObjectOutputStream out) throws IOException {
>         out.defaultWriteObject();
> @@ -145,8 +145,8 @@ public class BoundedFifoBuffer<E> extend
>      * Read the buffer in using a custom routine.
>      *
>      * @param in  the input stream
> -     * @throws IOException
> -     * @throws ClassNotFoundException
> +     * @throws IOException if an I/O error occurs while writing to the output stream
> +     * @throws ClassNotFoundException if the class of a serialized object can not
be found
>      */
>     @SuppressWarnings("unchecked")
>     private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException
{
> @@ -270,6 +270,22 @@ public class BoundedFifoBuffer<E> extend
>     }
>
>     /**
> +     * Returns the element at the specified position in this buffer.
> +     *
> +     * @param index the position of the element in the buffer
> +     * @return the element at position {@code index}
> +     * @throws NoSuchElementException if the requested position is outside the range
[0, size)
> +     */
> +    public E get(int index) {
> +        if (index < 0 || index >= size()) {
> +            throw new NoSuchElementException();

It would be helpful to show the values of index and size().

> +        }
> +
> +        final int idx = (start + index) % maxElements;
> +        return elements[idx];
> +    }
> +
> +    /**
>      * Removes the least recently inserted element from this buffer.
>      *
>      * @return the least recently inserted element
>
> Modified: commons/proper/collections/trunk/src/test/java/org/apache/commons/collections/buffer/TestBoundedFifoBuffer.java
> URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/java/org/apache/commons/collections/buffer/TestBoundedFifoBuffer.java?rev=1351852&r1=1351851&r2=1351852&view=diff
> ==============================================================================
> --- commons/proper/collections/trunk/src/test/java/org/apache/commons/collections/buffer/TestBoundedFifoBuffer.java
(original)
> +++ commons/proper/collections/trunk/src/test/java/org/apache/commons/collections/buffer/TestBoundedFifoBuffer.java
Tue Jun 19 21:05:48 2012
> @@ -19,6 +19,7 @@ package org.apache.commons.collections.b
>  import java.util.ArrayList;
>  import java.util.Iterator;
>  import java.util.List;
> +import java.util.NoSuchElementException;
>
>  import junit.framework.Test;
>
> @@ -171,6 +172,44 @@ public class TestBoundedFifoBuffer<E> ex
>         }
>         fail();
>     }
> +
> +    /**
> +     * Tests that the get(index) method correctly throws an exception.
> +     */
> +    public void testGetException() {
> +        resetFull();
> +        try {
> +            getCollection().get(-1);
> +            fail();
> +        } catch (NoSuchElementException ex) {
> +            // expected
> +        }
> +
> +        try {
> +            getCollection().get(getCollection().size());
> +            fail();
> +        } catch (NoSuchElementException ex) {
> +            // expected
> +        }
> +    }
> +
> +    public void testGetIndex() {
> +        resetFull();
> +
> +        BoundedFifoBuffer<E> buffer = getCollection();
> +        List<E> confirmed = getConfirmed();
> +        for (int i = 0; i < confirmed.size(); i++) {
> +            assertEquals(confirmed.get(i), buffer.get(i));
> +        }
> +
> +        // remove the first two elements and check again
> +        buffer.remove();
> +        buffer.remove();
> +
> +        for (int i = 0; i < buffer.size(); i++) {
> +            assertEquals(confirmed.get(i + 2), buffer.get(i));
> +        }
> +    }
>
>     @Override
>     public String getCompatibilityVersion() {
>
> Modified: commons/proper/collections/trunk/src/test/java/org/apache/commons/collections/buffer/TestCircularFifoBuffer.java
> URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/java/org/apache/commons/collections/buffer/TestCircularFifoBuffer.java?rev=1351852&r1=1351851&r2=1351852&view=diff
> ==============================================================================
> --- commons/proper/collections/trunk/src/test/java/org/apache/commons/collections/buffer/TestCircularFifoBuffer.java
(original)
> +++ commons/proper/collections/trunk/src/test/java/org/apache/commons/collections/buffer/TestCircularFifoBuffer.java
Tue Jun 19 21:05:48 2012
> @@ -415,6 +415,24 @@ public class TestCircularFifoBuffer<E> e
>         assertEquals(true, b3.contains("c"));
>     }
>
> +    public void testGetIndex() {
> +        resetFull();
> +
> +        CircularFifoBuffer<E> buffer = getCollection();
> +        List<E> confirmed = getConfirmed();
> +        for (int i = 0; i < confirmed.size(); i++) {
> +            assertEquals(confirmed.get(i), buffer.get(i));
> +        }
> +
> +        // remove the first two elements and check again
> +        buffer.remove();
> +        buffer.remove();
> +
> +        for (int i = 0; i < buffer.size(); i++) {
> +            assertEquals(confirmed.get(i + 2), buffer.get(i));
> +        }
> +    }
> +
>     @Override
>     public String getCompatibilityVersion() {
>         return "3.1";
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Mime
View raw message