1 package org.codehaus.classworlds;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49 /***
50 * Import description entry.
51 *
52 * @author <a href="mailto:bob@eng.werken.com">bob mcwhirter</a>
53 */
54 class Entry implements Comparable
55 {
56 private final ClassRealm realm;
57
58 private final String pkgName;
59
60 Entry( ClassRealm realm, String pkgName )
61 {
62 this.realm = realm;
63
64 this.pkgName = pkgName;
65 }
66
67
68
69
70
71 /***
72 * Retrieve the realm.
73 *
74 * @return The realm.
75 */
76 ClassRealm getRealm()
77 {
78 return this.realm;
79 }
80
81 /***
82 * Retrieve the page name.
83 *
84 * @return The package name.
85 */
86 String getPackageName()
87 {
88 return this.pkgName;
89 }
90
91 /***
92 * Determine if the classname matches the package
93 * described by this entry.
94 *
95 * @param classname The class name to test.
96 * @return <code>true</code> if this entry matches the
97 * classname, otherwise <code>false</code>.
98 */
99 boolean matches( String classname )
100 {
101 return classname.startsWith( getPackageName() );
102 }
103
104
105
106
107
108 /***
109 * Compare this entry to another for relative ordering.
110 * <p/>
111 * <p/>
112 * The natural ordering of Entry objects is reverse-alphabetical
113 * based upon package name.
114 * </p>
115 *
116 * @param thatObj The object to compare.
117 * @return -1 if this object sorts before that object, 0
118 * if they are equal, or 1 if this object sorts
119 * after that object.
120 */
121 public int compareTo( Object thatObj )
122 {
123 Entry that = (Entry) thatObj;
124
125
126
127
128
129
130
131
132 return ( getPackageName().compareTo( that.getPackageName() ) ) * -1;
133 }
134
135
136
137
138
139 /***
140 * Test this entry for equality to another.
141 * <p/>
142 * <p/>
143 * Consistent with {@link #compareTo}, this method tests
144 * for equality purely on the package name.
145 * </p>
146 *
147 * @param thatObj The object to compare
148 * @return <code>true</code> if the two objects are
149 * semantically equivalent, otherwise <code>false</code>.
150 */
151 public boolean equals( Object thatObj )
152 {
153 Entry that = (Entry) thatObj;
154
155 return getPackageName().equals( that.getPackageName() );
156 }
157
158 /***
159 * <p/>
160 * Consistent with {@link #equals}, this method creates a hashCode
161 * based on the packagename.
162 * </p>
163 */
164 public int hashCode()
165 {
166 return getPackageName().hashCode();
167 }
168 }