lucenenet-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jon Palmer (JIRA)" <j...@apache.org>
Subject [jira] Issue Comment Edited: (LUCENENET-97) HitIterator does not correctly implement System.Collections.IEnumerator
Date Wed, 29 Aug 2007 22:50:31 GMT

    [ https://issues.apache.org/jira/browse/LUCENENET-97?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12523727
] 

jonspalmer edited comment on LUCENENET-97 at 8/29/07 3:50 PM:
--------------------------------------------------------------

Right in that usage it clearly works but that entirely broken and not the correct implementation
of IEnumerator:

http://msdn2.microsoft.com/en-us/library/system.collections.ienumerator_members.aspx

it going to create weird issues if I use it like this

           HitIterator iterator = (HitIterator)hits.Iterator(); 
            MessageBox.Show(iterator.Length().ToString()); 
            while (iterator.MoveNext()) 
            { 
                Hit h = (Hit)iterator.Current; 
                MessageBox.Show(h.Get("field")); 
               SomeOtherMethod(iterator);

                iterator.MoveNext(); 
            } 

Now the IEnumerator contract says the SomeOtherMethod should be able to call iterator.Current
as many times as it wants without any effect. With the existing broken implementation you
are force only to every call Current once. 

Btw the Lucene.Net.Search.Hits should clearly implement IEnumerable by implementing the interface
with the simple method:

public IEnumerator GetEnumerator()
{
           return Iterator();
}

then you can do nice replace the ugly while loop above with nice .net things like this:

      foreach(Hit h in hits)
      { 
             MessageBox.Show(h.Get("field")); 
             SomeOtherMethod(h);
      } 



      was (Author: jonspalmer):
    Right in that usage it clearly works but that entirely broken and not the correct implementation
of IEnumerator:

http://msdn2.microsoft.com/en-us/library/system.collections.ienumerator_members.aspx

it going to create weird issues if I use it like this

           HitIterator iterator = (HitIterator)hits.Iterator(); 
            MessageBox.Show(iterator.Length().ToString()); 
            while (iterator.MoveNext()) 
            { 
                Hit h = (Hit)iterator.Current; 
                MessageBox.Show(h.Get("field")); 
               SomeOtherMethod(iterator);

                iterator.MoveNext(); 
            } 

Now the IEnumerator contract says the SomeOtherMethod should be able to call iterator.Current
as many times as it wants without any affect. With the existing broken implementation you
are force only to every call Current once. 

Btw the Lucene.Net.Search.Hits should clearly implement IEnumerable by implementing the interface
with the simple method:

public IEnumerator GetEnumerator()
{
           return Iterator();
}

then you can do nice replace the ugly while loop above with nice .net things like this:

      foreach(Hit h in hits)
      { 
             MessageBox.Show(h.Get("field")); 
             SomeOtherMethod(h);
      } 


  
> HitIterator does not correctly implement System.Collections.IEnumerator
> -----------------------------------------------------------------------
>
>                 Key: LUCENENET-97
>                 URL: https://issues.apache.org/jira/browse/LUCENENET-97
>             Project: Lucene.Net
>          Issue Type: Bug
>         Environment: .NET
>            Reporter: Neal Granroth
>
> method MoveNext() is supposed to increment the position within the list; it does not.
> method Current() is supposed to return the object at the current position, but not change
the position within the list.
> It incorrectly moves to the next position.

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


Mime
View raw message