1 /*
2 * Jour - java profiler and monitoring library
3 *
4 * Copyright (C) 2004 Jour team
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
15 *
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
20 */
21 package net.sf.jour.statistic;
22
23 import java.util.*;
24
25
26 import org.apache.log4j.Logger;
27
28 /***
29 * TODO Add docs
30 *
31 * Created on 13.12.2004
32 * Contributing Author(s):
33 *
34 * Misha Lifschitz <mishalifschitz at users.sourceforge.net> (Inital implementation)
35 * Vlad Skarzhevskyy <vlads at users.sourceforge.net> (Inital implementation)
36 *
37 * @author vlads
38 * @version $Revision: 1.2 $ ($Author: vlads $) $Date: 2004/12/15 08:00:40 $
39 */
40 public class AccumulationItmesList extends AccumulationItem implements AccumulationList {
41
42 protected static final Logger log = Logger.getLogger(AccumulationItmesList.class);
43
44 private Map items;
45
46 /*
47 * Speed up processing and do not create the lists.
48 */
49 private boolean simpleAccumulation = false;
50
51
52 public AccumulationItmesList() {
53 items = new HashMap();
54 }
55
56 /***
57 * Allow inherited overwite the new Accumulations types
58 */
59 public Accumulation createAccumulation(Object key) {
60 return new AccumulationItem();
61 }
62
63 public void onNewAccumulation(Object key, Accumulation accumulation) {
64
65 }
66
67 public void reset() {
68 super.reset();
69 this.items = new HashMap();
70 }
71
72 /* (non-Javadoc)
73 * @see net.sf.jour.statistic.AccumulationList#add(java.lang.Object, java.lang.Object)
74 */
75 public void add(Object key, Object num) {
76 if (!this.simpleAccumulation) {
77 Accumulation accumulation = getItem(key);
78 if (accumulation == null) {
79 accumulation = createAccumulation(key);
80 onNewAccumulation(key, accumulation);
81 items.put(key, accumulation);
82 }
83 accumulation.add(num);
84 }
85 super.add(num);
86 }
87
88 /* (non-Javadoc)
89 * @see net.sf.jour.statistic.AccumulationList#getKeys()
90 */
91 public Set getKeys() {
92 // TODO Auto-generated method stub
93 return items.keySet();
94 }
95
96 /* (non-Javadoc)
97 * @see net.sf.jour.statistic.AccumulationList#getItem(java.lang.Object)
98 */
99 public Accumulation getItem(Object key) {
100 return (Accumulation)items.get(key);
101 }
102
103 }