1 23 24 package net.sourceforge.cobertura.coveragedata; 25 26 import java.util.Collection ; 27 import java.util.Iterator ; 28 import java.util.SortedMap ; 29 import java.util.SortedSet ; 30 import java.util.TreeMap ; 31 import java.util.TreeSet ; 32 33 public class PackageData extends CoverageDataContainer 34 implements Comparable , HasBeenInstrumented 35 { 36 37 private static final long serialVersionUID = 5; 38 39 private String name; 40 41 public PackageData(String name) 42 { 43 if (name == null) 44 throw new IllegalArgumentException ( 45 "Package name must be specified."); 46 this.name = name; 47 } 48 49 public void addClassData(ClassData classData) 50 { 51 if (children.containsKey(classData.getBaseName())) 52 throw new IllegalArgumentException ("Package " + this.name 53 + " already contains a class with the name " 54 + classData.getBaseName()); 55 56 children.put(classData.getBaseName(), classData); 59 } 60 61 64 public int compareTo(Object o) 65 { 66 if (!o.getClass().equals(PackageData.class)) 67 return Integer.MAX_VALUE; 68 return this.name.compareTo(((PackageData)o).name); 69 } 70 71 public boolean contains(String name) 72 { 73 return this.children.containsKey(name); 74 } 75 76 81 public boolean equals(Object obj) 82 { 83 if (this == obj) 84 return true; 85 if ((obj == null) || !(obj.getClass().equals(this.getClass()))) 86 return false; 87 88 PackageData packageData = (PackageData)obj; 89 return super.equals(obj) && this.name.equals(packageData.name); 90 } 91 92 public SortedSet getClasses() 93 { 94 return new TreeSet (this.children.values()); 95 } 96 97 public String getName() 98 { 99 return this.name; 100 } 101 102 public String getSourceFileName() 103 { 104 return this.name.replace('.', '/'); 105 } 106 107 public Collection getSourceFiles() 108 { 109 SortedMap sourceFileDatas = new TreeMap (); 110 Iterator iter = this.children.values().iterator(); 111 while (iter.hasNext()) { 112 ClassData classData = (ClassData)iter.next(); 113 String sourceFileName = classData.getSourceFileName(); 114 SourceFileData sourceFileData = (SourceFileData)sourceFileDatas.get(sourceFileName); 115 if (sourceFileData == null) 116 { 117 sourceFileData = new SourceFileData(sourceFileName); 118 sourceFileDatas.put(sourceFileName, sourceFileData); 119 } 120 sourceFileData.addClassData(classData); 121 } 122 return sourceFileDatas.values(); 123 } 124 125 public int hashCode() 126 { 127 return this.name.hashCode(); 128 } 129 130 } 131 | Popular Tags |