|
From: <jom...@us...> - 2013-08-15 14:15:37
|
Revision: 1742
http://sourceforge.net/p/jason/svn/1742
Author: jomifred
Date: 2013-08-15 14:15:34 +0000 (Thu, 15 Aug 2013)
Log Message:
-----------
include a "clear" method in BB
implements "remove()" for BB iterator
Modified Paths:
--------------
trunk/src/jason/bb/BeliefBase.java
trunk/src/jason/bb/ChainBBAdapter.java
trunk/src/jason/bb/DefaultBeliefBase.java
trunk/src/jason/bb/JDBCPersistentBB.java
trunk/src/test/BeliefBaseTest.java
Modified: trunk/src/jason/bb/BeliefBase.java
===================================================================
--- trunk/src/jason/bb/BeliefBase.java 2013-07-18 16:54:23 UTC (rev 1741)
+++ trunk/src/jason/bb/BeliefBase.java 2013-08-15 14:15:34 UTC (rev 1742)
@@ -64,6 +64,9 @@
/** Called just before the end of MAS execution */
public void stop();
+ /** removes all beliefs from BB */
+ public void clear();
+
/** Adds a belief in the end of the BB, returns true if succeed.
* The annots of l may be changed to reflect what was changed in the BB,
* for example, if l is p[a,b] in a BB with p[a], l will be changed to
Modified: trunk/src/jason/bb/ChainBBAdapter.java
===================================================================
--- trunk/src/jason/bb/ChainBBAdapter.java 2013-07-18 16:54:23 UTC (rev 1741)
+++ trunk/src/jason/bb/ChainBBAdapter.java 2013-08-15 14:15:34 UTC (rev 1742)
@@ -89,6 +89,9 @@
nextBB.stop();
}
+ public void clear() {
+ nextBB.clear();
+ }
public boolean add(Literal l) {
return nextBB.add(l);
Modified: trunk/src/jason/bb/DefaultBeliefBase.java
===================================================================
--- trunk/src/jason/bb/DefaultBeliefBase.java 2013-07-18 16:54:23 UTC (rev 1741)
+++ trunk/src/jason/bb/DefaultBeliefBase.java 2013-08-15 14:15:34 UTC (rev 1742)
@@ -74,6 +74,12 @@
public int size() {
return size;
}
+
+ public void clear() {
+ size = 0;
+ percepts.clear();
+ belsMap.clear();
+ }
public Iterator<Literal> getPercepts() {
final Iterator<Literal> i = percepts.iterator();
@@ -188,13 +194,14 @@
return new Iterator<Literal>() {
Iterator<Literal> il = ibe.next().list.iterator();
-
+ Literal l;
+
public boolean hasNext() {
return il.hasNext();
}
public Literal next() {
- Literal l = il.next();
+ l = il.next();
if (!il.hasNext() && ibe.hasNext()) {
il = ibe.next().list.iterator();
}
@@ -202,7 +209,11 @@
}
public void remove() {
- logger.warning("remove is not implemented for BB.iterator().");
+ il.remove();
+ if (l.hasAnnot(TPercept)) {
+ percepts.remove(l);
+ }
+ size--;
}
};
} else {
@@ -213,10 +224,10 @@
/** @deprecated use iterator() instead of getAll */
public Iterator<Literal> getAll() {
return iterator();
- }
-
+ }
public boolean abolish(PredicateIndicator pi) {
+ // TODO: remove also in percepts list!
return belsMap.remove(pi) != null;
}
Modified: trunk/src/jason/bb/JDBCPersistentBB.java
===================================================================
--- trunk/src/jason/bb/JDBCPersistentBB.java 2013-07-18 16:54:23 UTC (rev 1741)
+++ trunk/src/jason/bb/JDBCPersistentBB.java 2013-08-15 14:15:34 UTC (rev 1742)
@@ -180,6 +180,10 @@
}
nextBB.stop();
}
+
+ public void clear() {
+ logger.warning("clear is still not implemented for JDBC BB!");
+ }
/** returns true if the literal is stored in a DB */
protected boolean isDB(Literal l) {
Modified: trunk/src/test/BeliefBaseTest.java
===================================================================
--- trunk/src/test/BeliefBaseTest.java 2013-07-18 16:54:23 UTC (rev 1741)
+++ trunk/src/test/BeliefBaseTest.java 2013-08-15 14:15:34 UTC (rev 1742)
@@ -172,6 +172,19 @@
assertEquals(iteratorSize(bb.getPercepts()), 0);
assertEquals(bb.size(), 1);
+ l2 = new LiteralImpl(true, new Pred("testRemIt"));
+ l2.addAnnot(new Structure("a"));
+ l2.addAnnot(BeliefBase.TPercept);
+ bb.add(l2);
+ Iterator<Literal> itl = bb.iterator();
+ while (itl.hasNext()) {
+ Literal l = itl.next();
+ if (l.getFunctor().startsWith("testRemIt")) {
+ itl.remove();
+ }
+ }
+ assertEquals(iteratorSize(bb.getPercepts()), 0);
+
l3 = Literal.parseLiteral("pos[source(ag1)]");
assertFalse(l2.isAtom());
assertTrue(bb.remove(l3));
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|