Created
April 16, 2012 02:44
-
-
Save keyvan/2396135 to your computer and use it in GitHub Desktop.
A piece of Java code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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