Iterator/Iterable の混乱をスキップします (そして、Iterable は基本的に Iterator ファクトリです... そのため、いずれかの方法で Iterator を記述する必要があります)、次のような意味だと思います。
Iterator<Test> getTests(final Map<String,Test> testMap, final Set<String> strings) {
return new Iterator<Test>() {
private final Iterator<String> 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); }
};
}
そして、Iterable を返したい場合は、それらのファクトリである必要があります。
Iterable<Test> getTests(final Map<String,Test> testMap, final Set<String> strings) {
return new Iterable<Test>() {
public Iterator<Test> iterator() {
return new Iterator<Test>() {
private final Iterator<String> 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); }
};
}
};
}
追加のクレジットとして、このメソッド自体をパラメーター化し、マップからの選択を反復する一般的な方法を使用できます。
Map<String, Action> map;
Set<String> keys;
for (Action x : filterMap(map, keys)) {
}