View Javadoc
1   package net.logAnalyzer.analysis;
2   
3   import java.util.Date;
4   
5   /***
6    * This analysis result class contains an hashtable of long values arrays.
7    * 
8    * @author Karim REFEYTON
9    * @version 0.1
10   */
11  public final class MultiValuesAnalysis extends LAAnalysis {
12  
13      /***
14       * Create a new analysis. Its initial value is <tt>0</tt>.
15       * 
16       * @param analyzer
17       *            Analyzer.
18       * @param names
19       *            Names of values.
20       */
21      public MultiValuesAnalysis(LAAnalyzer analyzer, String[] names) {
22          super(analyzer, names);
23      }
24  
25      /***
26       * Add the specified value to the specified key and index.
27       * 
28       * @param key
29       *            Key of the group of values to change.
30       * @param index
31       *            Index of the value in the group to change.
32       * @param value
33       *            Value to add.
34       * @return Old value if exists; <tt>0</tt> otherwiser.
35       * @see LAAnalysis#putDoubleValue(Comparable, int, double)
36       * @see LAAnalysis#getDoubleValue(Comparable, int)
37       */
38      public double addToDouble(Comparable key, int index, double value) {
39          return putDoubleValue(key, index, getDoubleValue(key, index) + value);
40      }
41  
42      /***
43       * Add the specified value to the specified key and index.
44       * 
45       * @param key
46       *            Key of the group of values to change.
47       * @param index
48       *            Index of the value in the group to change.
49       * @param value
50       *            Value to add.
51       * @return Old value if exists; <tt>0</tt> otherwiser.
52       * @see LAAnalysis#putDoubleValue(Comparable, int, double)
53       * @see LAAnalysis#getDoubleValue(Comparable, int)
54       */
55      public double addToDouble(Comparable key, int index, long value) {
56          return putDoubleValue(key, index, getDoubleValue(key, index) + value);
57      }
58  
59      /***
60       * Add the specified value to the specified key and name.
61       * 
62       * @param key
63       *            Key of the group of values to change.
64       * @param name
65       *            Name of the value in the group to change.
66       * @param value
67       *            Value to add.
68       * @return Old value if exists; <tt>0</tt> otherwiser.
69       * @see #getNameIndex(String)
70       * @see #addToDouble(Comparable, int, double)
71       */
72      public double addToDouble(Comparable key, String name, double value) {
73          return addToDouble(key, getNameIndex(name), value);
74      }
75  
76      /***
77       * Add the specified value to the specified key and name.
78       * 
79       * @param key
80       *            Key of the group of values to change.
81       * @param name
82       *            Name of the value in the group to change.
83       * @param value
84       *            Value to add.
85       * @return Old value if exists; <tt>0</tt> otherwiser.
86       * @see #getNameIndex(String)
87       * @see #addToDouble(Comparable, int, long)
88       */
89      public double addToDouble(Comparable key, String name, long value) {
90          return addToDouble(key, getNameIndex(name), value);
91      }
92  
93      /***
94       * Add the specified value to the specified key and index.
95       * 
96       * @param key
97       *            Key of the group of values to change.
98       * @param index
99       *            Index of the value in the group to change.
100      * @param value
101      *            Value to add.
102      * @return Old value if exists; <tt>0</tt> otherwiser.
103      * @see LAAnalysis#putLongValue(Comparable, int, long)
104      * @see LAAnalysis#getLongValue(Comparable, int)
105      */
106     public long addToLong(Comparable key, int index, double value) {
107         return putLongValue(key, index, getLongValue(key, index) + (long) value);
108     }
109 
110     /***
111      * Add the specified value to the specified key and index.
112      * 
113      * @param key
114      *            Key of the group of values to change.
115      * @param index
116      *            Index of the value in the group to change.
117      * @param value
118      *            Value to add.
119      * @return Old value if exists; <tt>0</tt> otherwiser.
120      * @see LAAnalysis#putLongValue(Comparable, int, long)
121      * @see LAAnalysis#getLongValue(Comparable, int)
122      */
123     public long addToLong(Comparable key, int index, long value) {
124         return putLongValue(key, index, getLongValue(key, index) + value);
125     }
126 
127     /***
128      * Add the specified value to the specified key and name.
129      * 
130      * @param key
131      *            Key of the group of values to change.
132      * @param name
133      *            Name of the value in the group to change.
134      * @param value
135      *            Value to add.
136      * @return Old value if exists; <tt>0</tt> otherwiser.
137      * @see #getNameIndex(String)
138      * @see #addToLong(Comparable, int, double)
139      */
140     public long addToLong(Comparable key, String name, double value) {
141         return addToLong(key, getNameIndex(name), value);
142     }
143 
144     /***
145      * Add the specified value to the specified key and name.
146      * 
147      * @param key
148      *            Key of the group of values to change.
149      * @param name
150      *            Name of the value in the group to change.
151      * @param value
152      *            Value to add.
153      * @return Old value if exists; <tt>0</tt> otherwiser.
154      * @see #getNameIndex(String)
155      * @see #addToLong(Comparable, int, long)
156      */
157     public long addToLong(Comparable key, String name, long value) {
158         return addToLong(key, getNameIndex(name), value);
159     }
160 
161     /***
162      * Set the specified value to the specified key and index.
163      * 
164      * @param key
165      *            Key of the group of values to change.
166      * @param index
167      *            Index of the value in the group to change.
168      * @param value
169      *            New value.
170      * @return Old value if exists; <tt>null</tt> otherwise.
171      * @see LAAnalysis#putDateValue(Comparable, int, Date)
172      */
173     public Date put(Comparable key, int index, Date value) {
174         return putDateValue(key, index, value);
175     }
176 
177     /***
178      * Set the specified value to the specified key and index.
179      * 
180      * @param key
181      *            Key of the group of values to change.
182      * @param index
183      *            Index of the value in the group to change.
184      * @param value
185      *            New value.
186      * @return Old value if exists; <tt>0</tt> otherwise.
187      * @see LAAnalysis#putDoubleValue(Comparable, int, double)
188      */
189     public double put(Comparable key, int index, double value) {
190         return putDoubleValue(key, index, value);
191     }
192 
193     /***
194      * Set the specified value to the specified key and index.
195      * 
196      * @param key
197      *            Key of the group of values to change.
198      * @param index
199      *            Index of the value in the group to change.
200      * @param value
201      *            New value.
202      * @return Old value if exists; <tt>0</tt> otherwise.
203      * @see LAAnalysis#putLongValue(Comparable, int, long)
204      */
205     public long put(Comparable key, int index, long value) {
206         return putLongValue(key, index, value);
207     }
208 
209     /***
210      * Set the specified value to the specified key and index.
211      * 
212      * @param key
213      *            Key of the group of values to change.
214      * @param index
215      *            Index of the value in the group to change.
216      * @param value
217      *            New value.
218      * @return Old value if exists; <tt>0</tt> otherwise.
219      * @see LAAnalysis#putStringValue(Comparable, int, String)
220      */
221     public String put(Comparable key, int index, String value) {
222         return putStringValue(key, index, value);
223     }
224 
225     /***
226      * Set the specified value to the specified key and name.
227      * 
228      * @param key
229      *            Key of the group of values to change.
230      * @param name
231      *            Name of the value in the group to change.
232      * @param value
233      *            New value.
234      * @return Old value if exists; <tt>null</tt> otherwise.
235      * @see #getNameIndex(String)
236      * @see #put(Comparable, int, Date)
237      */
238     public Date put(Comparable key, String name, Date value) {
239         return put(key, getNameIndex(name), value);
240     }
241 
242     /***
243      * Set the specified value to the specified key and name.
244      * 
245      * @param key
246      *            Key of the group of values to change.
247      * @param name
248      *            Name of the value in the group to change.
249      * @param value
250      *            New value.
251      * @return Old value if exists; <tt>0</tt> otherwise.
252      * @see #getNameIndex(String)
253      * @see #put(Comparable, int, double)
254      */
255     public double put(Comparable key, String name, double value) {
256         return put(key, getNameIndex(name), value);
257     }
258 
259     /***
260      * Set the specified value to the specified key and name.
261      * 
262      * @param key
263      *            Key of the group of values to change.
264      * @param name
265      *            Name of the value in the group to change.
266      * @param value
267      *            New value.
268      * @return Old value if exists; <tt>0</tt> otherwise.
269      * @see #getNameIndex(String)
270      * @see #put(Comparable, int, long)
271      */
272     public long put(Comparable key, String name, long value) {
273         return put(key, getNameIndex(name), value);
274     }
275 
276     /***
277      * Set the specified value to the specified key and name.
278      * 
279      * @param key
280      *            Key of the group of values to change.
281      * @param name
282      *            Name of the value in the group to change.
283      * @param value
284      *            New value.
285      * @return Old value if exists; <tt>0</tt> otherwise.
286      * @see #getNameIndex(String)
287      * @see #put(Comparable, int, String)
288      */
289     public String put(Comparable key, String name, String value) {
290         return put(key, getNameIndex(name), value);
291     }
292 
293     /***
294      * Return the resulting value associated to the specified key.
295      * 
296      * @param key
297      *            Key of the group of values.
298      * @param index
299      *            Index of the value in the group to read.
300      * @return Value; <tt>0</tt> if unknown.
301      * @see LAAnalysis#getDateValue(Comparable, int)
302      */
303     public Date getDate(Comparable key, int index) {
304         return getDateValue(key, index);
305     }
306 
307     /***
308      * Return the resulting value associated to the specified key.
309      * 
310      * @param key
311      *            Key of the group of values.
312      * @param name
313      *            Name of the value in the group to read.
314      * @return Value; <tt>0</tt> if unknown.
315      * @see LAAnalysis#getDateValue(Comparable, int)
316      * @see LAAnalysis#getValueNameIndex(String)
317      */
318     public Date getDate(Comparable key, String name) {
319         return getDateValue(key, getValueNameIndex(name));
320     }
321 
322     /***
323      * Return the resulting value associated to the specified key.
324      * 
325      * @param key
326      *            Key of the group of values.
327      * @param index
328      *            Index of the value in the group to read.
329      * @return Value; <tt>0</tt> if unknown.
330      * @see LAAnalysis#getDoubleValue(Comparable, int)
331      */
332     public double getDouble(Comparable key, int index) {
333         return getDoubleValue(key, index);
334     }
335 
336     /***
337      * Return the resulting value associated to the specified key.
338      * 
339      * @param key
340      *            Key of the group of values.
341      * @param name
342      *            Name of the value in the group to read.
343      * @return Value; <tt>0</tt> if unknown.
344      * @see LAAnalysis#getDoubleValue(Comparable, int)
345      * @see LAAnalysis#getValueNameIndex(String)
346      */
347     public double getDouble(Comparable key, String name) {
348         return getDoubleValue(key, getValueNameIndex(name));
349     }
350 
351     /***
352      * Return the resulting value associated to the specified key.
353      * 
354      * @param key
355      *            Key of the group of values.
356      * @param index
357      *            Index of the value in the group to read.
358      * @return Value; <tt>0</tt> if unknown.
359      * @see LAAnalysis#getLongValue(Comparable, int)
360      */
361     public long getLong(Comparable key, int index) {
362         return getLongValue(key, index);
363     }
364 
365     /***
366      * Return the resulting value associated to the specified key.
367      * 
368      * @param key
369      *            Key of the group of values.
370      * @param name
371      *            Name of the value in the group to read.
372      * @return Value; <tt>0</tt> if unknown.
373      * @see LAAnalysis#getLongValue(Comparable, int)
374      * @see LAAnalysis#getValueNameIndex(String)
375      */
376     public long getLong(Comparable key, String name) {
377         return getLongValue(key, getValueNameIndex(name));
378     }
379 
380     /***
381      * Return the resulting value associated to the specified key.
382      * 
383      * @param key
384      *            Key of the group of values.
385      * @param index
386      *            Index of the value in the group to read.
387      * @return Value; <tt>""</tt> if unknown.
388      * @see LAAnalysis#getStringValue(Comparable, int)
389      */
390     public String getString(Comparable key, int index) {
391         return getStringValue(key, index);
392     }
393 
394     /***
395      * Return the resulting value associated to the specified key.
396      * 
397      * @param key
398      *            Key of the group of values.
399      * @param name
400      *            Name of the value in the group to read.
401      * @return Value; <tt>0</tt> if unknown.
402      * @see LAAnalysis#getStringValue(Comparable, int)
403      * @see LAAnalysis#getValueNameIndex(String)
404      */
405     public String getString(Comparable key, String name) {
406         return getStringValue(key, getValueNameIndex(name));
407     }
408 
409     /***
410      * Return the resulting value associated to the specified key.
411      * 
412      * @param key
413      *            Key of the group of values.
414      * @param index
415      *            Index of the value in the group to read.
416      * @return Value; <tt>null</tt> if unknown.
417      * @see LAAnalysis#getObjectValue(Comparable, int)
418      */
419     public Object getValue(Comparable key, int index) {
420         return getObjectValue(key, index);
421     }
422 
423     /***
424      * Return the resulting value associated to the specified key.
425      * 
426      * @param key
427      *            Key of the group of values.
428      * @param name
429      *            Name of the value in the group to read.
430      * @return Value; <tt>null</tt> if unknown.
431      * @see LAAnalysis#getObjectValue(Comparable, int)
432      * @see LAAnalysis#getValueNameIndex(String)
433      */
434     public Object getValue(Comparable key, String name) {
435         return getObjectValue(key, getValueNameIndex(name));
436     }
437 
438     /***
439      * Return the value name.
440      * 
441      * @param index
442      *            Index of the value.
443      * @return Value name.
444      * @see LAAnalysis#getValueName(int)
445      */
446     public String getName(int index) {
447         return getValueName(index);
448     }
449 
450     /***
451      * Return the index of the value name.
452      * 
453      * @param name
454      *            Name of value.
455      * @return Index of the value name.
456      * @see LAAnalysis#getValueNameIndex(String)
457      */
458     public int getNameIndex(String name) {
459         return getValueNameIndex(name);
460     }
461 
462     /***
463      * Return the values names.
464      * 
465      * @return Values names.
466      * @see LAAnalysis#getValuesNames()
467      */
468     public String[] getNames() {
469         return getValuesNames();
470     }
471 
472     /***
473      * Change the specified old key to the new key.
474      * 
475      * @param oldKey
476      *            Key to change.
477      * @param newKey
478      *            New key.
479      */
480     public void change(Comparable oldKey, Comparable newKey) {
481         changeKey(oldKey, newKey);
482     }
483 
484     /***
485      * Remove the specified key of the analysis.
486      * 
487      * @param key
488      *            Key to remove.
489      */
490     public void remove(Comparable key) {
491         removeKey(key);
492     }
493 
494     /***
495      * Remove the key at the specified index of the analysis.
496      * 
497      * @param keyIndex
498      *            Key index to remove.
499      */
500     public void remove(int keyIndex) {
501         removeKey(keyIndex);
502     }
503 
504     /***
505      * Sort results by the specified value form lowest to greatest.
506      * 
507      * @param index
508      *            Index of the value used to sort results.
509      */
510     public void sortASC(int index) {
511         sortByValueASC(index);
512     }
513 
514     /***
515      * Sort results by the specified value form lowest to greatest.
516      * 
517      * @param name
518      *            Value name used to sort results.
519      */
520     public void sortASC(String name) {
521         sortByValueASC(getValueNameIndex(name));
522     }
523 
524     /***
525      * Sort results by the specified value form greatest to lowest.
526      * 
527      * @param index
528      *            Index of the value used to sort results.
529      */
530     public void sortDESC(int index) {
531         sortByValueDESC(index);
532     }
533 
534     /***
535      * Sort results by the specified value form greatest to lowest.
536      * 
537      * @param name
538      *            Value name used to sort results.
539      */
540     public void sortDESC(String name) {
541         sortByValueDESC(getValueNameIndex(name));
542     }
543 }