Package jason.bb
Class ChainBBAdapter
java.lang.Object
jason.bb.BeliefBase
jason.bb.ChainBBAdapter
- Direct Known Subclasses:
ChainBB
,IndexedBB
,JDBCPersistentBB
,TextPersistentBB
public abstract class ChainBBAdapter extends BeliefBase
This class is to be extended by customised belief bases that may be
used in chains (of responsibility).
For example, the code
BeliefBase bb = new MyBB1( new MyBB2()); // DefaultBeliefBase is the next of the last element of the chainwill chain 3 BBs: MyBB1, myBB2, and the DefaultBeliefBase. So, for any operation of the BB interface, the operation is firstly called in MyBB1, then in MyBB2 and finally in the DefaultBeliefBase. The code of MyBB1 looks like:
class MyBB1 extends ChainBBAdapter { public MyBB1() { } public MyBB1(BeliefBase next) { super(next); } public boolean add(Literal l) { ... some customisation of add .... return next.add(l); // delegate the operation for the next BB in the chain } ... customisation of other operations ... }
- Author:
- Jomi
-
Field Summary
Fields Modifier and Type Field Description protected BeliefBase
nextBB
-
Constructor Summary
Constructors Constructor Description ChainBBAdapter()
ChainBBAdapter(BeliefBase bb)
-
Method Summary
Modifier and Type Method Description boolean
abolish(PredicateIndicator pi)
Removes all believes with some functor/arity in the default namespaceboolean
add(int index, Literal l)
Adds a belief in the BB at index position, returns true if succeedboolean
add(Literal l)
Adds a belief in the end of the BB, returns true if succeed.void
clear()
removes all beliefs from BBBeliefBase
clone()
Literal
contains(Literal l)
Returns the literal l as it is in BB, this method does not consider annotations in the search.org.w3c.dom.Element
getAsDOM(org.w3c.dom.Document document)
Gets the BB as XMLjava.util.Iterator<Literal>
getCandidateBeliefs(Literal l, Unifier u)
Returns an iterator for all literals relevant for l's predicate indicator, if l is a var, returns all beliefs.
The unifier u may contain values for variables in l.java.util.Iterator<Literal>
getCandidateBeliefs(PredicateIndicator pi)
Returns an iterator for all literals in the default namespace of the BB that match the functor/arity of the parameter.BeliefBase
getLastBB()
java.util.Set<Atom>
getNameSpaces()
ChainBBAdapter
getNextAdapter()
java.util.Iterator<Literal>
getPercepts()
Returns all beliefs that have "percept" as sourcevoid
init(Agent ag, java.lang.String[] args)
Called before the MAS execution with the agent that uses this BB and the args informed in .mas2j project.
Example in .mas2j:
agent BeliefBaseClass(1,bla);
the init args will be ["1", "bla"].java.util.Iterator<Literal>
iterator()
Returns an iterator for all beliefs.boolean
remove(Literal l)
Removes a literal from BB, returns true if succeedvoid
setNext(BeliefBase bb)
int
size()
Returns the number of beliefs in BBvoid
stop()
Called just before the end of MAS executionjava.lang.String
toString()
Methods inherited from class jason.bb.BeliefBase
abolish, getLock
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
nextBB
-
-
Constructor Details
-
ChainBBAdapter
public ChainBBAdapter() -
ChainBBAdapter
-
-
Method Details
-
setNext
-
getNextAdapter
-
getLastBB
-
init
Description copied from class:BeliefBase
Called before the MAS execution with the agent that uses this BB and the args informed in .mas2j project.
Example in .mas2j:
agent BeliefBaseClass(1,bla);
the init args will be ["1", "bla"].- Overrides:
init
in classBeliefBase
-
stop
public void stop()Description copied from class:BeliefBase
Called just before the end of MAS execution- Overrides:
stop
in classBeliefBase
-
clear
public void clear()Description copied from class:BeliefBase
removes all beliefs from BB- Overrides:
clear
in classBeliefBase
-
getNameSpaces
- Overrides:
getNameSpaces
in classBeliefBase
-
add
Description copied from class:BeliefBase
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 p[b] to produce the event +p[b], since only the annotation b is changed in the BB.- Overrides:
add
in classBeliefBase
-
add
Description copied from class:BeliefBase
Adds a belief in the BB at index position, returns true if succeed- Overrides:
add
in classBeliefBase
-
contains
Description copied from class:BeliefBase
Returns the literal l as it is in BB, this method does not consider annotations in the search.
Example, if BB={a(10)[a,b]},contains(a(10)[d])
returns a(10)[a,b].- Overrides:
contains
in classBeliefBase
-
iterator
Description copied from class:BeliefBase
Returns an iterator for all beliefs.- Specified by:
iterator
in interfacejava.lang.Iterable<Literal>
- Specified by:
iterator
in classBeliefBase
-
getCandidateBeliefs
Description copied from class:BeliefBase
Returns an iterator for all literals in the default namespace of the BB that match the functor/arity of the parameter.- Specified by:
getCandidateBeliefs
in classBeliefBase
-
getCandidateBeliefs
Description copied from class:BeliefBase
Returns an iterator for all literals relevant for l's predicate indicator, if l is a var, returns all beliefs.
The unifier u may contain values for variables in l. Example, if BB={a(10),a(20),a(2,1),b(f)}, thengetCandidateBeliefs(a(5), {})
= {{a(10),a(20)}.
if BB={a(10),a(20)}, thengetCandidateBeliefs(X)
= {{a(10),a(20)}. ThegetCandidateBeliefs(a(X), {X -> 5})
should also return {{a(10),a(20)}.- Overrides:
getCandidateBeliefs
in classBeliefBase
-
getPercepts
Description copied from class:BeliefBase
Returns all beliefs that have "percept" as source- Overrides:
getPercepts
in classBeliefBase
-
abolish
Description copied from class:BeliefBase
Removes all believes with some functor/arity in the default namespace- Overrides:
abolish
in classBeliefBase
-
remove
Description copied from class:BeliefBase
Removes a literal from BB, returns true if succeed- Overrides:
remove
in classBeliefBase
-
size
public int size()Description copied from class:BeliefBase
Returns the number of beliefs in BB- Overrides:
size
in classBeliefBase
-
getAsDOM
public org.w3c.dom.Element getAsDOM(org.w3c.dom.Document document)Description copied from class:BeliefBase
Gets the BB as XML- Specified by:
getAsDOM
in interfaceToDOM
- Overrides:
getAsDOM
in classBeliefBase
-
clone
- Specified by:
clone
in classBeliefBase
-
toString
public java.lang.String toString()- Overrides:
toString
in classjava.lang.Object
-