1 22 package org.jboss.varia.stats; 23 24 25 29 public abstract class AbstractStatisticalItem 30 implements StatisticalItem 31 { 32 protected final String name; 33 protected String 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 name) 40 { 41 this.name = name; 42 } 43 44 public String getName() 45 { 46 return name; 47 } 48 49 public String 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 ("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 minCountPerTx = 0; 102 } 103 104 public int getMergedItemsTotal() 105 { 106 return mergedItemsTotal; 107 } 108 } 109 | Popular Tags |