1 package rydeen;
2
3 import java.util.Iterator;
4 import java.util.LinkedHashMap;
5 import java.util.Map;
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 public class Summary implements Iterable<Summary.Entry>{
24 private String processorId;
25 private Map<String, Summary.Entry> entries = new LinkedHashMap<String, Summary.Entry>();
26
27
28
29
30 public Summary(String processorId){
31 setProcessorId(processorId);
32 }
33
34
35
36
37
38
39
40
41
42 public void setProcessorId(String id){
43 if(id == null){
44 throw new NullPointerException();
45 }
46 this.processorId = id;
47 }
48
49
50
51
52
53 public String getProcessorId(){
54 return processorId;
55 }
56
57
58
59
60
61
62
63 public void putEntry(String key, String value){
64 if(key == null || value == null){
65 throw new NullPointerException();
66 }
67 entries.put(key, new Summary.Entry(key, value));
68 }
69
70
71
72
73
74
75
76
77
78
79
80 public String getEntry(String key){
81 if(key == null){
82 throw new NullPointerException();
83 }
84 Entry entry = entries.get(key);
85 String value = null;
86 if(entry != null){
87 value = entry.getValue();
88 }
89 return value;
90 }
91
92
93
94
95
96
97
98
99
100 public void removeEntry(String key){
101 entries.remove(key);
102 }
103
104
105
106
107
108 public int getEntryCount(){
109 return entries.size();
110 }
111
112
113
114
115 @Override
116 public Iterator<Summary.Entry> iterator(){
117 return entries.values().iterator();
118 }
119
120
121
122
123 public static class Entry{
124 private String key;
125 private String value;
126
127
128
129
130
131
132 public Entry(String key, String value){
133 if(key == null || value == null){
134 throw new NullPointerException();
135 }
136 this.key = key;
137 this.value = value;
138 }
139
140
141
142
143 public String getKey(){
144 return key;
145 }
146
147
148
149
150 public String getValue(){
151 return value;
152 }
153 }
154 }