KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > varia > stats > AbstractStatisticalItem


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.varia.stats;
23
24
25 /**
26  * @author <a HREF="mailto:alex@jboss.org">Alexey Loubyansky</a>
27  * @version <tt>$Revision: 37459 $</tt>
28  */

29 public abstract class AbstractStatisticalItem
30    implements StatisticalItem
31 {
32    protected final String JavaDoc name;
33    protected String JavaDoc value;
34    private int count = 1;
35    private int minCountPerTx = Integer.MAX_VALUE;
36    private int maxCountPerTx;
37    private int mergedItemsTotal = 1;
38
39    public AbstractStatisticalItem(String JavaDoc name)
40    {
41       this.name = name;
42    }
43
44    public String JavaDoc getName()
45    {
46       return name;
47    }
48
49    public String JavaDoc getValue()
50    {
51       return value;
52    }
53
54    public int getMinCountPerTx()
55    {
56       return minCountPerTx == Integer.MAX_VALUE ? count : minCountPerTx;
57    }
58
59    public int getMaxCountPerTx()
60    {
61       return maxCountPerTx == 0 ? count : maxCountPerTx;
62    }
63
64    public int getCount()
65    {
66       return count;
67    }
68
69    public void add(StatisticalItem item)
70    {
71       if(!getName().equals(item.getName()))
72       {
73          throw new IllegalArgumentException JavaDoc("Can't merge statistical items with different names: " +
74             getName() + " and " + item.getName());
75       }
76
77       this.count += item.getCount();
78    }
79
80    public void merge(StatisticalItem item)
81    {
82       add(item);
83
84       ++mergedItemsTotal;
85
86       int count = item.getCount();
87       if(count > maxCountPerTx)
88       {
89          maxCountPerTx = count;
90       }
91
92       if(count < minCountPerTx)
93       {
94          minCountPerTx = count;
95       }
96    }
97
98    public void mergeNull()
99    {
100       //++mergedItemsTotal;
101
minCountPerTx = 0;
102    }
103
104    public int getMergedItemsTotal()
105    {
106       return mergedItemsTotal;
107    }
108 }
109
Popular Tags