Skip to content

Instantly share code, notes, and snippets.

@keyvan
Created April 16, 2012 02:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save keyvan/2396135 to your computer and use it in GitHub Desktop.
Save keyvan/2396135 to your computer and use it in GitHub Desktop.
A piece of Java code
public class RenamedClass extends Iterator {
protected Iterator iterator;
protected Predicate[] predicates;
protected Tuple currentTuple;
public RenamedClass(Iterator iter, Predicate... preds) {
this.schema = iter.schema;
this.iterator = iter;
this.predicates = preds;
this.currentTuple = null;
}
public void explain(int depth) {
indent(depth);
System.out.print("What? ");
for (int i = 0; i < this.predicates.length - 1; i++)
System.out.print(this.predicates[i].toString() + " OR ");
System.out.println(this.predicates[(this.predicates.length - 1)]);
this.iterator.explain(depth + 1);
}
public void restart() {
this.iterator.restart();
this.currentTuple = null;
}
public boolean isOpen() {
return this.iterator != null;
}
public void close() {
if (this.iterator != null) {
this.iterator.close();
this.iterator = null;
}
}
public boolean hasNext() {
while (this.iterator.hasNext()) {
this.currentTuple = this.iterator.getNext();
for (int i = 0; i < this.predicates.length; i++)
if (this.predicates[i].evaluate(this.currentTuple))
return true;
}
return false;
}
public Tuple getNext() {
if (this.currentTuple == null)
throw new IllegalStateException("No next tuple.");
return this.currentTuple;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment