1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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 }