ClosableIterable<Triple> triples = graph.find(ANY_TRIPLE);
try {
for (Triple triple : triples) {
System.out.println("Graph: " + triple);
}
} finally {
triples.iterator().close();
}
try {
for (Triple triple : triples) {
System.out.println("Graph: " + triple);
}
} finally {
triples.iterator().close();
}
Using "ClosableIterators.with" this becomes:
with(graph.find(ANY_TRIPLE), new Function<Void, ClosableIterable<Triple>>() {
public Void apply(ClosableIterable<Triple> object) {
for (Triple triple : object) {
System.out.println("Graph: " + triple);
}
return null;
}
});
It's typically one line less but that's not that much of an improvement.
public Void apply(ClosableIterable<Triple> object) {
for (Triple triple : object) {
System.out.println("Graph: " + triple);
}
return null;
}
});