bdi4jade

Renamed methods to get beliefs

9/4/2014 6:42:26 PM

Details

diff --git a/bdi-jade/src/bdi4jade/belief/BeliefBase.java b/bdi-jade/src/bdi4jade/belief/BeliefBase.java
index d5ec621..dc6bd14 100644
--- a/bdi-jade/src/bdi4jade/belief/BeliefBase.java
+++ b/bdi-jade/src/bdi4jade/belief/BeliefBase.java
@@ -139,14 +139,41 @@ public class BeliefBase implements Serializable {
 	}
 
 	/**
+	 * Retrieves a belief from the belief base. If this belief base does not
+	 * contain it, the method checks whole-capabilities' belief base
+	 * recursively.
+	 * 
+	 * @param name
+	 *            the name of the belief to be retrieved.
+	 * @return the belief, or null if no belief is found.
+	 */
+	public Belief<?, ?> getBelief(Object name) {
+		Belief<?, ?> belief = this.beliefs.get(name);
+		if (belief == null && capability.getWholeCapability() != null) {
+			belief = capability.getWholeCapability().getBeliefBase()
+					.getBelief(name);
+		}
+		return belief;
+	}
+
+	/**
+	 * Returns all the current belief listeners of this belief base.
+	 * 
+	 * @return the belief listeners.
+	 */
+	public Set<BeliefListener> getBeliefListeners() {
+		return new HashSet<>(beliefListeners);
+	}
+
+	/**
 	 * Gets all beliefs of this belief base and the belief bases of the
 	 * whole-capabilities of the capability that this belief base belongs to.
 	 * 
 	 * @return the beliefs of this capability and all of its whole-capabilities.
 	 */
