jason.bb
Class ChainBBAdapter

Package class diagram package ChainBBAdapter
java.lang.Object
  extended by jason.bb.ChainBBAdapter
All Implemented Interfaces:
BeliefBase, java.lang.Cloneable, java.lang.Iterable<Literal>
Direct Known Subclasses:
ChainBB, IndexedBB, JDBCPersistentBB, TextPersistentBB

public class ChainBBAdapter
extends java.lang.Object
implements 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 chain
 
will 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 ...
 }
 


Field Summary
protected  BeliefBase nextBB
           
 
Fields inherited from interface jason.bb.BeliefBase
APercept, ASelf, TPercept, TSelf
 
Constructor Summary
ChainBBAdapter()
           
ChainBBAdapter(BeliefBase bb)
           
 
Method Summary
 boolean abolish(PredicateIndicator pi)
          Removes all believes with some functor/arity
 boolean add(int index, Literal l)
          Adds a belief in the BB at index position, returns true if succeed
 boolean add(Literal l)
          Adds a belief in the end of the BB, returns true if succeed.
 BeliefBase clone()
           
 Literal contains(Literal l)
          Returns the literal l as it is in BB, this method does not consider annotations in the search.
 java.util.Iterator<Literal> getAll()
           
 org.w3c.dom.Element getAsDOM(org.w3c.dom.Document document)
          Gets the BB as XML
 java.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 BB that match the functor/arity of the parameter.
 BeliefBase getLastBB()
           
 ChainBBAdapter getNextAdapter()
           
 java.util.Iterator<Literal> getPercepts()
          Returns all beliefs that have "percept" as source
 java.util.Iterator<Literal> getRelevant(Literal l)
           
 void 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 succeed
 void setNext(BeliefBase bb)
           
 int size()
          Returns the number of beliefs in BB
 void stop()
          Called just before the end of MAS execution
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

nextBB

protected BeliefBase nextBB
Constructor Detail

ChainBBAdapter

public ChainBBAdapter()

ChainBBAdapter

public ChainBBAdapter(BeliefBase bb)
Method Detail

setNext

public void setNext(BeliefBase bb)

getNextAdapter

public ChainBBAdapter getNextAdapter()

getLastBB

public BeliefBase getLastBB()

init

public void init(Agent ag,
                 java.lang.String[] args)
Description copied from interface: 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"].

Specified by:
init in interface BeliefBase

stop

public void stop()
Description copied from interface: BeliefBase
Called just before the end of MAS execution

Specified by:
stop in interface BeliefBase

add

public boolean add(Literal l)
Description copied from interface: 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.

Specified by:
add in interface BeliefBase

add

public boolean add(int index,
                   Literal l)
Description copied from interface: BeliefBase
Adds a belief in the BB at index position, returns true if succeed

Specified by:
add in interface BeliefBase

contains

public Literal contains(Literal l)
Description copied from interface: 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].

Specified by:
contains in interface BeliefBase

getAll

public java.util.Iterator<Literal> getAll()
Specified by:
getAll in interface BeliefBase

iterator

public java.util.Iterator<Literal> iterator()
Description copied from interface: BeliefBase
Returns an iterator for all beliefs.

Specified by:
iterator in interface BeliefBase
Specified by:
iterator in interface java.lang.Iterable<Literal>

getCandidateBeliefs

public java.util.Iterator<Literal> getCandidateBeliefs(PredicateIndicator pi)
Description copied from interface: BeliefBase
Returns an iterator for all literals in BB that match the functor/arity of the parameter.

Specified by:
getCandidateBeliefs in interface BeliefBase

getCandidateBeliefs

public java.util.Iterator<Literal> getCandidateBeliefs(Literal l,
                                                       Unifier u)
Description copied from interface: 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)}, then getCandidateBeliefs(a(5), {}) = {{a(10),a(20)}.
if BB={a(10),a(20)}, then getCandidateBeliefs(X) = {{a(10),a(20)}. The getCandidateBeliefs(a(X), {X -> 5}) should also return {{a(10),a(20)}.

Specified by:
getCandidateBeliefs in interface BeliefBase

getPercepts

public java.util.Iterator<Literal> getPercepts()
Description copied from interface: BeliefBase
Returns all beliefs that have "percept" as source

Specified by:
getPercepts in interface BeliefBase

getRelevant

public java.util.Iterator<Literal> getRelevant(Literal l)
Specified by:
getRelevant in interface BeliefBase

abolish

public boolean abolish(PredicateIndicator pi)
Description copied from interface: BeliefBase
Removes all believes with some functor/arity

Specified by:
abolish in interface BeliefBase

remove

public boolean remove(Literal l)
Description copied from interface: BeliefBase
Removes a literal from BB, returns true if succeed

Specified by:
remove in interface BeliefBase

size

public int size()
Description copied from interface: BeliefBase
Returns the number of beliefs in BB

Specified by:
size in interface BeliefBase

getAsDOM

public org.w3c.dom.Element getAsDOM(org.w3c.dom.Document document)
Description copied from interface: BeliefBase
Gets the BB as XML

Specified by:
getAsDOM in interface BeliefBase

clone

public BeliefBase clone()
Specified by:
clone in interface BeliefBase
Overrides:
clone in class java.lang.Object

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object