KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > groboutils > codecoverage > v2 > logger > TestLogger


1 /*
2  * @(#)TestLogger.java
3  *
4  * Copyright (C) 2003 Matt Albrecht
5  * groboclown@users.sourceforge.net
6  * http://groboutils.sourceforge.net
7  *
8  * Permission is hereby granted, free of charge, to any person obtaining a
9  * copy of this software and associated documentation files (the "Software"),
10  * to deal in the Software without restriction, including without limitation
11  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12  * and/or sell copies of the Software, and to permit persons to whom the
13  * Software is furnished to do so, subject to the following conditions:
14  *
15  * The above copyright notice and this permission notice shall be included in
16  * all copies or substantial portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24  * DEALINGS IN THE SOFTWARE.
25  */

26
27 package net.sourceforge.groboutils.codecoverage.v2.logger;
28
29 import java.util.ArrayList JavaDoc;
30 import java.util.HashMap JavaDoc;
31 import java.util.Iterator JavaDoc;
32 import java.util.List JavaDoc;
33
34 import net.sourceforge.groboutils.codecoverage.v2.compiler.ParseCoverageLogger;
35
36
37 /**
38  * Replacement logger.
39  *
40  * @author Matt Albrecht <a HREF="mailto:groboclown@users.sourceforge.net">groboclown@users.sourceforge.net</a>
41  * @version $Date: 2004/04/15 05:48:28 $
42  * @since January 27, 2003
43  */

44 public class TestLogger
45 {
46     public static class MarkData
47     {
48         public String JavaDoc classSig;
49         public short measureIndex;
50         public short methodIndex;
51         public short markIndex;
52         
53         public MarkData( String JavaDoc sig, short meaI, short metI, short marI )
54         {
55             this.classSig = sig;
56             this.measureIndex = meaI;
57             this.methodIndex = metI;
58             this.markIndex = marI;
59         }
60         
61         public String JavaDoc toString()
62         {
63             return "[Class Sig="+this.classSig+";measure="+
64                 this.measureIndex+";method="+this.methodIndex+
65                 ";mark="+this.markIndex+"]";
66         }
67     }
68     
69     private static HashMap JavaDoc marksPerThread = new HashMap JavaDoc();
70     
71     public static ParseCoverageLogger createPCL()
72     {
73         return new ParseCoverageLogger( TestLogger.class, "cover" );
74     }
75         
76         
77     public static void cover( String JavaDoc classSig,
78             short methodIndex, short channel, short markIndex )
79     {
80         //DOC.getLog().info( "Inside cover" );
81
List JavaDoc list = getThreadList();
82         MarkData md = new MarkData( classSig, channel, methodIndex,
83             markIndex );
84         synchronized( list )
85         {
86             //DOC.getLog().info( "adding mark: "+md );
87
list.add( md );
88         }
89     }
90         
91         
92     public static void reset()
93     {
94         List JavaDoc list = getThreadList();
95         synchronized( list )
96         {
97             list.clear();
98         }
99     }
100     
101     
102     public static int size()
103     {
104         return getThreadList().size();
105     }
106     
107     
108     public static Iterator JavaDoc getMarkData()
109     {
110         return getThreadList().iterator();
111     }
112     
113     
114     private static List JavaDoc getThreadList()
115     {
116         List JavaDoc list;
117         synchronized( TestLogger.class )
118         {
119             list = (List JavaDoc)marksPerThread.get( Thread.currentThread() );
120             if (list == null)
121             {
122                 list = new ArrayList JavaDoc();
123                 marksPerThread.put( Thread.currentThread(), list );
124             }
125         }
126         return list;
127     }
128 }
129
130
Popular Tags