bdi4jade

Added clone() method to beliefs.

9/6/2014 12:12:18 AM

Details

diff --git a/bdi-jade/src/bdi4jade/belief/AbstractBelief.java b/bdi-jade/src/bdi4jade/belief/AbstractBelief.java
index 263f93b..09842ec 100644
--- a/bdi-jade/src/bdi4jade/belief/AbstractBelief.java
+++ b/bdi-jade/src/bdi4jade/belief/AbstractBelief.java
@@ -95,6 +95,16 @@ public abstract class AbstractBelief<K, V> extends MetadataElementImpl
 	}
 
 	/**
+	 * @see java.lang.Object#clone()
+	 */
+	@Override
+	public Object clone() throws CloneNotSupportedException {
+		AbstractBelief<?, ?> clone = (AbstractBelief<?, ?>) super.clone();
+		clone.beliefBases.clear();
+		return clone;
+	}
+
+	/**
 	 * Returns true of the object is a belief and has the same name of this
 	 * belief.
 	 * 
diff --git a/bdi-jade/src/bdi4jade/belief/Belief.java b/bdi-jade/src/bdi4jade/belief/Belief.java
index 05960d6..7fa5bf1 100644
--- a/bdi-jade/src/bdi4jade/belief/Belief.java
+++ b/bdi-jade/src/bdi4jade/belief/Belief.java
@@ -47,7 +47,8 @@ import bdi4jade.core.MetadataElement;
  * 
  * @author Ingrid Nunes
  */
-public interface Belief<K, V> extends MetadataElement, Serializable, Concept {
+public interface Belief<K, V> extends MetadataElement, Serializable, Concept,
+		Cloneable {
 
 	/**
 	 * Adds a belief base that contains this belief. The agent whose capability
@@ -59,6 +60,17 @@ public interface Belief<K, V> extends MetadataElement, Serializable, Concept {
 	public void addBeliefBase(BeliefBase beliefBase);
 
 	/**
+	 * Clones a belief. This may be particularly useful to share this belief
+	 * with other agents, copying the information of this belief without sharing
+	 * other information, such as belief bases associated with a belief.
+	 * 
+	 * @return the clone of this belief.
+	 * @throws CloneNotSupportedException
+	 *             if an implementation of a belief does not support clone.
+	 */
+	public Object clone() throws CloneNotSupportedException;
+
+	/**
 	 * Returns the belief bases with which this belief is associated.
 	 * 
 	 * @return the belief bases.
diff --git a/bdi-jade/src/bdi4jade/belief/PersistentBelief.java b/bdi-jade/src/bdi4jade/belief/PersistentBelief.java
index 1e1a02c..86c4e54 100644
--- a/bdi-jade/src/bdi4jade/belief/PersistentBelief.java
+++ b/bdi-jade/src/bdi4jade/belief/PersistentBelief.java
@@ -23,9 +23,9 @@
 package bdi4jade.belief;
 
 /**
- * This class extends the {@link Belief} and represents a persistent belief,
- * which is persisted in a permanent memory. This class has not been implemented
- * yet.
+ * This class extends the {@link AbstractBelief} and represents a persistent
+ * belief, which is persisted in a permanent memory. This class has not been
+ * implemented yet.
  * 
  * @author Ingrid Nunes
  *