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.addon;
22 import com.intendico.gorite.*;
23 import com.intendico.gorite.Performer.TodoGroup;
24 import java.util.Vector;
27 * This plan is a {@link TodoGroup} meta goal handler to cycle through
28 * the stacked intentions, by putting the top one last, except when it
29 * is newly added. The actual goal name for the meta goal is given at
30 * construction time, and unless it is the default {@link
31 * Performer#TODOGROUP_META_GOAL}, the actual {@link TodoGroup}
32 * instances to be managed by this goal need to be set up explicitly
33 * using {@link Performer#addTodoGroup}.
37 * new Performer( "example" ) {
38 * addGoal( new TodoGroupRoundRobin( "round robin todogroup meta goal" ) );
39 * addTodoGroup( "example", "round robin todogroup meta goal" );
43 * <p> Another usage example, to make it the default todogroup meta goal:
45 * new Performer( "example" ) {
46 * addGoal( new TodoGroupRoundRobin( TODOGROUP_META_GOAL ) );
50 public class TodoGroupRoundRobin extends Goal {
53 * Constructor for providing {@link TodoGroup} management through
54 * the named meta goal.
56 public TodoGroupRoundRobin(String name) {
61 * Overrides {@link Goal#execute} to provide the meta goal
62 * implementation. This expects a {@link Data} object with
63 * elements named by {@link Performer#TODOGROUP}, "coming" and
64 * "top". The implementation cycles the todogroup unless the "top"
65 * intention is in the "coming" vector.
67 public States execute(Data d) {
68 TodoGroup todogroup = (TodoGroup) d.getValue( Performer.TODOGROUP );
69 Vector coming = (Vector) d.getValue( "coming" );
70 Goal.Instance top = (Goal.Instance) d.getValue( "top" );
71 if ( ! coming.contains( top ) )