1 10 package com.hp.hpl.jena.reasoner.rulesys.impl.oldCode; 11 12 import com.hp.hpl.jena.reasoner.TriplePattern; 13 import com.hp.hpl.jena.reasoner.rulesys.impl.StateFlag; 14 15 import java.util.Iterator ; 16 17 26 public class TopGoalIterator implements Iterator { 27 28 29 GoalState goalState; 30 31 32 Object lookAhead; 33 34 35 BRuleEngine engine; 36 37 40 public TopGoalIterator(BRuleEngine engine, TriplePattern goal) { 41 this.engine = engine; 42 this.goalState = engine.findGoal(goal); 43 moveForward(); 44 } 45 46 50 private void moveForward() { 51 lookAhead = goalState.next(); 52 if (lookAhead == StateFlag.SUSPEND) { 53 if (engine.next(goalState) != null) { 54 lookAhead = goalState.next(); 55 } else { 56 lookAhead = null; 57 } 58 } else if (lookAhead == StateFlag.FAIL) { 59 lookAhead = null; 60 } 61 if (lookAhead == null) close(); 62 } 63 64 67 public void close() { 68 goalState.close(); 69 engine.halt(); 70 } 71 72 75 public boolean hasNext() { 76 return (lookAhead != null); 77 } 78 79 82 public Object next() { 83 Object result = lookAhead; 84 moveForward(); 85 return result; 86 } 87 88 91 public void remove() { 92 throw new UnsupportedOperationException (); 93 } 94 95 } 96 97 98 | Popular Tags |