Coverage details for com.martiansoftware.nailgun.NailStats

LineHitsSource
1 /*
2  
3   Copyright 2004, Martian Software, Inc.
4  
5   Licensed under the Apache License, Version 2.0 (the "License");
6   you may not use this file except in compliance with the License.
7   You may obtain a copy of the License at
8  
9   http://www.apache.org/licenses/LICENSE-2.0
10  
11   Unless required by applicable law or agreed to in writing, software
12   distributed under the License is distributed on an "AS IS" BASIS,
13   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   See the License for the specific language governing permissions and
15   limitations under the License.
16  
17 */
18  
19 package com.martiansoftware.nailgun;
20  
21 /**
22  * <p>Collects and provides statistics on a nail.</p>
23  *
24  * @author <a href="http://www.martiansoftware.com/contact.html">Marty Lamb</a>
25  */
26  
27 public class NailStats implements Cloneable {
28  
29     private Class nailclass;
30     private long runCounter;
31     private long refCounter;
32     private Object lock;
33     
34     /**
35      * Creates a new NailStats object for the specified class
36      * @param nailclass the class for which we'll collect statistics
37      */
381    NailStats(Class nailclass) {
391        this.nailclass = nailclass;
401        runCounter = 0;
411        refCounter = 0;
421        lock = new Object();
431    }
44  
45     /**
46      * Logs the fact that an instance of this nail has started
47      */
48     void nailStarted() {
491000        synchronized(lock) {
501000            ++runCounter;
511000            ++refCounter;
521000        }
531000    }
54     
55     /**
56      * Logs the fact that an instance of this nail has finished
57      */
58     void nailFinished() {
591000        synchronized(lock) {
601000            --refCounter;
611000        }
621000    }
63  
64     /**
65      * Returns the number of times this nail has been run. Nails
66      * that have started but not yet finished are included in this
67      * number.
68      * @return the number of times this nail has been run.
69      */
70     public long getRunCount() {
711002        return (runCounter);
72     }
73     
74     /**
75      * Returns the number of sessions currently running this nail.
76      * @return the number of sessions currently running this nail.
77      */
78     public long getRefCount() {
791002        return (refCounter);
80     }
81     
82     /**
83      * Returns the class for which we're tracking statistics
84      * @return the class for which we're tracking statistics
85      */
86     public Class getNailClass() {
871        return (nailclass);
88     }
89     
90     /**
91      * @see java.lang.Object#hashCode
92      */
93     public int hashCode() {
942        return (nailclass.hashCode());
95     }
96     
97     /**
98      * Returns true iff the specified <code>NailStats</code> object
99      * is tracking the same class.
100      * @param o the NailStats object to check
101      * @return true iff the specified <code>NailStats</code> object
102      * is tracking the same class.
103      */
104     public boolean equals(Object o) {
1051        NailStats other = (NailStats) o;
1061        return (nailclass.equals(other.nailclass));
107     }
108     
109     /**
110      * Creates a copy of this <code>NailStats</code> object.
111      * @return a copy of this <code>NailStats</code> object.
112      */
113     public Object clone() {
1141        Object result = null;
115         try {
1161            result = super.clone();
1171        } catch (CloneNotSupportedException toDiscard) {}
1181        return (result);
119     }
120     
121     /**
122      * Returns a String representation of this <code>NailStats</code>
123      * object, in the form "classname: runcount/refcount".
124      * *return a String representation of this <code>NailStats</code>
125      * object.
126      */
127     public String toString() {
1281        return (nailclass.getName() + ": " + getRunCount() + "/" + getRefCount());
129     }
130 }

this report was generated by version 1.0.5 of jcoverage.
visit www.jcoverage.com for updates.

copyright © 2003, jcoverage ltd. all rights reserved.
Java is a trademark of Sun Microsystems, Inc. in the United States and other countries.