1 26 27 package net.sourceforge.groboutils.codecoverage.v2.report; 28 29 30 import java.util.HashMap ; 31 import java.util.HashSet ; 32 import java.util.Map ; 33 import java.util.Set ; 34 35 import net.sourceforge.groboutils.codecoverage.v2.IAnalysisMetaData; 36 37 38 46 public class PackageSorter 47 { 48 private Map packagesToClassSet = new HashMap (); 49 50 53 public PackageSorter() 54 { 55 } 57 58 59 public void addClassSignatures( String classSigs[] ) 60 { 61 if (classSigs == null) 62 { 63 throw new IllegalArgumentException ("no null args"); 64 } 65 66 for (int i = 0; i < classSigs.length; ++i) 67 { 68 addClassSignature( classSigs[i] ); 69 } 70 } 71 72 73 public void addClassSignature( String classSig ) 74 { 75 if (classSig == null) 76 { 77 throw new IllegalArgumentException ("no null args"); 78 } 79 80 String packageName = getPackageName( classSig ); 81 Set classSigSet = (Set )this.packagesToClassSet.get( packageName ); 82 if (classSigSet == null) 83 { 84 classSigSet = new HashSet (); 85 this.packagesToClassSet.put( packageName, classSigSet ); 86 } 87 classSigSet.add( classSig ); 88 } 89 90 91 94 public String [] getPackages() 95 { 96 Set s = this.packagesToClassSet.keySet(); 97 String [] pkgs = (String [])s.toArray( new String [ s.size() ] ); 98 return pkgs; 99 } 100 101 102 105 public String [] getClassSignaturesForPackage( String packageName ) 106 { 107 Set s = (Set )this.packagesToClassSet.get( packageName ); 108 if (s == null) 109 { 110 return new String [0]; 111 } 112 return (String [])s.toArray( new String [ s.size() ] ); 113 } 114 115 116 public static String getPackageName( String classSig ) 117 { 118 if (classSig == null) 119 { 120 throw new IllegalArgumentException ("no null args"); 121 } 122 String pkg = ""; 123 int pos = classSig.lastIndexOf( '.' ); 124 if (pos >= 0) 125 { 126 pkg = classSig.substring( 0, pos ); 127 } 128 return pkg; 129 } 130 } 131 132 | Popular Tags |