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  package zeus.concepts;
25  
26  import java.util.*;
27  import zeus.util.*;
28  
29  public class SummaryTable extends Hashtable {
30     public SummaryTable() {
31     }
32  
33     public void add(String agent) {
34        Hashtable table = (Hashtable)get(agent);
35        if ( table == null ) {
36           table = new Hashtable();
37           put(agent,table);
38        }
39     }
40  
41     public void del(String agent) {
42        this.remove(agent);
43     }
44     
45     public String[] listAgents() {
46        String[] agents = new String[size()];
47        Enumeration enum = keys();
48        for( int i = 0; enum.hasMoreElements(); i++ )
49           agents[i] = (String)enum.nextElement();
50        return agents;
51     }
52  
53     public String[][] getData(String agent) {
54        Hashtable table = (Hashtable)get(agent);
55        if ( table == null || table.isEmpty() ) return null;
56        String[][] data = new String[table.size()][];
57        Enumeration enum = table.elements();
58        Summary g;
59        for( int i = 0; enum.hasMoreElements(); i++ ) {
60           g = (Summary)enum.nextElement();
61           data[i] = g.summarize();
62        }
63        return data;   
64     }
65  
66     public Summary getData(String agent, String id) {
67        Hashtable table = (Hashtable)get(agent);
68        if ( table == null || table.isEmpty() ) return null;
69        return (Summary) table.get(id);
70     }
71  
72     public void add(String agent, Summary item) {
73        String id = item.getId();
74        Hashtable table = (Hashtable)get(agent);
75        if ( table == null ) {
76           table = new Hashtable();
77           this.put(agent,table);
78        }
79        table.put(id,item);
80     }
81     public void add(String agent, Vector items) {
82        Hashtable table = (Hashtable)get(agent);
83        if ( table == null ) {
84           table = new Hashtable();
85           this.put(agent,table);
86        }
87        Summary item;
88        String id;
89        for(int i = 0; i < items.size(); i++ ) {
90           item = (Summary)items.elementAt(i);
91           id = item.getId(); 
92           table.put(id,item);
93        }
94     }
95  
96     public void del(String agent, Summary item) {
97        String id = item.getId(); 
98        Hashtable table = (Hashtable)get(agent);
99        if ( table == null ) {
100          Assert.notNull(null);
101          return;
102       }
103       Assert.notNull( table.remove(id) );
104    }
105    public void del(String agent, Vector items) {
106       Hashtable table = (Hashtable)get(agent);
107       if ( table == null ) {
108          Assert.notNull(null);
109          return;
110       }
111       Summary item;
112       String id;
113       for(int i = 0; i < items.size(); i++ ) {
114          item = (Summary)items.elementAt(i);
115          id = item.getId();
116          Assert.notNull( table.remove(id) );
117       }
118    }
119 
120    public void modify(String agent, Summary item) {
121       String id = item.getId();
122       Hashtable table = (Hashtable)get(agent);
123       if ( table == null ) {
124          Assert.notNull(null);
125          return;
126       }
127       Assert.notNull( table.put(id,item) );
128    }
129    public void modify(String agent, Vector items) {
130       Hashtable table = (Hashtable)get(agent);
131       if ( table == null ) {
132          Assert.notNull(null);
133          return;
134       }
135       Summary item;
136       String id;
137       for(int i = 0; i < items.size(); i++ ) {
138          item = (Summary)items.elementAt(i);
139          id = item.getId();
140          Assert.notNull( table.put(id,item) );
141       }
142    }
143 }