1 10 package com.hp.hpl.jena.reasoner.rulesys.impl.oldCode; 11 12 import com.hp.hpl.jena.reasoner.rulesys.impl.StateFlag; 13 import com.hp.hpl.jena.util.iterator.ClosableIterator; 14 import org.apache.commons.logging.Log; 15 import org.apache.commons.logging.LogFactory; 16 17 28 public class GoalState { 29 30 31 protected ClosableIterator tripleMatches; 32 33 34 protected GoalResults results; 35 36 37 protected int solutionPointer = 0; 38 39 static Log logger = LogFactory.getLog(GoalState.class); 40 41 49 public GoalState(ClosableIterator tripleMatches, GoalResults results) { 50 this.tripleMatches = tripleMatches; 51 this.results = results; 52 } 53 54 57 public GoalResults getGoalResultsEntry() { 58 return results; 59 } 60 61 68 public Object next() { 69 if (tripleMatches != null) { 70 if (tripleMatches.hasNext()) { 71 return tripleMatches.next(); 72 } else { 73 tripleMatches = null; 74 } 75 } 76 if (solutionPointer < results.numResults()) { 77 return results.getResult(solutionPointer++); 78 } else if (results.isComplete() ){ 79 return StateFlag.FAIL; 80 } else { 81 return StateFlag.SUSPEND; 83 } 84 } 85 86 90 public boolean couldProcess() { 91 if (tripleMatches != null && tripleMatches.hasNext()) return true; 92 if (results.started && solutionPointer < results.numResults()) return true; 93 if (results.isComplete) return true; 94 return false; 95 } 96 97 100 public void close() { 101 if (tripleMatches != null) { 102 tripleMatches.close(); 103 tripleMatches = null; 104 } 105 } 106 107 110 public String toString() { 111 return "GoalState(" + results.goal.toString() + ")"; 112 } 113 114 } 115 116 117 118 | Popular Tags |