# Coverage details for com.martiansoftware.nailgun.NailStats

Line | Hits | Source
--- | --- | ---
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 |  | `*/`
38 | 1 | `NailStats(Class nailclass) {`
39 | 1 | `this.nailclass = nailclass;`
40 | 1 | `runCounter = 0;`
41 | 1 | `refCounter = 0;`
42 | 1 | `lock = new Object();`
43 | 1 | `}`
44 |  | ``
45 |  | `/**`
46 |  | `* Logs the fact that an instance of this nail has started`
47 |  | `*/`
48 |  | `void nailStarted() {`
49 | 1000 | `synchronized(lock) {`
50 | 1000 | `++runCounter;`
51 | 1000 | `++refCounter;`
52 | 1000 | `}`
53 | 1000 | `}`
54 |  | ``
55 |  | `/**`
56 |  | `* Logs the fact that an instance of this nail has finished`
57 |  | `*/`
58 |  | `void nailFinished() {`
59 | 1000 | `synchronized(lock) {`
60 | 1000 | `--refCounter;`
61 | 1000 | `}`
62 | 1000 | `}`
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() {`
71 | 1002 | `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() {`
79 | 1002 | `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() {`
87 | 1 | `return (nailclass);`
88 |  | `}`
89 |  | ``
90 |  | `/**`
91 |  | `* @see java.lang.Object#hashCode`
92 |  | `*/`
93 |  | `public int hashCode() {`
94 | 2 | `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) {`
105 | 1 | `NailStats other = (NailStats) o;`
106 | 1 | `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() {`
114 | 1 | `Object result = null;`
115 |  | `try {`
116 | 1 | `result = super.clone();`
117 | 1 | `} catch (CloneNotSupportedException toDiscard) {}`
118 | 1 | `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() {`
128 | 1 | `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.