1 23 24 28 29 35 36 37 package com.sun.enterprise.admin.monitor.util; 38 39 import javax.management.j2ee.statistics.Statistic ; 40 import javax.management.j2ee.statistics.CountStatistic ; 41 import javax.management.j2ee.statistics.BoundedRangeStatistic ; 42 import javax.management.j2ee.statistics.RangeStatistic ; 43 import javax.management.j2ee.statistics.TimeStatistic ; 44 45 51 final class StatisticToString { 52 53 private final Statistic stc; 54 private final String SEP = ":"; 55 60 StatisticToString(Statistic stc) { 61 this.stc = stc; 62 } 63 64 66 public String toString() { 67 final StringBuffer s = new StringBuffer (); 68 return ( s.append(baseString()).append(SEP).append(specificString()).toString() ); 69 } 70 71 private String baseString() { 72 final StringBuffer s = new StringBuffer (); 73 s.append(stc.getName()).append(SEP).append(stc.getUnit()).append(SEP). 74 append(stc.getDescription()).append(stc.getStartTime()).append(stc.getStartTime()); 75 return (s.toString()); 76 } 77 private String specificString() { 78 final StringBuffer s = new StringBuffer (); 79 if (stc instanceof CountStatistic ) 80 s.append(countStatisticSpecificString()); 81 if (stc instanceof RangeStatistic ) 82 s.append(rangeStatisticSpecificString()); 83 if (stc instanceof BoundedRangeStatistic ) 84 s.append(boundedRangeStatisticSpecificString()); 85 if (stc instanceof TimeStatistic ) 86 s.append(timeStatisticSpecificString()); 87 return ( s.toString() ); 88 } 89 private String countStatisticSpecificString() { 90 final StringBuffer s = new StringBuffer (); 91 final CountStatistic cs = (CountStatistic )stc; 92 return ( s.append(cs.getCount()).toString() ); 93 } 94 private String rangeStatisticSpecificString() { 95 final StringBuffer s = new StringBuffer (); 96 final RangeStatistic rs = (RangeStatistic )stc; 97 return ( s.append(rs.getLowWaterMark()).append(SEP).append(rs.getHighWaterMark()).toString() ); 98 } 99 private String boundedRangeStatisticSpecificString() { 100 final StringBuffer s = new StringBuffer (); 101 final BoundedRangeStatistic bs = (BoundedRangeStatistic )stc; 102 return ( s.append(bs.getUpperBound()).append(SEP).append(bs.getLowerBound()).toString() ); 103 } 104 private String timeStatisticSpecificString() { 105 final StringBuffer s = new StringBuffer (); 106 final TimeStatistic ts = (TimeStatistic )stc; 107 return ( s.append(ts.getMaxTime()).append(SEP).append(ts.getMinTime()).append(SEP).append(ts.getTotalTime()).toString() ); 108 } 109 } 110 | Popular Tags |