KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > groboutils > codecoverage > v2 > datastore > MarkRecord


1 /*
2  * @(#)MarkRecord.java
3  *
4  * Copyright (C) 2002-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.datastore;
28
29 import net.sourceforge.groboutils.codecoverage.v2.IAnalysisMetaData;
30
31 /**
32  * Contains data associated with an analysis module's bytecode instruction
33  * mark. It should be associated with a particular class.
34  *
35  * @author Matt Albrecht <a HREF="mailto:groboclown@users.sourceforge.net">groboclown@users.sourceforge.net</a>
36  * @version $Date: 2003/11/25 13:10:41 $
37  * @since December 15, 2002
38  */

39 public class MarkRecord
40 {
41     private IAnalysisMetaData amd;
42     private String JavaDoc analysisModule;
43     private String JavaDoc methodSignature;
44     private short markIndex;
45     
46     private short amIndex = -1;
47     private short methIndex = -1;
48     private int lineNo = -1;
49     
50     
51     /**
52      * @param data cannot be <tt>null</tt>.
53      * @param am the analysis module that made this mark.
54      * @param methSig the method signature where this mark was placed.
55      * @param lineNumber the Java source line corresponding to this mark.
56      */

57     public MarkRecord( IAnalysisMetaData data, String JavaDoc am, String JavaDoc methSig,
58             short markId, int lineNumber )
59     {
60         if (data == null || am == null || methSig == null)
61         {
62             throw new IllegalArgumentException JavaDoc( "No null args." );
63         }
64         if (markId < 0)
65         {
66             throw new IllegalArgumentException JavaDoc(
67                 "Indicies cannot be less than 0.");
68         }
69         this.amd = data;
70         this.analysisModule = am;
71         this.methodSignature = methSig;
72         this.markIndex = markId;
73         this.lineNo = lineNumber;
74     }
75     
76     
77     /**
78      * @see ClassRecord#addMark( MarkRecord )
79      */

80     void processMark( ClassRecord cr, AnalysisModuleSet ams )
81     {
82         if (cr == null)
83         {
84             throw new IllegalArgumentException JavaDoc( "No null args." );
85         }
86         if (ams == null)
87         {
88             ams = cr.getAnalysisModuleSet();
89         }
90         this.amIndex = ams.getMeasureIndex( getAnalysisModule() );
91         this.methIndex = cr.getMethodIndex( getMethodSignature() );
92     }
93     
94     
95     public boolean equals( Object JavaDoc o )
96     {
97         if (o == null || !(o instanceof MarkRecord))
98         {
99             return false;
100         }
101         if (this == o)
102         {
103             return true;
104         }
105         
106         // line number doesn't add into the equals.
107
MarkRecord mr = (MarkRecord)o;
108         if (mr.analysisModule.equals( this.analysisModule ) &&
109             mr.methodSignature.equals( this.methodSignature ) &&
110             mr.markIndex == this.markIndex)
111         {
112             // the amd object doesn't have to match.
113
return true;
114         }
115         // else
116
return false;
117     }
118     
119     
120     public int hashCode()
121     {
122         return (int)this.markIndex +
123             this.analysisModule.hashCode() +
124             this.methodSignature.hashCode();
125     }
126     
127     
128     public IAnalysisMetaData getAnalysisMetaData()
129     {
130         return this.amd;
131     }
132     
133     
134     public String JavaDoc getAnalysisModule()
135     {
136         return this.analysisModule;
137     }
138     
139     
140     public short getAnalysisModuleIndex()
141     {
142         if (this.amIndex < 0)
143         {
144             throw new IllegalStateException JavaDoc(
145                 "Never processed or unknown module '"+this.analysisModule+
146                 "'." );
147         }
148         return this.amIndex;
149     }
150     
151     
152     public String JavaDoc getMethodSignature()
153     {
154         return this.methodSignature;
155     }
156     
157     
158     public short getMethodIndex()
159     {
160         if (this.methIndex < 0)
161         {
162             throw new IllegalStateException JavaDoc(
163                 "Never processed or unknown method '"+this.methodSignature+
164                 "'." );
165         }
166         return this.methIndex;
167     }
168     
169     
170     public short getMarkIndex()
171     {
172         return this.markIndex;
173     }
174     
175     
176     public int getLineNumber()
177     {
178         return this.lineNo;
179     }
180     
181     
182     public String JavaDoc toString()
183     {
184         return "Mark Record: "+getMethodSignature()+", mark "+getMarkIndex();
185     }
186 }
187
188
Popular Tags