1 /*********************************************************************
2 Copyright 2012, Ralph Ronnquist.
4 This file is part of GORITE.
6 GORITE is free software: you can redistribute it and/or modify it
7 under the terms of the Lesser GNU General Public License as published
8 by the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 GORITE is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 License for more details.
16 You should have received a copy of the Lesser GNU General Public
17 License along with GORITE. If not, see <http://www.gnu.org/licenses/>.
18 **********************************************************************/
20 package com.intendico.gorite;
22 import com.intendico.data.Query;
23 import com.intendico.data.Ref;
24 import com.intendico.gorite.Goal.States;
26 import java.util.HashSet;
27 import java.util.Iterator;
28 import java.util.Vector;
31 * A FailGoal is achieved by means of failing any sub goal, which are
32 * attempted in sequence. The goal fails when and if all sub goals
33 * have been attempted and succeeded. In particular, a fail goal
34 * without sub goals always fail immediately, and is a way to induce
35 * failure. Failure may also be induced by tasks, which can succeed or
40 public class FailGoal extends SequenceGoal {
45 public FailGoal(String n,Goal [] sg) {
50 * Convenience constructor without sub goals.
52 public FailGoal(String n) {
57 * Creates and returns an instance object for achieving
60 public Instance instantiate(String head,Data d) {
61 return new FailInstance( head );
65 * Represents the process of achieving a FailGoal
67 public class FailInstance extends SequenceInstance {
72 public FailInstance(String h) {
77 * Process all sub goals in sequence, then reverse {@link
78 * States#PASSED} and {@link States#FAILED}.
80 public States action(String head,Data d)
81 throws LoopEndException, ParallelEndException {
82 States s = super.action( head, d );
83 if ( s == States.PASSED )
85 if ( s == States.FAILED )