Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package jason.bb;
  
  
 
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 ...
}

Author(s):
Jomi
Navassoc:
- nextBB - BeliefBase
 
 @SuppressWarnings("deprecation")
 public abstract class ChainBBAdapter implements BeliefBase {
 
     protected BeliefBase nextBB = null// the next BB in the chain
     
     public ChainBBAdapter() {
          = new DefaultBeliefBase();        
     }
     public ChainBBAdapter(BeliefBase bb) {
          = bb;
     }
 
     public void setNext(BeliefBase bb) {
          = bb;
     }
     
     public ChainBBAdapter getNextAdapter() {
         return  instanceof ChainBBAdapter ? (ChainBBAdapter) : null;
     }
     
     public BeliefBase getLastBB() {
         if ( == null)
             return this;
         else if ( instanceof ChainBBAdapter
             return ((ChainBBAdapter)).getLastBB();
         else 
             return ;            
     }
 
     // Methods of BB interface
     
     public void init(Agent agString[] args) {
         .init(agargs);
     }
     public void stop() {
         .stop();
     }
 
     public void clear() {
         .clear();
     }
     
     public boolean add(Literal l) {
         return .add(l);
     }
 
    public boolean add(int indexLiteral l) {
        return .add(indexl);
    }
    public Literal contains(Literal l) {
        return .contains(l);
    }
    public Iterator<LiteralgetAll() {
        return .getAll();
    }
    public Iterator<Literaliterator() {
        return .iterator();
    }
        return .getCandidateBeliefs(pi);
    }
    
    public Iterator<LiteralgetCandidateBeliefs(Literal lUnifier u) {
        return .getCandidateBeliefs(lu);
    }
    public Iterator<LiteralgetPercepts() {
        return .getPercepts();
    }
    public Iterator<LiteralgetRelevant(Literal l) {
        return .getRelevant(l);
    }
    public boolean abolish(PredicateIndicator pi) {
        return .abolish(pi);
    }
    public boolean remove(Literal l) {
        return .remove(l);
    }
    public int size() {
        return .size();
    }
    public Element getAsDOM(Document document) {
        return .getAsDOM(document);
    }
    @Override
    public BeliefBase clone() {
        return this;
    }
    
    @Override
    public String toString() {
        return .toString();
    }
New to GrepCode? Check out our FAQ X