You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by "Michael Pavlov (JIRA)" <ji...@apache.org> on 2007/01/17 10:27:27 UTC

[jira] Created: (COLLECTIONS-239) In LinkIterator hasPrevious() is not working properly for the first entry

In LinkIterator hasPrevious() is not working properly for the first entry
-------------------------------------------------------------------------

                 Key: COLLECTIONS-239
                 URL: https://issues.apache.org/jira/browse/COLLECTIONS-239
             Project: Commons Collections
          Issue Type: Bug
          Components: Iterator
    Affects Versions: 3.2
         Environment: Windows XP, jdk-1.5.0_02
            Reporter: Michael Pavlov


In hasPrevious() method of LinkIterator 'next' field is used, that is not correct  - method returns 'true' for the first entry. 'last' field should be used insted.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: https://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

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


[jira] Commented: (COLLECTIONS-239) In LinkIterator hasPrevious() is not working properly for the first entry

Posted by "Henri Yandell (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/COLLECTIONS-239?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12468439 ] 

Henri Yandell commented on COLLECTIONS-239:
-------------------------------------------

Looking at trunk, the actual code is:

            return (next.before != parent.header);

Not the most semantically clear, but the following test appears to pass quite happily:

    // http://issues.apache.org/jira/browse/COLLECTIONS-239
    public void testCollections239() {
        LinkedMap map = new LinkedMap();
        map.put("1", "1");
        map.put("2", "2");
        map.put("3", "3");
        map.put("4", "4");

        OrderedIterator itr = (OrderedIterator) map.values().iterator();
        assertFalse( itr.hasPrevious() );
        for( int i=0; i < 4; i++) {
            assertTrue( itr.hasNext() );
            Object ignore = itr.next();
            assertTrue( itr.hasPrevious() );
        }

        assertFalse( itr.hasNext() );
    }

So I think this is resolvable as "cannot reproduce". Do you have a test case that fails?

> In LinkIterator hasPrevious() is not working properly for the first entry
> -------------------------------------------------------------------------
>
>                 Key: COLLECTIONS-239
>                 URL: https://issues.apache.org/jira/browse/COLLECTIONS-239
>             Project: Commons Collections
>          Issue Type: Bug
>          Components: Iterator
>    Affects Versions: 3.2
>         Environment: Windows XP, jdk-1.5.0_02
>            Reporter: Michael Pavlov
>
> In hasPrevious() method of LinkIterator 'next' field is used, that is not correct  - method returns 'true' for the first entry. 'last' field should be used insted.

-- 
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


[jira] Commented: (COLLECTIONS-239) In LinkIterator hasPrevious() is not working properly for the first entry

Posted by "Michael Pavlov (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/COLLECTIONS-239?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12470528 ] 

Michael Pavlov commented on COLLECTIONS-239:
--------------------------------------------

Why OrderedIterator should rely on 'next' field? Current(last returned) entry is in 'last' field. 
Semantically in java.util.Iterator hasNext() referes to last returned value.
My use case is: I need to iterate through map values in JSP and construct a table with command to move up &down. My code is:
  for (OrderedIterator I = (OrderedIterator)map.values().iterator(); I.hasNext();)
  {
     /* next() is the only method that can return current value, but it moves iterator cursor to the next entry
     so hasPrevious returns true. In order to get it right i need to remember it first in separate field like these*/
   // boolean hasPrevious = I.hasPrevious();
     String s = (String) I.next();%>
     <tr><td><%=s%></td><td><%if(I.hasPrevious()){%><input type="button" value="UP" onClick="..."/><%}%></td>...</tr><%
   
  }


> In LinkIterator hasPrevious() is not working properly for the first entry
> -------------------------------------------------------------------------
>
>                 Key: COLLECTIONS-239
>                 URL: https://issues.apache.org/jira/browse/COLLECTIONS-239
>             Project: Commons Collections
>          Issue Type: Bug
>          Components: Iterator
>    Affects Versions: 3.2
>         Environment: Windows XP, jdk-1.5.0_02
>            Reporter: Michael Pavlov
>
> In hasPrevious() method of LinkIterator 'next' field is used, that is not correct  - method returns 'true' for the first entry. 'last' field should be used insted.

-- 
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


[jira] Commented: (COLLECTIONS-239) In LinkIterator hasPrevious() is not working properly for the first entry

Posted by "Henri Yandell (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/COLLECTIONS-239?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12470730 ] 

