bdi4jade

Added method: hasGoal

9/12/2014 7:01:35 PM

Details

diff --git a/bdi-jade/src/bdi4jade/core/AbstractBDIAgent.java b/bdi-jade/src/bdi4jade/core/AbstractBDIAgent.java
index 6fd026c..749d3ab 100644
--- a/bdi-jade/src/bdi4jade/core/AbstractBDIAgent.java
+++ b/bdi-jade/src/bdi4jade/core/AbstractBDIAgent.java
@@ -238,6 +238,7 @@ public abstract class AbstractBDIAgent extends Agent implements BDIAgent {
 
 	}
 
+	private static final Log log = LogFactory.getLog(AbstractBDIAgent.class);
 	private static final long serialVersionUID = -841774495336214256L;
 
 	private final Collection<Intention> agentIntentions;
@@ -248,7 +249,6 @@ public abstract class AbstractBDIAgent extends Agent implements BDIAgent {
 	private Set<Capability> capabilities;
 	private AgentDeliberationFunction deliberationFunction;
 	protected final List<GoalListener> goalListeners;
-	protected final Log log;
 	private AgentOptionGenerationFunction optionGenerationFunction;
 	private AgentPlanSelectionStrategy planSelectionStrategy;
 	private Map<Class<? extends Capability>, Set<Capability>> restrictedAccessOwnersMap;
@@ -258,7 +258,6 @@ public abstract class AbstractBDIAgent extends Agent implements BDIAgent {
 	 * Default constructor.
 	 */
 	public AbstractBDIAgent() {
-		this.log = LogFactory.getLog(this.getClass());
 		this.bdiInterpreter = new BDIInterpreter(this);
 		this.capabilities = new HashSet<>();
 		this.restrictedAccessOwnersMap = new HashMap<>();
@@ -389,7 +388,7 @@ public abstract class AbstractBDIAgent extends Agent implements BDIAgent {
 				restart();
 				return intention;
 			} else {
-				log.warn("This agent already has goal: " + goal);
+				log.info("This agent already has goal: " + goal);
 				if (goalListener != null) {
 					intention.addGoalListener(goalListener);
 				}
@@ -624,6 +623,14 @@ public abstract class AbstractBDIAgent extends Agent implements BDIAgent {
 	}
 
 	/**
+	 * @see bdi4jade.core.BDIAgent#hasGoal(bdi4jade.goal.Goal)
+	 */
+	@Override
+	public boolean hasGoal(Goal goal) {
+		return allIntentions.get(goal) != null;
+	}
+
+	/**
 	 * This method initializes the BDI agent. It is invoked by the
 	 * {@link #setup()} method. This is an empty method that should be overriden
 	 * by subclasses.
diff --git a/bdi-jade/src/bdi4jade/core/BDIAgent.java b/bdi-jade/src/bdi4jade/core/BDIAgent.java
index 9491c06..cef7a00 100644
--- a/bdi-jade/src/bdi4jade/core/BDIAgent.java
+++ b/bdi-jade/src/bdi4jade/core/BDIAgent.java
@@ -355,6 +355,15 @@ public interface BDIAgent {
 	public Set<Softgoal> getSoftgoals();
 
 	/**
+	 * Checks if this agent has a given goal.
+	 * 
+	 * @param goal
+	 *            the goal to be checked.
+	 * @return true if this agent has the goal, false otherwise.
+	 */
+	public boolean hasGoal(Goal goal);
+
+	/**
 	 * @see Agent#here()
 	 */
 	public Location here();