/Users/lyon/j4p/src/classUtils/putils/ClassList.java

1    /** 
2     * 
3     * @author D. Lyon 
4     * @version 1.0 
5     * Date: Apr 1, 2002 
6     * Time: 2:39:17 PM 
7     */ 
8    package classUtils.putils; 
9     
10   import classUtils.reflection.ReflectUtil; 
11    
12   import java.util.Arrays; 
13   import java.util.Comparator; 
14   import java.util.Vector; 
15    
16   public class ClassList { 
17       private Vector v = new Vector(); 
18    
19       public Vector getVector() { 
20           return v; 
21       } 
22    
23       public void add(Class c) { 
24           v.addElement(c); 
25       } 
26    
27       public void add(Class c[]) { 
28           for (int i = 0; i < c.length; i++) 
29               add(c[i]); 
30       } 
31    
32       public static void sort(Class ca[]) { 
33           Arrays.sort(ca, 
34                   new ClassComparator() 
35           ); 
36       } 
37    
38       private static class ClassComparator implements Comparator { 
39           public int compare(Object a, Object b) { 
40               return ((Class) a).getName().compareTo( 
41                       ((Class) b).getName()); 
42           } 
43       } 
44    
45       public static void main(String args[]) { 
46           Package p = Package.getPackage("java.lang"); 
47           System.out.println(p); 
48       } 
49    
50    
51       public int getNumberOfMethods() { 
52           Class ca[] = getClasses(); 
53           int n = 0; 
54           for (int i = 0; i < ca.length; i++) { 
55               ReflectUtil ru = 
56                       new ReflectUtil(ca[i]); 
57               n = n + ru.getMethods().length; 
58           } 
59           return n; 
60       } 
61    
62       public Class[] getClasses() { 
63           Class ca[] = new Class[v.size()]; 
64           v.copyInto(ca); 
65           return ca; 
66       } 
67    
68       public String toString() { 
69           StringBuffer sb = new StringBuffer(); 
70           for (int i = 0; i < v.size(); i++) 
71               sb.append(v.elementAt(i) + ""); 
72           return sb.toString(); 
73       } 
74    
75       public void print() { 
76           for (int i = 0; i < v.size(); i++) 
77               System.out.println(v.elementAt(i)); 
78           System.out.println("printed " 
79                   + v.size() + " classes"); 
80       } 
81    
82       public int getSize() { 
83           return v.size(); 
84       } 
85   } 
86