bdi4jade
Changes
bdi-jade/src/bdi4jade/event/BeliefEvent.java 35(+25 -10)
bdi-jade/src/bdi4jade/event/GoalEvent.java 50(+45 -5)
bdi-jade/src/bdi4jade/event/package-info.java 104(+31 -73)
bdi-jade/src/bdi4jade/goal/CompositeGoal.java 24(+12 -12)
bdi-jade/src/bdi4jade/goal/GoalStatus.java 23(+22 -1)
Details
diff --git a/bdi-jade/src/bdi4jade/belief/BeliefBase.java b/bdi-jade/src/bdi4jade/belief/BeliefBase.java
index c4d5d7c..cafff19 100644
--- a/bdi-jade/src/bdi4jade/belief/BeliefBase.java
+++ b/bdi-jade/src/bdi4jade/belief/BeliefBase.java
@@ -247,7 +247,7 @@ public class BeliefBase implements Serializable {
*/
protected void notifyBeliefChanged(BeliefEvent beliefChanged) {
for (BeliefListener beliefListener : beliefListeners) {
- beliefListener.update(beliefChanged);
+ beliefListener.eventOccurred(beliefChanged);
}
for (Capability part : capability.getPartCapabilities()) {
part.getBeliefBase().notifyBeliefChanged(beliefChanged);
bdi-jade/src/bdi4jade/event/BeliefEvent.java 35(+25 -10)
diff --git a/bdi-jade/src/bdi4jade/event/BeliefEvent.java b/bdi-jade/src/bdi4jade/event/BeliefEvent.java
index c594399..b6896c0 100644
--- a/bdi-jade/src/bdi4jade/event/BeliefEvent.java
+++ b/bdi-jade/src/bdi4jade/event/BeliefEvent.java
@@ -16,7 +16,7 @@
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// To contact the authors:
-// http://inf.ufrgs.br/~ingridnunes/bdi4jade/
+// http://inf.ufrgs.br/prosoft/bdi4jade/
//
//----------------------------------------------------------------------------
@@ -56,20 +56,20 @@ public class BeliefEvent implements AgentAction {
}
/**
- * Creates a Belief Changed.
+ * Creates a belief event.
*
* @param belief
- * the belief that has changed.
+ * the belief over which the event has occurred.
*/
public BeliefEvent(Belief<?> belief) {
this(belief, Action.BELIEF_UPDATED);
}
/**
- * Creates a Belief Changed.
+ * Creates a belief event.
*
* @param belief
- * the belief that has changed.
+ * the belief over which the event has occurred.
* @param action
* the action performed.
*/
@@ -78,10 +78,10 @@ public class BeliefEvent implements AgentAction {
}
/**
- * Creates a Belief Changed.
+ * Creates a belief event.
*
* @param belief
- * the belief that has changed.
+ * the belief over which the event has occurred.
* @param action
* the action performed.
* @param args
@@ -94,6 +94,8 @@ public class BeliefEvent implements AgentAction {
}
/**
+ * Returns the action performed.
+ *
* @return the action
*/
public Action getAction() {
@@ -101,6 +103,8 @@ public class BeliefEvent implements AgentAction {
}
/**
+ * Returns arguments associated with the action performed.
+ *
* @return the args
*/
public Object getArgs() {
@@ -108,6 +112,8 @@ public class BeliefEvent implements AgentAction {
}
/**
+ * Returns the belief over which the event has occurred.
+ *
* @return the belief
*/
public Belief<?> getBelief() {
@@ -115,29 +121,38 @@ public class BeliefEvent implements AgentAction {
}
/**
+ * Sets the action performed.
+ *
* @param action
- * the action to set
+ * the action to set.
*/
public void setAction(Action action) {
this.action = action;
}
/**
+ * Sets the arguments associated with the action performed.
+ *
* @param args
- * the args to set
+ * the args to set.
*/
public void setArgs(Object args) {
this.args = args;
}
/**
+ * Sets the belief over which the event has occurred.
+ *
* @param belief
- * the belief to set
+ * the belief to set.
*/
public void setBelief(Belief<?> belief) {
this.belief = belief;
}
+ /**
+ * @see java.lang.Object#toString()
+ */
@Override
public String toString() {
StringBuffer sb = new StringBuffer();
diff --git a/bdi-jade/src/bdi4jade/event/BeliefListener.java b/bdi-jade/src/bdi4jade/event/BeliefListener.java
index f6b1246..40ea6fd 100644
--- a/bdi-jade/src/bdi4jade/event/BeliefListener.java
+++ b/bdi-jade/src/bdi4jade/event/BeliefListener.java
@@ -16,7 +16,7 @@
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// To contact the authors:
-// http://inf.ufrgs.br/~ingridnunes/bdi4jade/
+// http://inf.ufrgs.br/prosoft/bdi4jade/
//
//----------------------------------------------------------------------------
@@ -25,19 +25,20 @@ package bdi4jade.event;
import java.util.EventListener;
/**
- * This interface defined the method that a belief listener should implement. A
- * belief listener can be notified about changes in beliefs, when it subscribed
- * to a class that can notify updates.
+ * This interface defines the method that a belief listener should implement. A
+ * belief listener is notified about changes in beliefs of a belief base, when
+ * it is subscribed to the belief base.
*
- * @author ingridnunes
+ * @author Ingrid Nunes
*/
public interface BeliefListener extends EventListener {
/**
- * Updates the listener according to a change in a belief.
+ * Notifies the listener that a {@link BeliefEvent} occurred.
*
* @param beliefEvent
+ * the belief event that occurred.
*/
- public void update(BeliefEvent beliefEvent);
+ public void eventOccurred(BeliefEvent beliefEvent);
}
bdi-jade/src/bdi4jade/event/GoalEvent.java 50(+45 -5)
diff --git a/bdi-jade/src/bdi4jade/event/GoalEvent.java b/bdi-jade/src/bdi4jade/event/GoalEvent.java
index 01514be..2fd00f9 100644
--- a/bdi-jade/src/bdi4jade/event/GoalEvent.java
+++ b/bdi-jade/src/bdi4jade/event/GoalEvent.java
@@ -16,7 +16,7 @@
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// To contact the authors:
-// http://inf.ufrgs.br/~ingridnunes/bdi4jade/
+// http://inf.ufrgs.br/prosoft/bdi4jade/
//
//----------------------------------------------------------------------------
@@ -24,17 +24,19 @@ package bdi4jade.event;
import jade.content.AgentAction;
import bdi4jade.goal.Goal;
+import bdi4jade.goal.GoalStatus;
/**
* This class represents an event performed over a goal.
*
- * @author ingrid
+ * @author Ingrid Nunes
*/
public class GoalEvent implements AgentAction {
private static final long serialVersionUID = 8315524257754153164L;
protected Goal goal;
+ protected GoalStatus status;
/**
* Default constructor.
@@ -48,24 +50,62 @@ public class GoalEvent implements AgentAction {
*
* @param goal
* the goal of this event.
+ * @param status
+ * the goal status.
*/
- public GoalEvent(Goal goal) {
+ public GoalEvent(Goal goal, GoalStatus status) {
this.goal = goal;
+ this.status = status;
}
/**
- * @return the goal
+ * Returns the goal associated with this event.
+ *
+ * @return the goal associated with this event.
*/
public Goal getGoal() {
return goal;
}
/**
+ * Returns the goal status.
+ *
+ * @return the status.
+ */
+ public GoalStatus getStatus() {
+ return status;
+ }
+
+ /**
+ * Sets the goal associated with this event.
+ *
* @param goal
- * the goal to set
+ * the goal to set.
*/
public void setGoal(Goal goal) {
this.goal = goal;
}
+ /**
+ * Sets the goal status.
+ *
+ * @param status
+ * the status to set.
+ */
+ public void setStatus(GoalStatus status) {
+ this.status = status;
+ }
+
+ /**
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString() {
+ StringBuffer sb = new StringBuffer();
+ sb.append(getClass().getSimpleName()).append("\n");
+ sb.append("Goal: ").append(goal).append("\n");
+ sb.append("Status: ").append(status);
+ return sb.toString();
+ }
+
}
diff --git a/bdi-jade/src/bdi4jade/event/GoalListener.java b/bdi-jade/src/bdi4jade/event/GoalListener.java
index 3b71760..1c0b72c 100644
--- a/bdi-jade/src/bdi4jade/event/GoalListener.java
+++ b/bdi-jade/src/bdi4jade/event/GoalListener.java
@@ -16,7 +16,7 @@
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// To contact the authors:
-// http://inf.ufrgs.br/~ingridnunes/bdi4jade/
+// http://inf.ufrgs.br/prosoft/bdi4jade/
//
//----------------------------------------------------------------------------
@@ -25,19 +25,19 @@ package bdi4jade.event;
import java.util.EventListener;
/**
- * This interface defined the method that a goal listener should implement. A
- * goal listener can be notified about changes in goal, when it subscribed to a
- * class that can notify updates.
+ * This interface defines the method that a goal listener should implement. A
+ * goal listener can be notified about changes in goals, when it subscribed to a
+ * class that can notify events about goals.
*
- * @author ingrid
+ * @author Ingrid Nunes
*/
public interface GoalListener extends EventListener {
/**
- * Notifies the listener that the goal was performed.
+ * Notifies the listener that a goal that was performed.
*
* @param event
- * the performed goal event.
+ * the goal event that occurred.
*/
public void goalPerformed(GoalEvent event);
bdi-jade/src/bdi4jade/goal/CompositeGoal.java 24(+12 -12)
diff --git a/bdi-jade/src/bdi4jade/goal/CompositeGoal.java b/bdi-jade/src/bdi4jade/goal/CompositeGoal.java
index f66bb40..f775f9b 100644
--- a/bdi-jade/src/bdi4jade/goal/CompositeGoal.java
+++ b/bdi-jade/src/bdi4jade/goal/CompositeGoal.java
@@ -25,7 +25,7 @@ package bdi4jade.goal;
import java.util.Collection;
import java.util.List;
-import bdi4jade.event.GoalFinishedEvent;
+import bdi4jade.event.GoalEvent;
/**
* This class represents a goal that is a composition of other goals (subgoals).
@@ -39,7 +39,7 @@ public abstract class CompositeGoal implements Goal {
private static final long serialVersionUID = -8253189774672851571L;
protected List<Goal> completedGoals;
- protected GoalFinishedEvent failedGoal;
+ protected GoalEvent failedGoal;
protected final Collection<Goal> goals;
/**
@@ -54,8 +54,8 @@ public abstract class CompositeGoal implements Goal {
/**
* Instantiates a CompositeGoal with the provided goals array. A
- * {@link Collection} is instantiated by the method {@link #createGoals(int)}
- * and is initialized with the provided goals.
+ * {@link Collection} is instantiated by the method
+ * {@link #createGoals(int)} and is initialized with the provided goals.
*
* @param goals
* the goals that compose this goal.
@@ -87,15 +87,15 @@ public abstract class CompositeGoal implements Goal {
}
/**
- * Returns the goal that could not be achieved, if any. If it is not
- * possible to achieve one of the goals, the remaining goals that were not
- * completed yet will not be achieved. If there are goals part of this
- * composite goal that are being tried to be achieved, they become no longer
- * desired.
+ * Returns the goal event associated with a goal that could not be achieved,
+ * if any. If it is not possible to achieve one of the goals, the remaining
+ * goals that were not completed yet will not be achieved. If there are
+ * goals part of this composite goal that are being tried to be achieved,
+ * they become no longer desired.
*
* @return the goal that failed.
*/
- public GoalFinishedEvent getFailedGoal() {
+ public GoalEvent getFailedGoal() {
return failedGoal;
}
@@ -119,12 +119,12 @@ public abstract class CompositeGoal implements Goal {
}
/**
- * Sets the goal that failed.
+ * Sets the goal event associated with the goal that failed.
*
* @param failedGoal
* the failedGoal to set.
*/
- public void setFailedGoal(GoalFinishedEvent failedGoal) {
+ public void setFailedGoal(GoalEvent failedGoal) {
this.failedGoal = failedGoal;
}
bdi-jade/src/bdi4jade/goal/GoalStatus.java 23(+22 -1)
diff --git a/bdi-jade/src/bdi4jade/goal/GoalStatus.java b/bdi-jade/src/bdi4jade/goal/GoalStatus.java
index 6e42137..68a8178 100644
--- a/bdi-jade/src/bdi4jade/goal/GoalStatus.java
+++ b/bdi-jade/src/bdi4jade/goal/GoalStatus.java
@@ -32,6 +32,27 @@ import bdi4jade.core.Intention;
*/
public enum GoalStatus {
- ACHIEVED, NO_LONGER_DESIRED, PLAN_FAILED, TRYING_TO_ACHIEVE, UNACHIEVABLE, WAITING;
+ ACHIEVED(true), NO_LONGER_DESIRED(true), PLAN_FAILED, TRYING_TO_ACHIEVE, UNACHIEVABLE(
+ true), WAITING;
+
+ private boolean isFinished;
+
+ private GoalStatus() {
+ this(false);
+ }
+
+ private GoalStatus(boolean isFinished) {
+ this.isFinished = isFinished;
+ }
+
+ /**
+ * Indicates whether this status corresponds to a status in which the goal
+ * has finished, that is, the agent does not have the goal anymore.
+ *
+ * @return true if the status is a status of finished goal, false otherwise.
+ */
+ public boolean isFinished() {
+ return isFinished;
+ }
}