Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Skipping over your Iterator/Iterable confusion (and Iterable is basically an Iterator factory... so you need to write an Iterator either way), I think you mean something like this:</p> <pre><code>Iterator&lt;Test&gt; getTests(final Map&lt;String,Test&gt; testMap, final Set&lt;String&gt; strings) { return new Iterator&lt;Test&gt;() { private final Iterator&lt;String&gt; keyIter = strings.iterator(); private String lastKey; public boolean hasNext() { return keyIter.hasNext(); } public Test next() { lastKey = keyIter.next(); return testMap.get(lastKey); } public void remove() { testMap.remove(lastKey); } }; } </code></pre> <p>And if you want to return an Iterable, well, that just has to be a factory for those:</p> <pre><code>Iterable&lt;Test&gt; getTests(final Map&lt;String,Test&gt; testMap, final Set&lt;String&gt; strings) { return new Iterable&lt;Test&gt;() { public Iterator&lt;Test&gt; iterator() { return new Iterator&lt;Test&gt;() { private final Iterator&lt;String&gt; keyIter = strings.iterator(); private String lastKey; public boolean hasNext() { return keyIter.hasNext(); } public Test next() { lastKey = keyIter.next(); return testMap.get(lastKey); } public void remove() { testMap.remove(lastKey); } }; } }; } </code></pre> <p>For extra credit, you can parameterise this method itself and have a generic way of iterating over a selection from a map:</p> <pre><code>Map&lt;String, Action&gt; map; Set&lt;String&gt; keys; for (Action x : filterMap(map, keys)) { } </code></pre>
    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. 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