-	public Collection<Belief<?, ?>> getAllBeliefs() {
+	public Collection<Belief<?, ?>> getBeliefs() {
 		Collection<Belief<?, ?>> beliefs = new LinkedList<>();
-		getAllBeliefs(beliefs);
+		getBeliefs(beliefs);
 		return beliefs;
 	}
 
@@ -157,11 +184,10 @@ public class BeliefBase implements Serializable {
 	 * @param beliefs
 	 *            the set to which beliefs are added.
 	 */
-	private void getAllBeliefs(final Collection<Belief<?, ?>> beliefs) {
+	private void getBeliefs(final Collection<Belief<?, ?>> beliefs) {
 		beliefs.addAll(this.beliefs.values());
 		if (capability.getWholeCapability() != null) {
-			capability.getWholeCapability().getBeliefBase()
-					.getAllBeliefs(beliefs);
+			capability.getWholeCapability().getBeliefBase().getBeliefs(beliefs);
 		}
 	}
 
@@ -174,13 +200,13 @@ public class BeliefBase implements Serializable {
 	 *            the class of the name of beliefs.
 	 * @return the set of beliefs assignable from the given class.
 	 */
-	public Set<Belief<?, ?>> getAllBeliefsAssignableFrom(Class<?> beliefNameType) {
+	public Set<Belief<?, ?>> getBeliefsAssignableFrom(Class<?> beliefNameType) {
 		Set<Belief<?, ?>> beliefs = new HashSet<>();
-		getAllBeliefsAssignableFrom(beliefNameType, beliefs);
+		getBeliefsAssignableFrom(beliefNameType, beliefs);
 		return beliefs;
 	}
 
-	private void getAllBeliefsAssignableFrom(Class<?> beliefNameType,
+	private void getBeliefsAssignableFrom(Class<?> beliefNameType,
 			Collection<Belief<?, ?>> beliefs) {
 		for (Class<?> beliefSupertype : beliefsByType.keySet()) {
 			if (beliefSupertype.isAssignableFrom(beliefNameType)) {
@@ -192,7 +218,7 @@ public class BeliefBase implements Serializable {
 
 		if (capability.getWholeCapability() != null) {
 			capability.getWholeCapability().getBeliefBase()
-					.getAllBeliefsAssignableFrom(beliefNameType, beliefs);
+					.getBeliefsAssignableFrom(beliefNameType, beliefs);
 		}
 	}
 
@@ -204,13 +230,13 @@ public class BeliefBase implements Serializable {
 	 *            the class of the name of beliefs.
 	 * @return the set of beliefs of the given class.
 	 */
-	public Set<Belief<?, ?>> getAllBeliefsByType(Class<?> beliefNameType) {
+	public Set<Belief<?, ?>> getBeliefsByType(Class<?> beliefNameType) {
 		Set<Belief<?, ?>> beliefs = new HashSet<>();
-		getAllBeliefsByType(beliefNameType, beliefs);
+		getBeliefsByType(beliefNameType, beliefs);
 		return beliefs;
 	}
 
-	private void getAllBeliefsByType(Class<?> beliefNameType,
+	private void getBeliefsByType(Class<?> beliefNameType,
 			Collection<Belief<?, ?>> beliefs) {
 		Set<Belief<?, ?>> beliefsOfType = beliefsByType.get(beliefNameType);
 		if (beliefsOfType != null) {
@@ -219,35 +245,17 @@ public class BeliefBase implements Serializable {
 
 		if (capability.getWholeCapability() != null) {
 			capability.getWholeCapability().getBeliefBase()
-					.getAllBeliefsByType(beliefNameType, beliefs);
+					.getBeliefsByType(beliefNameType, beliefs);
 		}
 	}
 
 	/**
-	 * Retrieves a belief from the belief base. If this belief base does not
-	 * contain it, the method checks whole-capabilities' belief base
-	 * recursively.
-	 * 
-	 * @param name
-	 *            the name of the belief to be retrieved.
-	 * @return the belief, or null if no belief is found.
-	 */
-	public Belief<?, ?> getBelief(Object name) {
-		Belief<?, ?> belief = this.beliefs.get(name);
-		if (belief == null && capability.getWholeCapability() != null) {
-			belief = capability.getWholeCapability().getBeliefBase()
-					.getBelief(name);
-		}
-		return belief;
-	}
-
-	/**
-	 * Returns all the current belief listeners of this belief base.
+	 * Returns the capability with which this belief base is associated.
 	 * 
-	 * @return the belief listeners.
+	 * @return the capability.
 	 */
-	public Set<BeliefListener> getBeliefListeners() {
-		return new HashSet<>(beliefListeners);
+	public Capability getCapability() {
+		return capability;
 	}
 
 	/**
@@ -255,7 +263,7 @@ public class BeliefBase implements Serializable {
 	 * 
 	 * @return the beliefs
 	 */
-	public Set<Belief<?, ?>> getBeliefs() {
+	public Set<Belief<?, ?>> getLocalBeliefs() {
 		return new HashSet<>(beliefs.values());
 	}
 
@@ -267,7 +275,8 @@ public class BeliefBase implements Serializable {
 	 *            the class of the name of beliefs.
 	 * @return the set of beliefs assignable from the given class.
 	 */
-	public Set<Belief<?, ?>> getBeliefsAssignableFrom(Class<?> beliefNameType) {
+	public Set<Belief<?, ?>> getLocalBeliefsAssignableFrom(
+			Class<?> beliefNameType) {
 		Set<Belief<?, ?>> beliefs = new HashSet<>();
 		for (Class<?> beliefsubtype : beliefsByType.keySet()) {
 			if (beliefNameType.isAssignableFrom(beliefsubtype)) {
@@ -280,13 +289,13 @@ public class BeliefBase implements Serializable {
 	}
 
 	/**
-	 * Returns all beliefs whose name is of the given class.
+	 * Returns beliefs whose name is of the given class.
 	 * 
 	 * @param beliefNameType
 	 *            the class of the name of beliefs.
 	 * @return the set of beliefs of the given class.
 	 */
-	public Set<Belief<?, ?>> getBeliefsByType(Class<?> beliefNameType) {
+	public Set<Belief<?, ?>> getLocalBeliefsByType(Class<?> beliefNameType) {
 		Set<Belief<?, ?>> beliefs = new HashSet<>();
 		Set<Belief<?, ?>> beliefsOfType = beliefsByType.get(beliefNameType);
 		if (beliefsOfType != null) {
@@ -296,11 +305,11 @@ public class BeliefBase implements Serializable {
 	}
 
 	/**
-	 * Returns a list of all belief values from this belief base.
+	 * Returns a list of belief values from this belief base.
 	 * 
 	 * @return the beliefValues
 	 */
-	public List<Object> getBeliefValues() {
+	public List<Object> getLocalBeliefValues() {
 		List<Object> beliefValues = new ArrayList<>(beliefs.size());
 		for (Belief<?, ?> belief : beliefs.values())
 			beliefValues.add(belief.getValue());
@@ -308,15 +317,6 @@ public class BeliefBase implements Serializable {
 	}
 
 	/**
-	 * Returns the capability with which this belief base is associated.
-	 * 
-	 * @return the capability.
-	 */
-	public Capability getCapability() {
-		return capability;
-	}
-
-	/**
 	 * Checks whether a belief is part of the belief base. If this belief base
 	 * does not contain it, the method checks whole-capabilities' belief base
 	 * recursively.
@@ -398,7 +398,8 @@ public class BeliefBase implements Serializable {
 		if (belief != null) {
 			Class<?> beliefNameType = belief.getName().getClass();
 			Set<Belief<?, ?>> beliefTypeSet = beliefsByType.get(beliefNameType);
-			assert beliefTypeSet.remove(belief);
+			boolean removed = beliefTypeSet.remove(belief);
+			assert removed;
 			if (beliefTypeSet.isEmpty()) {
 				beliefsByType.remove(beliefNameType);
 			}