KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > monitor > util > StatisticToString


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /*
25  * Copyright 2004-2005 Sun Microsystems, Inc. All rights reserved.
26  * Use is subject to license terms.
27  */

28
29 /*
30  * StatisticToString.java
31  * $Id: StatisticToString.java,v 1.2 2005/12/25 03:52:33 tcfujii Exp $
32  * $Date: 2005/12/25 03:52:33 $
33  * $Revision: 1.2 $
34  */

35
36
37 package com.sun.enterprise.admin.monitor.util;
38
39 import javax.management.j2ee.statistics.Statistic JavaDoc;
40 import javax.management.j2ee.statistics.CountStatistic JavaDoc;
41 import javax.management.j2ee.statistics.BoundedRangeStatistic JavaDoc;
42 import javax.management.j2ee.statistics.RangeStatistic JavaDoc;
43 import javax.management.j2ee.statistics.TimeStatistic JavaDoc;
44
45 /**
46  * Provides for String representation of all the Statistic classes.
47  * @author <a HREF="mailto:Kedar.Mhaswade@sun.com">Kedar Mhaswade</a>
48  * @since S1AS8.0
49  * @version $Revision: 1.2 $
50  */

51 final class StatisticToString {
52     
53     private final Statistic JavaDoc stc;
54     private final String JavaDoc SEP = ":";
55     /** Creates a new instance of StatisticToString for given Statistic. Instances of
56      * this class are immutable. Note that the returned Strings are basically for debug
57      * purposes and should be displayed taking that into account.
58      * @param c Statistic instance that needs its string representation from this class
59      */

60     StatisticToString(Statistic JavaDoc stc) {
61         this.stc = stc;
62     }
63     
64     /**
65      */

66     public String JavaDoc toString() {
67         final StringBuffer JavaDoc s = new StringBuffer JavaDoc();
68         return ( s.append(baseString()).append(SEP).append(specificString()).toString() );
69     }
70     
71     private String JavaDoc baseString() {
72         final StringBuffer JavaDoc s = new StringBuffer JavaDoc();
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 JavaDoc specificString() {
78         final StringBuffer JavaDoc s = new StringBuffer JavaDoc();
79         if (stc instanceof CountStatistic JavaDoc)
80             s.append(countStatisticSpecificString());
81         if (stc instanceof RangeStatistic JavaDoc)
82             s.append(rangeStatisticSpecificString());
83         if (stc instanceof BoundedRangeStatistic JavaDoc)
84             s.append(boundedRangeStatisticSpecificString());
85         if (stc instanceof TimeStatistic JavaDoc)
86             s.append(timeStatisticSpecificString());
87         return ( s.toString() );
88     }
89     private String JavaDoc countStatisticSpecificString() {
90         final StringBuffer JavaDoc s = new StringBuffer JavaDoc();
91         final CountStatistic JavaDoc cs = (CountStatistic JavaDoc)stc;
92         return ( s.append(cs.getCount()).toString() );
93     }
94     private String JavaDoc rangeStatisticSpecificString() {
95         final StringBuffer JavaDoc s = new StringBuffer JavaDoc();
96         final RangeStatistic JavaDoc rs = (RangeStatistic JavaDoc)stc;
97         return ( s.append(rs.getLowWaterMark()).append(SEP).append(rs.getHighWaterMark()).toString() );
98     }
99     private String JavaDoc boundedRangeStatisticSpecificString() {
100         final StringBuffer JavaDoc s = new StringBuffer JavaDoc();
101         final BoundedRangeStatistic JavaDoc bs = (BoundedRangeStatistic JavaDoc)stc;
102         return ( s.append(bs.getUpperBound()).append(SEP).append(bs.getLowerBound()).toString() );
103     }
104     private String JavaDoc timeStatisticSpecificString() {
105         final StringBuffer JavaDoc s = new StringBuffer JavaDoc();
106         final TimeStatistic JavaDoc ts = (TimeStatistic JavaDoc)stc;
107         return ( s.append(ts.getMaxTime()).append(SEP).append(ts.getMinTime()).append(SEP).append(ts.getTotalTime()).toString() );
108     }
109 }
110
Popular Tags