KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > appserv > management > j2ee > statistics > StatisticImpl


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  * $Header: /cvs/glassfish/admin-core/mbeanapi/src/java/com/sun/appserv/management/j2ee/statistics/StatisticImpl.java,v 1.5 2005/12/25 03:50:56 tcfujii Exp $
26  * $Revision: 1.5 $
27  * $Date: 2005/12/25 03:50:56 $
28  */

29
30 package com.sun.appserv.management.j2ee.statistics;
31
32 import java.io.Serializable JavaDoc;
33 import java.util.Map JavaDoc;
34
35 import javax.management.j2ee.statistics.Statistic JavaDoc;
36
37 import com.sun.appserv.management.util.misc.MapUtil;
38 import com.sun.appserv.management.util.misc.ObjectUtil;
39 import com.sun.appserv.management.util.j2ee.stringifier.StatisticStringifier;
40 import com.sun.appserv.management.util.j2ee.J2EEUtil;
41
42
43 /**
44     Implementation of Statistic which records its values in member
45     variables.
46  */

47 public class StatisticImpl implements Statistic JavaDoc, Serializable JavaDoc
48 {
49     static final long serialVersionUID = -8120492090789878204L;
50     
51     /* members names as defined by JSR 77 */
52     
53     private final String JavaDoc mName;
54     private final String JavaDoc mDescription;
55     private final String JavaDoc mUnit;
56     protected long mLastSampleTime;
57     private final long mStartTime;
58     
59         public
60     StatisticImpl(
61         final String JavaDoc name,
62         final String JavaDoc description,
63         final String JavaDoc unit,
64         final long startTime,
65         final long lastSampleTime )
66     {
67         mName = name;
68         mDescription = description;
69         mUnit = unit;
70         mLastSampleTime = lastSampleTime;
71         mStartTime = startTime;
72     }
73     
74         public
75     StatisticImpl( final Statistic JavaDoc s )
76     {
77         mName = s.getName();
78         mDescription = s.getDescription();
79         mUnit = s.getUnit();
80         mLastSampleTime = s.getLastSampleTime();
81         mStartTime = s.getStartTime();
82     }
83     
84     /**
85         Get the description for this Statistic
86      */

87         public String JavaDoc
88     getDescription()
89     {
90         return( mDescription );
91     }
92     
93     
94     /**
95         Get the last sample time for this Statistic
96      */

97         public long
98     getLastSampleTime()
99     {
100         return( mLastSampleTime );
101     }
102     
103     /**
104         Get the name of this Statistic
105      */

106         public String JavaDoc
107     getName()
108     {
109         return( mName );
110     }
111     
112     /**
113         Get the start time for this Statistic
114      */

115         public long
116     getStartTime()
117     {
118         return( mStartTime );
119     }
120     
121     
122     /**
123         Get the units associated with this statistic.
124      */

125         public String JavaDoc
126     getUnit()
127     {
128         return( mUnit );
129     }
130     
131         public String JavaDoc
132     toString()
133     {
134         return StatisticStringifier.DEFAULT.stringify( this );
135     }
136     
137     
138         public int
139     hashCode()
140     {
141         return ObjectUtil.hashCode( mName, mDescription, mUnit) ^
142                 ObjectUtil.hashCode( mLastSampleTime ) ^
143                 ObjectUtil.hashCode( mStartTime );
144     }
145     
146         public boolean
147     equals( final Object JavaDoc rhs )
148     {
149         boolean equals = false;
150         
151         if ( rhs instanceof Statistic JavaDoc )
152         {
153             final Statistic JavaDoc s = (Statistic JavaDoc)rhs;
154             
155             equals = getName().equals( s.getName() ) &&
156                         getUnit().equals( s.getUnit() ) &&
157                         getDescription().equals( s.getDescription() ) &&
158                         getStartTime() == s.getStartTime() &&
159                         getLastSampleTime() == s.getLastSampleTime();
160         }
161         return( equals );
162     }
163     
164 }
165
166
167
168
169
170
Popular Tags