Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The two options I know of is <a href="https://code.google.com/p/infomancers-collections/" rel="noreferrer">Aviad Ben Dov's infomancers-collections library from 2007</a> and <a href="http://svn.jimblackler.net/jimblackler/trunk/IdeaProjects/YieldAdapter/" rel="noreferrer">Jim Blackler's YieldAdapter library from 2008</a> (which is also mentioned in the other answer).</p> <p>Both will allow you to write code with <code>yield return</code>-like construct in Java, so both will satisfy your request. The notable differences between the two are:</p> <h3>Mechanics</h3> <p>Aviad's library is using bytecode manipulation while Jim's uses multithreading. Depending on your needs, each may have its own advantages and disadvantages. It's likely Aviad's solution is faster, while Jim's is more portable (for example, I don't think Aviad's library will work on Android).</p> <h3>Interface</h3> <p>Aviad's library has a cleaner interface - here's an example:</p> <pre><code>Iterable&lt;Integer&gt; it = new Yielder&lt;Integer&gt;() { @Override protected void yieldNextCore() { for (int i = 0; i &lt; 10; i++) { yieldReturn(i); if (i == 5) yieldBreak(); } } }; </code></pre> <p>While Jim's is way more complicated, requiring you to <code>adept</code> a generic <code>Collector</code> which has a <code>collect(ResultHandler)</code> method... ugh. However, you could use something like <a href="https://github.com/domlachowicz/java-generators" rel="noreferrer">this wrapper around Jim's code by Zoom Information</a> which greatly simplifies that:</p> <pre><code>Iterable&lt;Integer&gt; it = new Generator&lt;Integer&gt;() { @Override protected void run() { for (int i = 0; i &lt; 10; i++) { yield(i); if (i == 5) return; } } }; </code></pre> <h3>License</h3> <p>Aviad's solution is BSD.</p> <p>Jim's solution is public domain, and so is its wrapper mentioned above.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload