View Javadoc

1   /*
2   * The contents of this file are subject to the BT "ZEUS" Open Source 
3   * Licence (L77741), Version 1.0 (the "Licence"); you may not use this file 
4   * except in compliance with the Licence. You may obtain a copy of the Licence
5   * from $ZEUS_INSTALL/licence.html or alternatively from
6   * http://www.labs.bt.com/projects/agents/zeus/licence.htm
7   * 
8   * Except as stated in Clause 7 of the Licence, software distributed under the
9   * Licence is distributed WITHOUT WARRANTY OF ANY KIND, either express or 
10  * implied. See the Licence for the specific language governing rights and 
11  * limitations under the Licence.
12  * 
13  * The Original Code is within the package zeus.*.
14  * The Initial Developer of the Original Code is British Telecommunications
15  * public limited company, whose registered office is at 81 Newgate Street, 
16  * London, EC1A 7AJ, England. Portions created by British Telecommunications 
17  * public limited company are Copyright 1996-9. All Rights Reserved.
18  * 
19  * THIS NOTICE MUST BE INCLUDED ON ANY COPY OF THIS FILE
20  */
21  
22  
23  
24  /*
25   * @(#)PlanDb.java 1.00
26   */
27  
28  package zeus.actors;
29  
30  import java.util.*;
31  import zeus.util.*;
32  import zeus.concepts.*;
33  
34  /***
35   * The Plan Database is a simple storage component that holds the plan
36   * descriptions known by the owning agent.  This information is used by
37   * the agent's {@link Planner} component.
38   */
39  
40  public class PlanDb extends Hashtable {
41  
42     public void add(PlanRecord rec) {
43       Assert.notNull(rec);
44       Core.DEBUG(3,"Adding " + rec);
45       Goal goal = rec.getGoal();
46       String goalId = goal.getId();
47       Object obj = this.put(goalId,rec);
48       Core.ERROR(obj == null,1,this);
49     }
50  
51     public void del(PlanRecord rec) {
52       Assert.notNull(rec);
53       Goal goal = rec.getGoal();
54       String goalId = goal.getId();
55  
56       PlanRecord rec1 = (PlanRecord) this.remove(goalId);
57       Assert.notFalse( rec1 == rec );
58     }
59  
60     public void del(Vector List) {
61        for( int i = 0; i < List.size(); i++ )
62  	 this.del((PlanRecord) List.elementAt(i) );
63     }
64  
65     public void add(Vector List) {
66        for( int i = 0; i < List.size(); i++ )
67           this.add((PlanRecord) List.elementAt(i) );
68     }
69  
70     public PlanRecord lookUp(Goal goal) {
71        return (PlanRecord)this.get(goal.getId());
72     }
73  
74     public PlanRecord lookUp(String goalId) {
75        return (PlanRecord)this.get(goalId);
76     }
77     public boolean containsRecord(PlanRecord rec) {
78        return this.get(rec.getGoal().getId()) != null;
79     }
80  }