01: package org.ontoware.rdfreactor.runtime;
02:
03: import org.ontoware.aifbcommons.collection.ClosableIterator;
04: import org.ontoware.rdf2go.model.Statement;
05:
06: public class ProjectingIterator<T> implements ClosableIterator<T> {
07:
08: public static enum projection {
09: Subject, Predicate, Object, Context
10: }
11:
12: private ClosableIterator<Statement> it;
13: private projection p;
14:
15: public ProjectingIterator(ClosableIterator<Statement> it,
16: projection p) {
17: this .it = it;
18: this .p = p;
19: }
20:
21: public void close() {
22: it.close();
23: }
24:
25: public boolean hasNext() {
26: return it.hasNext();
27: }
28:
29: @SuppressWarnings("unchecked")
30: public T next() {
31: Statement statement = it.next();
32: switch (p) {
33: case Subject:
34: return (T) statement.getSubject();
35: case Predicate:
36: return (T) statement.getPredicate();
37: case Object:
38: return (T) statement.getObject();
39: case Context:
40: return (T) statement.getContext();
41: }
42: throw new AssertionError("never happens");
43: }
44:
45: public void remove() {
46: it.remove();
47: }
48:
49: }
|