/** DFS over all parent states to find a match. */ public GoalState findGoalStateByGoal(Goal<?> goal) { // TODO: handle wrap-around (though it's not likely to occur anyway) int mark = nextVisitationMark++; List<GoalState> stack = newArrayListWithCapacity(activeGoalStates.size()); stack.add(this); this.visitationMark = mark; while (!stack.isEmpty()) { GoalState state = stack.remove(stack.size() - 1); if (state.goal.hashCode() == goal.hashCode() && state.goal.equals(goal)) return state; for (GoalState parent : state.parentStates) if (parent.visitationMark < mark) { parent.visitationMark = mark; stack.add(parent); } } return null; }
@Override public int hashCode() { int result = goal != null ? goal.hashCode() : 0; result = 31 * result + (job != null ? job.hashCode() : 0); return result; }