1 26 27 package net.sourceforge.groboutils.codecoverage.v2.datastore; 28 29 import java.util.HashMap ; 30 import java.util.Iterator ; 31 import java.util.LinkedList ; 32 import java.util.List ; 33 import java.util.Map ; 34 35 import net.sourceforge.groboutils.codecoverage.v2.IAnalysisModule; 36 import net.sourceforge.groboutils.codecoverage.v2.util.ClassSignatureUtil; 37 38 46 public class ClassRecord 47 { 48 private String className; 49 private long classCRC; 50 private String sourceFileName; 51 private Map methodToIndex; 52 private String [] methodSignatures; 53 private AnalysisModuleSet amSet; 54 private List marks[]; 56 public ClassRecord( String className, long classCRC, String sourceFileName, 57 String [] methSigs, AnalysisModuleSet ams ) 58 { 59 if (className == null || className.length() <= 0 || 61 methSigs == null || ams == null || sourceFileName == null) 62 { 63 throw new IllegalArgumentException ( "No null args." ); 64 } 65 66 this.className = className; 67 this.classCRC = classCRC; 68 this.sourceFileName = sourceFileName; 69 int len = methSigs.length; 70 if (len > Short.MAX_VALUE) 71 { 72 throw new IllegalStateException ( 73 "Too many methods. There is a maximum internal count of "+ 74 Short.MAX_VALUE+"." ); 75 } 76 this.methodSignatures = new String [ len ]; 77 this.methodToIndex = new HashMap (); 78 for (int i = 0; i < len; ++i) 79 { 80 if (methSigs[i] == null) 81 { 82 throw new IllegalArgumentException ( "No null args." ); 83 } 84 85 this.methodSignatures[i] = methSigs[i]; 86 this.methodToIndex.put( methSigs[i], new Short ( (short)i ) ); 87 } 88 89 this.amSet = new AnalysisModuleSet( ams ); 91 len = this.amSet.getAnalysisModuleCount(); 92 this.marks = new List [ len ]; 93 for (int i = 0; i < len; ++i) 94 { 95 this.marks[i] = new LinkedList (); 96 } 97 } 98 99 100 105 public String getClassName() 106 { 107 return this.className; 108 } 109 110 111 116 public long getClassCRC() 117 { 118 return this.classCRC; 119 } 120 121 122 131 public String getClassSignature() 132 { 133 return ClassSignatureUtil.getInstance(). 134 createClassSignature( getClassName(), getClassCRC() ); 135 } 136 137 138 143 public String getSourceFileName() 144 { 145 return this.sourceFileName; 146 } 147 148 149 154 public AnalysisModuleSet getAnalysisModuleSet() 155 { 156 return new AnalysisModuleSet( this.amSet ); 157 } 158 159 160 166 public String [] getMethods() 167 { 168 int len = this.methodSignatures.length; 169 String s[] = new String [ len ]; 170 System.arraycopy( this.methodSignatures, 0, s, 0, len ); 171 return s; 172 } 173 174 175 186 public short getMethodIndex( String methodSignature ) 187 { 188 if (methodSignature == null) 189 { 190 throw new IllegalArgumentException ( "No null args." ); 191 } 192 Short i = (Short )this.methodToIndex.get( methodSignature ); 193 if (i == null) 194 { 195 return -1; 196 } 197 return i.shortValue(); 198 } 199 200 201 206 public int getMethodCount() 207 { 208 return this.methodSignatures.length; 209 } 210 211 212 220 public String getMethodAt( short index ) 221 { 222 int iindex = (int)index; 223 if (iindex < 0 || iindex >= this.methodSignatures.length) 224 { 225 throw new IllegalArgumentException ( "Index out of bounds [0.."+ 226 this.methodSignatures.length+")" ); 227 } 228 return this.methodSignatures[ iindex ]; 229 } 230 231 232 238 public void addMark( MarkRecord mr ) 239 { 240 if (mr == null) 241 { 242 throw new IllegalArgumentException ( "No null args." ); 243 } 244 mr.processMark( this, getAnalysisModuleSet() ); 245 int moduleIndex = (int)mr.getAnalysisModuleIndex(); 246 247 Iterator iter = this.marks[ moduleIndex ].iterator(); 248 boolean add = true; 249 while (iter.hasNext()) 250 { 251 MarkRecord listRecord = (MarkRecord)iter.next(); 252 if (listRecord.equals( mr )) 253 { 254 add = false; 255 break; 256 } 257 } 258 if (add) 259 { 260 this.marks[ moduleIndex ].add( mr ); 261 } 262 } 263 264 265 public MarkRecord[] getMarksForAnalysisModule( String measureName ) 266 { 267 int moduleIndex = (int)this.amSet.getMeasureIndex( measureName ); 268 if (moduleIndex < 0 || moduleIndex >= this.marks.length) 269 { 270 throw new IllegalArgumentException ( 271 "Unknown analysis module '"+measureName+ 272 "' (index = "+moduleIndex+")" ); 273 } 274 275 List list = this.marks[ moduleIndex ]; 276 MarkRecord mr[] = (MarkRecord[])list.toArray( 277 new MarkRecord[ list.size() ] ); 278 return mr; 279 } 280 281 282 public MarkRecord[] getMarksForAnalysisModule( IAnalysisModule am ) 283 { 284 return getMarksForAnalysisModule( am.getMeasureName() ); 285 } 286 } 287 288 | Popular Tags |