KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > roblisa > classfinder > LibClass


1 /**
2  * ClassFinder - a javadoc webserver.
3  * Copyright (C) 2003 Rob Nielsen
4  * rob@roblisa.com
5  * http://www.roblisa.com/java/classfinder/
6  *
7  * Released under the GNU GPL - http://www.gnu.org/copyleft/gpl.html
8  */

9 package com.roblisa.classfinder;
10
11 public class LibClass implements Comparable
12 {
13     public static final int DOC=1;
14     public static final int SRC=2;
15     public static final int CLA=4;
16
17     private static final String[] order=new String[]{"java.lang","java.util","java.io","java"};
18
19     public static final int START=0;
20     public static final int END=1;
21     public static final int EQUAL=2;
22     public static final int CONTAINS=3;
23
24     String path;
25     String fullName;
26     String name;
27     int ord;
28     int available;
29
30     public LibClass(String path)
31     {
32
33         this.path=path;
34         this.fullName=path.replace('/','.');
35         int ind=path.lastIndexOf('/');
36         if (ind!=-1)
37             name=path.substring(ind+1).toLowerCase();
38         ord=order.length;
39         for(int i=0;i<order.length;i++)
40         {
41             if (fullName.startsWith(order[i]))
42             {
43                 ord=i;
44                 break;
45             }
46         }
47     }
48
49     public boolean hasResource(int field)
50     {
51         return (available&field)>0;
52     }
53
54     public void setResource(int field)
55     {
56         if (!hasResource(field))
57             available+=field;
58     }
59
60     public String getSortName()
61     {
62         return name;
63     }
64
65     public String getClassName()
66     {
67         return fullName;
68     }
69
70     public String getClassPath()
71     {
72         return path;
73     }
74
75     public String getPackage()
76     {
77         return fullName.substring(0,fullName.length()-name.length()-1);
78     }
79
80     public String getName()
81     {
82         return fullName.substring(fullName.length()-name.length());
83     }
84
85     public String getSourceName()
86     {
87         int dot=name.indexOf('.');
88         if (dot!=-1)
89         {
90             return fullName.substring(fullName.length()-name.length(),fullName.length()-dot);
91         }
92         else
93             return getName();
94     }
95
96     public String getSourcePath()
97     {
98         int dot=path.lastIndexOf('.');
99         if (dot!=-1)
100             return path.substring(0,dot);
101         else
102             return path;
103     }
104
105     public int compareTo(Object o)
106     {
107         LibClass cla=(LibClass)o;
108         if (cla.ord!=ord)
109             return ord-cla.ord;
110
111         return String.CASE_INSENSITIVE_ORDER.compare(path,cla.path);
112     }
113
114     public boolean checkMatch(String m,int type,boolean full)
115     {
116         String test=full?fullName:name;
117         switch(type)
118         {
119             case START: return (test.startsWith(m));
120             case END: return (test.endsWith(m));
121             case EQUAL: return (test.equals(m));
122             case CONTAINS: return (test.indexOf(m)!=-1);
123         }
124         return false;
125     }
126 }
Popular Tags