commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Frank hefter (JIRA)" <j...@apache.org>
Subject [jira] Updated: (COLLECTIONS-246) LoopingListIterator behaves unexpected on next and previous mixed
Date Tue, 20 Mar 2007 09:44:32 GMT

     [ https://issues.apache.org/jira/browse/COLLECTIONS-246?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Frank hefter updated COLLECTIONS-246:
-------------------------------------

    Description: 
Using ArrayList as the backing list. 
This combination at least returns unexpected results as you can see in the testcase below.
I used this for a list navigator in a web frontend and had trouble with users.
I suspect java.util.AbstrList$ListItr (role of "cursor" var seems to be wrong implemented
) to cause this problem. If so maybe we have to implement it in a different way.

Testcase (it runs without hassle but the comments show whats wrong):
-------------------------------------------
import java.util.ArrayList;
import junit.framework.TestCase;
import org.apache.commons.collections.iterators.LoopingListIterator;

public class SelectionControllerTest extends TestCase {
    public void testSelectorForApache() {
        ArrayList al = new ArrayList();
        al.add("0"); al.add("1"); al.add("2");
        LoopingListIterator it = new  LoopingListIterator(al);
        assertEquals("0", it.next()); // This is OK
        // here I am on "0"
        assertEquals("0", it.previous()); // Wrong ! This should be 2!
        //      here I am on "0" too! This wrong.
        assertEquals("2", it.previous());
        assertEquals("1", it.previous());
        assertEquals("0", it.previous());
        assertEquals("2", it.previous());
        // here I am on "2" 
        assertEquals("2", it.next()); // Wrong ! This should be 0!
        // here I am on "2" too! This wrong.
        assertEquals("0", it.next()); 
        assertEquals("1", it.next());
        // here I am on "1"         
        assertEquals("1", it.previous()); // Wrong ! This should be 0!
    }
}
-------------------------------------------

Thanks for your help.

  was:
Using ArrayList as the backing list. 
This combination at least returns unexpected results as you can see in the testcase below.
I used this for a list navigator in a web frontend and had trouble with users.
I suspect java.util.AbstrList$ListItr (role of "cursor" var seems to be wrong implemented
) to cause this problem. If so maybe we have to implement it in a different way.

Testcase (it runs without hassle but the comments show whats wrong):
-------------------------------------------
import java.util.ArrayList;
import junit.framework.TestCase;
import org.apache.commons.collections.iterators.LoopingListIterator;

public class SelectionControllerTest extends TestCase {
    public void testSelectorForApache() {
        ArrayList al = new ArrayList();
        al.add("0"); al.add("1"); al.add("2");
        LoopingListIterator it = new  LoopingListIterator(al);
        assertEquals("0", it.next()); // This is OK
        // here I am on "0"
        assertEquals("0", it.previous()); // Wrong ! This should be 3!
        //      here I am on "0" too! This wrong.
        assertEquals("2", it.previous());
        assertEquals("1", it.previous());
        assertEquals("0", it.previous());
        assertEquals("2", it.previous());
        // here I am on "2" 
        assertEquals("2", it.next()); // Wrong ! This should be 0!
        // here I am on "2" too! This wrong.
        assertEquals("0", it.next()); 
        assertEquals("1", it.next());
        // here I am on "1"         
        assertEquals("1", it.previous()); // Wrong ! This should be 0!
    }
}
-------------------------------------------

Thanks for your help.


> LoopingListIterator behaves unexpected on next and previous mixed
> -----------------------------------------------------------------
>
>                 Key: COLLECTIONS-246
>                 URL: https://issues.apache.org/jira/browse/COLLECTIONS-246
>             Project: Commons Collections
>          Issue Type: Bug
>          Components: Iterator
>    Affects Versions: 3.2
>         Environment: JDK 1.4.2_12 
> Common Collections 3.2
>            Reporter: Frank hefter
>            Priority: Blocker
>
> Using ArrayList as the backing list. 
> This combination at least returns unexpected results as you can see in the testcase below.
> I used this for a list navigator in a web frontend and had trouble with users.
> I suspect java.util.AbstrList$ListItr (role of "cursor" var seems to be wrong implemented
) to cause this problem. If so maybe we have to implement it in a different way.
> Testcase (it runs without hassle but the comments show whats wrong):
> -------------------------------------------
> import java.util.ArrayList;
> import junit.framework.TestCase;
> import org.apache.commons.collections.iterators.LoopingListIterator;
> public class SelectionControllerTest extends TestCase {
>     public void testSelectorForApache() {
>         ArrayList al = new ArrayList();
>         al.add("0"); al.add("1"); al.add("2");
>         LoopingListIterator it = new  LoopingListIterator(al);
>         assertEquals("0", it.next()); // This is OK
>         // here I am on "0"
>         assertEquals("0", it.previous()); // Wrong ! This should be 2!
>         //      here I am on "0" too! This wrong.
>         assertEquals("2", it.previous());
>         assertEquals("1", it.previous());
>         assertEquals("0", it.previous());
>         assertEquals("2", it.previous());
>         // here I am on "2" 
>         assertEquals("2", it.next()); // Wrong ! This should be 0!
>         // here I am on "2" too! This wrong.
>         assertEquals("0", it.next()); 
>         assertEquals("1", it.next());
>         // here I am on "1"         
>         assertEquals("1", it.previous()); // Wrong ! This should be 0!
>     }
> }
> -------------------------------------------
> Thanks for your help.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


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


Mime
View raw message