View Javadoc
1   package net.logAnalyzer.analysis;
2   
3   import java.util.Date;
4   
5   /***
6    * This analysis result class contains an hashtable of values.
7    * 
8    * @author Karim REFEYTON
9    * @version 0.1
10   */
11  public final class SingleValueAnalysis extends LAAnalysis {
12  
13      /***
14       * Create a new analysis. Its initial value is <tt>0</tt>.
15       * 
16       * @param analyzer
17       *            Analyzer.
18       * @param name
19       *            Name of the value.
20       */
21      public SingleValueAnalysis(final LAAnalyzer analyzer, final String name) {
22          super(analyzer, new String[] { name });
23      }
24  
25      /***
26       * Add the specified value to the specified key.
27       * 
28       * @param key
29       *            Key of the value to change.
30       * @param value
31       *            Value to add.
32       * @return Old value if exists; <tt>0</tt> otherwiser.
33       * @see LAAnalysis#putDoubleValue(Comparable, int, double)
34       * @see LAAnalysis#getDoubleValue(Comparable, int)
35       */
36      public double addToDouble(Comparable key, double value) {
37          return putDoubleValue(key, 0, getDoubleValue(key, 0) + value);
38      }
39  
40      /***
41       * Add the specified value to the specified key.
42       * 
43       * @param key
44       *            Key of the value to change.
45       * @param value
46       *            Value to add.
47       * @return Old value if exists; <tt>0</tt> otherwiser.
48       * @see LAAnalysis#putDoubleValue(Comparable, int, double)
49       * @see LAAnalysis#getDoubleValue(Comparable, int)
50       */
51      public double addToDouble(Comparable key, long value) {
52          return putDoubleValue(key, 0, getDoubleValue(key, 0) + value);
53      }
54  
55      /***
56       * Add the specified value to the specified key.
57       * 
58       * @param key
59       *            Key of the value to change.
60       * @param value
61       *            Value to add.
62       * @return Old value if exists; <tt>0</tt> otherwiser.
63       * @see LAAnalysis#putLongValue(Comparable, int, long)
64       * @see LAAnalysis#getLongValue(Comparable, int)
65       */
66      public long addToLong(Comparable key, double value) {
67          return putLongValue(key, 0, getLongValue(key, 0) + (long) value);
68      }
69  
70      /***
71       * Add the specified value to the specified key.
72       * 
73       * @param key
74       *            Key of the value to change.
75       * @param value
76       *            Value to add.
77       * @return Old value if exists; <tt>0</tt> otherwiser.
78       * @see LAAnalysis#putLongValue(Comparable, int, long)
79       * @see LAAnalysis#getLongValue(Comparable, int)
80       */
81      public long addToLong(Comparable key, long value) {
82          return putLongValue(key, 0, getLongValue(key, 0) + value);
83      }
84  
85      /***
86       * Set the specified value to the current value.
87       * 
88       * @param key
89       *            Key of the value to change.
90       * @param value
91       *            Value to add.
92       * @return Old value if exists; <tt>null</tt> otherwise.
93       * @see LAAnalysis#putDateValue(Comparable, int, Date)
94       */
95      public Date put(Comparable key, Date value) {
96          return putDateValue(key, 0, value);
97      }
98  
99      /***
100      * Set the specified value to the current value.
101      * 
102      * @param key
103      *            Key of the value to change.
104      * @param value
105      *            Value to add.
106      * @return Old value if exists; <tt>0</tt> otherwise.
107      * @see LAAnalysis#putDoubleValue(Comparable, int, double)
108      */
109     public double put(Comparable key, double value) {
110         return putDoubleValue(key, 0, value);
111     }
112 
113     /***
114      * Set the specified value to the current value.
115      * 
116      * @param key
117      *            Key of the value to change.
118      * @param value
119      *            Value to add.
120      * @return Old value if exists; <tt>0</tt> otherwise.
121      * @see LAAnalysis#putLongValue(Comparable, int, long)
122      */
123     public long put(Comparable key, long value) {
124         return putLongValue(key, 0, value);
125     }
126 
127     /***
128      * Set the specified value to the current value.
129      * 
130      * @param key
131      *            Key of the value to change.
132      * @param value
133      *            Value to add.
134      * @return Old value if exists; <tt>0</tt> otherwise.
135      * @see LAAnalysis#putStringValue(Comparable, int, String)
136      */
137     public String put(Comparable key, String value) {
138         return putStringValue(key, 0, value);
139     }
140 
141     /***
142      * Return the resulting value associated to the specified key.
143      * 
144      * @param index
145      *            Index of the value.
146      * @return Value; <tt>null</tt> if unknown.
147      * @see LAAnalysis#getDateValue(Comparable, int)
148      */
149     public Date getDate(int index) {
150         return getDateValue(getKey(index), 0);
151     }
152 
153     /***
154      * Return the resulting value associated to the specified key.
155      * 
156      * @param key
157      *            Key of the value.
158      * @return Value; <tt>null</tt> if unknown.
159      * @see LAAnalysis#getDateValue(Comparable, int)
160      */
161     public Date getDate(Comparable key) {
162         return getDateValue(key, 0);
163     }
164 
165     /***
166      * Return the resulting value associated to the specified key.
167      * 
168      * @param index
169      *            Index of the value.
170      * @return Value; <tt>0</tt> if unknown.
171      * @see LAAnalysis#getDoubleValue(Comparable, int)
172      */
173     public double getDouble(int index) {
174         return getDoubleValue(getKey(index), 0);
175     }
176 
177     /***
178      * Return the resulting value associated to the specified key.
179      * 
180      * @param key
181      *            Key of the value.
182      * @return Value; <tt>0</tt> if unknown.
183      * @see LAAnalysis#getDoubleValue(Comparable, int)
184      */
185     public double getDouble(Comparable key) {
186         return getDoubleValue(key, 0);
187     }
188 
189     /***
190      * Return the resulting value associated to the specified key.
191      * 
192      * @param index
193      *            Index of the value.
194      * @return Value; <tt>0</tt> if unknown.
195      * @see LAAnalysis#getLongValue(Comparable, int)
196      */
197     public long getLong(int index) {
198         return getLongValue(getKey(index), 0);
199     }
200 
201     /***
202      * Return the resulting value associated to the specified key.
203      * 
204      * @param key
205      *            Key of the value.
206      * @return Value; <tt>0</tt> if unknown.
207      * @see LAAnalysis#getLongValue(Comparable, int)
208      */
209     public long getLong(Comparable key) {
210         return getLongValue(key, 0);
211     }
212 
213     /***
214      * Return the resulting value associated to the specified key.
215      * 
216      * @param index
217      *            Index of the value.
218      * @return Value; <tt>""</tt> if unknown.
219      * @see LAAnalysis#getStringValue(Comparable, int)
220      */
221     public String getString(int index) {
222         return getStringValue(getKey(index), 0);
223     }
224 
225     /***
226      * Return the resulting value associated to the specified key.
227      * 
228      * @param key
229      *            Key of the value.
230      * @return Value; <tt>""</tt> if unknown.
231      * @see LAAnalysis#getStringValue(Comparable, int)
232      */
233     public String getString(Comparable key) {
234         return getStringValue(key, 0);
235     }
236 
237     /***
238      * Return the resulting value associated to the specified key.
239      * 
240      * @param index
241      *            Index of the value.
242      * @return Value; <tt>null</tt> if unknown.
243      * @see LAAnalysis#getObjectValue(Comparable, int)
244      */
245     public Object getValue(int index) {
246         return getObjectValue(getKey(index), 0);
247     }
248 
249     /***
250      * Return the resulting value associated to the specified key.
251      * 
252      * @param key
253      *            Key of the value.
254      * @return Value; <tt>null</tt> if unknown.
255      * @see LAAnalysis#getObjectValue(Comparable, int)
256      */
257     public Object getValue(Comparable key) {
258         return getObjectValue(key, 0);
259     }
260 
261     /***
262      * Return the value name.
263      * 
264      * @return Value name.
265      * @see LAAnalysis#getValueName(int)
266      */
267     public String getName() {
268         return getValueName(0);
269     }
270 
271     /***
272      * Change the specified old key to the new key.
273      * 
274      * @param oldKey
275      *            Key to change.
276      * @param newKey
277      *            New key.
278      */
279     public void change(Comparable oldKey, Comparable newKey) {
280         changeKey(oldKey, newKey);
281     }
282 
283     /***
284      * Remove the specified key of the analysis.
285      * 
286      * @param key
287      *            Key to remove.
288      */
289     public void remove(Comparable key) {
290         removeKey(key);
291     }
292 
293     /***
294      * Remove the key at the specified index of the analysis.
295      * 
296      * @param keyIndex
297      *            Key index to remove.
298      */
299     public void remove(int keyIndex) {
300         removeKey(keyIndex);
301     }
302 
303     /***
304      * Sort results form greatest to lowest.
305      */
306     public void sortDESC() {
307         sortByValueDESC(0);
308     }
309 }