You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucenenet.apache.org by GitBox <gi...@apache.org> on 2020/09/15 14:36:54 UTC

[GitHub] [lucenenet] clambertus opened a new issue #279: Convert Java Iterator classes to implement IEnumerable

clambertus opened a new issue #279:
URL: https://github.com/apache/lucenenet/issues/279


   <p>The Iterator pattern in Java is equivalent to IEnumerable in .NET.  Classes that were directly ported in Java using the Iterator pattern, cannot be used with Linq or foreach blocks in .NET.</p>
   
   <p><tt>Next()</tt> would be equivalent to .NET's <tt>MoveNext()</tt>, and in the below case, <tt>Term()</tt> would be as .NET's <tt>Current</tt> property.  In cases as below, it will require <tt>TermEnum</tt> to become an abstract class with <tt>Term</tt> and <tt>DocFreq</tt> properties, which would be returned from another class or method that implemented <tt>IEnumerable<TermEnum></tt>.</p>
   
   <div class="preformatted panel" style="border-width: 1px;"><div class="preformattedContent panelContent">
   <pre> 
   	public abstract class TermEnum : IDisposable
   	{
   		public abstract bool Next();
   		public abstract Term Term();
   		public abstract int DocFreq();
   		public abstract void  Close();
   	public abstract void Dispose();
   	}
   </pre>
   </div></div> 
   
   <p>would instead look something like:</p>
   
   <div class="preformatted panel" style="border-width: 1px;"><div class="preformattedContent panelContent">
   <pre> 
   	public class TermFreq
   	{
   		public abstract Term { get; }
   		public abstract int { get; }
   	}
   
   public abstract class TermEnum : IEnumerable<TermFreq>, IDisposable
   {
   // ...
   }
   </pre>
   </div></div>
   
   <p>Keep in mind that it is important that if the class being converted implements <tt>IDisposable</tt>, the class that is enumerating the terms (in this case <tt>TermEnum</tt>) should inherit from both <tt>IEnumerable<T></tt> <b>and</b> <tt>IDisposable</tt>.  This won't be any change to the user, as the compiler automatically calls <tt>IDisposable</tt> when used in a <tt>foreach</tt> loop.</p>
   <i>JIRA link - <a href="https://issues.apache.org/jira/browse/LUCENENET-469">[LUCENENET-469]</a> created by ccurrens</i>


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [lucenenet] NightOwl888 closed issue #279: Convert Java Iterator classes to implement IEnumerable

Posted by GitBox <gi...@apache.org>.
NightOwl888 closed issue #279:
URL: https://github.com/apache/lucenenet/issues/279


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [lucenenet] NightOwl888 commented on issue #279: Convert Java Iterator classes to implement IEnumerable

Posted by GitBox <gi...@apache.org>.
NightOwl888 commented on issue #279:
URL: https://github.com/apache/lucenenet/issues/279#issuecomment-692757842


   This was partially addressed in #341. However, there are still a few iterators to convert, if sensible.
   
   1. `DocIdBitSetIterator` and all subclasses
   2. `CharacterIterator`
   3. `BreakIterator` and all subclasses


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [lucenenet] clambertus edited a comment on issue #279: Convert Java Iterator classes to implement IEnumerable

Posted by GitBox <gi...@apache.org>.
clambertus edited a comment on issue #279:
URL: https://github.com/apache/lucenenet/issues/279#issuecomment-624212396


   <p>GitHub user AndyPook opened a pull request:</p>
   
   <p>    <a href="https://github.com/apache/lucenenet/pull/212" class="external-link" rel="nofollow">https://github.com/apache/lucenenet/pull/212</a></p>
   
   <p>    <a href="https://issues.apache.org/jira/browse/GH-469" title="Convert Java Iterator classes to implement IEnumerable<T>" class="issue-link" data-issue-key="GH-469">GH-469</a> - enumerables</p>
   
   <p>    See <a href="https://issues.apache.org/jira/projects/LUCENENET/issues/GH-469" class="external-link" rel="nofollow">https://issues.apache.org/jira/projects/LUCENENET/issues/GH-469</a> for background.</p>
   
   <p>    This is an early stage proposal for implementing IEnumerable<T> on various "Enum" types. To enable `foreach` and linq style operators.</p>
   
   <p>    This prototype provides `EnumEnumerator<T>` as a helper. It can be used in various ways to make the implementation of `IEnumerable<T>` more straightforward.</p>
   
   <p>    I have modified `IBytesRefIterator` and `TermsEnum` to add `IEnumerable<BytesRef>` and therefore to all of it's descendants.</p>
   
   <p>    The test (such as it is) demonstrates retrieving a `TermsEnum` from a reader. Then using `foreach` and a simple `.Count()` linq operator.</p>
   
   <p>    If this approach is acceptable it ought to be adaptable to other Enum types</p>
   
   <p>You can merge this pull request into a Git repository by running:</p>
   
   <p>    $ git pull <a href="https://github.com/AndyPook/lucenenet" class="external-link" rel="nofollow">https://github.com/AndyPook/lucenenet</a> <a href="https://issues.apache.org/jira/browse/GH-469" title="Convert Java Iterator classes to implement IEnumerable<T>" class="issue-link" data-issue-key="GH-469">GH-469</a></p>
   
   <p>Alternatively you can review and apply these changes as the patch at:</p>
   
   <p>    <a href="https://github.com/apache/lucenenet/pull/212.patch" class="external-link" rel="nofollow">https://github.com/apache/lucenenet/pull/212.patch</a></p>
   
   <p>To close this pull request, make a commit to your master/trunk branch<br/>
   with (at least) the following in the commit message:</p>
   
   <p>    This closes #212</p>
   
   <hr />
   <p>commit 008df498bcba7e9940ca97efc83d656ddb03b2c3<br/>
   Author: Andy Pook <an...@gmail.com><br/>
   Date:   2017-08-14T21:32:45Z</p>
   
   <p>    simple editorconfig</p>
   
   <p>    ensures spaces for indent</p>
   
   <p>commit 59646be0cf8fbc7e8ad64f395f451a11aca57fc6<br/>
   Author: Andy Pook <an...@gmail.com><br/>
   Date:   2017-08-14T21:34:48Z</p>
   
   <p>    add EnumEnumerator helper</p>
   
   <p>commit 526ddaf8c837f82cd141324e922372155914701b<br/>
   Author: Andy Pook <an...@gmail.com><br/>
   Date:   2017-08-14T21:35:32Z</p>
   
   <p>    add IEnumerable to TermsEnum/IBytesRefArray</p>
   
   <p>commit 456df8e8347ef67055b712722b50cc3b1bbf26cc<br/>
   Author: Andy Pook <an...@gmail.com><br/>
   Date:   2017-08-14T21:36:54Z</p>
   
   <p>    add header, fix usings</p>
   
   <p>commit 1a1c25da7cbcd112d12d6c418c669786cdf4088c<br/>
   Author: Andy Pook <an...@gmail.com><br/>
   Date:   2017-08-14T22:25:15Z</p>
   
   <p>    add example test</p>
   
   <hr />
   <i>by githubbot</i>


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org