Henri Yandell commented on COLLECTIONS-239:
-------------------------------------------

(grr's at firefox 2 for losing a long reply).

I'm still thinking we should resolve this as not to be fixed. Here's why:

OrderedIterator oi = ...;
oi.next();
oi.previous();
oi.next();
oi.previous();
// back at the start

If hasPrevious() was to return false after moving passed the first element, then the above would not be possible. Looking at the Javadoc for OrderedIterator, the previous() method does need to indicate that movement happens, and the class Javadoc could do with a note on this subject - that hasPrevious() returns true after calling the first next().

> In LinkIterator hasPrevious() is not working properly for the first entry
> -------------------------------------------------------------------------
>
>                 Key: COLLECTIONS-239
>                 URL: https://issues.apache.org/jira/browse/COLLECTIONS-239
>             Project: Commons Collections
>          Issue Type: Bug
>          Components: Iterator
>    Affects Versions: 3.2
>         Environment: Windows XP, jdk-1.5.0_02
>            Reporter: Michael Pavlov
>         Attachments: COLLECTIONS-239-test.patch
>
>
> In hasPrevious() method of LinkIterator 'next' field is used, that is not correct  - method returns 'true' for the first entry. 'last' field should be used insted.

-- 
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


[jira] Reopened: (COLLECTIONS-239) In LinkIterator hasPrevious() is not working properly for the first entry

Posted by "Michael Pavlov (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/COLLECTIONS-239?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Michael Pavlov reopened COLLECTIONS-239:
----------------------------------------


Semantically hasNext() referes to last returned value ('last' field) (in java.util.Iterator ). 
Why hasPrevious() should use 'next' field (in LinkIterator)?


> In LinkIterator hasPrevious() is not working properly for the first entry
> -------------------------------------------------------------------------
>
>                 Key: COLLECTIONS-239
>                 URL: https://issues.apache.org/jira/browse/COLLECTIONS-239
>             Project: Commons Collections
>          Issue Type: Bug
>          Components: Iterator
>    Affects Versions: 3.2
>         Environment: Windows XP, jdk-1.5.0_02
>            Reporter: Michael Pavlov
>
> In hasPrevious() method of LinkIterator 'next' field is used, that is not correct  - method returns 'true' for the first entry. 'last' field should be used insted.

-- 
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


[jira] Closed: (COLLECTIONS-239) In LinkIterator hasPrevious() is not working properly for the first entry

Posted by "Henri Yandell (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/COLLECTIONS-239?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Henri Yandell closed COLLECTIONS-239.
-------------------------------------

    Resolution: Cannot Reproduce

Going ahead with the 'cannot reproduce'. Please feel free to reopen the issue.

> In LinkIterator hasPrevious() is not working properly for the first entry
> -------------------------------------------------------------------------
>
>                 Key: COLLECTIONS-239
>                 URL: https://issues.apache.org/jira/browse/COLLECTIONS-239
>             Project: Commons Collections
>          Issue Type: Bug
>          Components: Iterator
>    Affects Versions: 3.2
>         Environment: Windows XP, jdk-1.5.0_02
>            Reporter: Michael Pavlov
>
> In hasPrevious() method of LinkIterator 'next' field is used, that is not correct  - method returns 'true' for the first entry. 'last' field should be used insted.

-- 
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


[jira] Updated: (COLLECTIONS-239) In LinkIterator hasPrevious() is not working properly for the first entry

Posted by "Henri Yandell (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/COLLECTIONS-239?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Henri Yandell updated COLLECTIONS-239:
--------------------------------------

    Attachment: COLLECTIONS-239-test.patch

I think I see. Your report is that hasPrevious() should still return false after the first element.

I've attached a unit test that shows that this is a problem. Thanks for reopening.

> In LinkIterator hasPrevious() is not working properly for the first entry
> -------------------------------------------------------------------------
>
>                 Key: COLLECTIONS-239
>                 URL: https://issues.apache.org/jira/browse/COLLECTIONS-239
>             Project: Commons Collections
>          Issue Type: Bug
>          Components: Iterator
>    Affects Versions: 3.2
>         Environment: Windows XP, jdk-1.5.0_02
>            Reporter: Michael Pavlov
>         Attachments: COLLECTIONS-239-test.patch
>
>
> In hasPrevious() method of LinkIterator 'next' field is used, that is not correct  - method returns 'true' for the first entry. 'last' field should be used insted.

-- 
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