View Javadoc
1 package org.codehaus.classworlds; 2 3 /* 4 $Id: Entry.java,v 1.3 2003/09/23 14:09:46 jvanzyl Exp $ 5 6 Copyright 2002 (C) The Werken Company. All Rights Reserved. 7 8 Redistribution and use of this software and associated documentation 9 ("Software"), with or without modification, are permitted provided 10 that the following conditions are met: 11 12 1. Redistributions of source code must retain copyright 13 statements and notices. Redistributions must also contain a 14 copy of this document. 15 16 2. Redistributions in binary form must reproduce the 17 above copyright notice, this list of conditions and the 18 following disclaimer in the documentation and/or other 19 materials provided with the distribution. 20 21 3. The name "classworlds" must not be used to endorse or promote 22 products derived from this Software without prior written 23 permission of The Werken Company. For written permission, 24 please contact bob@werken.com. 25 26 4. Products derived from this Software may not be called "classworlds" 27 nor may "classworlds" appear in their names without prior written 28 permission of The Werken Company. "classworlds" is a registered 29 trademark of The Werken Company. 30 31 5. Due credit should be given to The Werken Company. 32 (http://classworlds.werken.com/). 33 34 THIS SOFTWARE IS PROVIDED BY THE WERKEN COMPANY AND CONTRIBUTORS 35 ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT 36 NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 37 FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 38 THE WERKEN COMPANY OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 39 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 40 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 41 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 42 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 43 STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 44 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 45 OF THE POSSIBILITY OF SUCH DAMAGE. 46 47 */ 48 49 /*** Import description entry. 50 * 51 * @author <a href="mailto:bob@eng.werken.com">bob mcwhirter</a> 52 */ 53 class Entry implements Comparable 54 { 55 // ------------------------------------------------------------ 56 // Instance members 57 // ------------------------------------------------------------ 58 59 /*** The realm. */ 60 private final DefaultClassRealm realm; 61 62 </*** The package name/ *//package-summary/html">color="#AA0000">* The package name/ *//package-summary.html">font color="#AA0000">/*** The package name/ *//package-summary.html">color="#AA0000">* The package name. */ 63 private final String pkgName; 64 65 // ------------------------------------------------------------ 66 // Constructors 67 // ------------------------------------------------------------ 68 69 /*** Construct. 70 * 71 * @param realm The realm. 72 * @param pkgName The package name. 73 */ 74 Entry(DefaultClassRealm realm, 75 String pkgName) 76 { 77 this.realm = realm; 78 this.pkgName = pkgName; 79 } 80 81 // ------------------------------------------------------------ 82 // Instance methods 83 // ------------------------------------------------------------ 84 85 /*** Retrieve the realm. 86 * 87 * @return The realm. 88 */ 89 DefaultClassRealm getRealm() 90 { 91 return this.realm; 92 } 93 94 /*** Retrieve the page name. 95 * 96 * @return The package name. 97 */ 98 String getPackageName() 99 { 100 return this.pkgName; 101 } 102 103 /*** Determine if the classname matches the package 104 * described by this entry. 105 * 106 * @param classname The class name to test. 107 * 108 * @return <code>true</code> if this entry matches the 109 * classname, otherwise <code>false</code>. 110 */ 111 boolean matches(String classname) 112 { 113 return classname.startsWith( getPackageName() ); 114 } 115 116 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 117 // java.lang.Comparable 118 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 119 120 /*** Compare this entry to another for relative ordering. 121 * 122 * <p> 123 * The natural ordering of Entry objects is reverse-alphabetical 124 * based upon package name. 125 * </p> 126 * 127 * @param thatObj The object to compare. 128 * 129 * @return -1 if this object sorts before that object, 0 130 * if they are equal, or 1 if this object sorts 131 * after that object. 132 */ 133 public int compareTo(Object thatObj) 134 { 135 Entry that = (Entry) thatObj; 136 137 // We are reverse sorting this list, so that 138 // we get longer matches first: 139 // 140 // com.werken.foo.bar 141 // com.werken.foo 142 // com.werken 143 144 return ( getPackageName().compareTo( that.getPackageName() ) ) * -1; 145 } 146 147 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 148 // java.lang.Object 149 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 150 151 /*** Test this entry for equality to another. 152 * 153 * <p> 154 * Consistent with {@link #compareTo}, this method tests 155 * for equality purely on the package name. 156 * </p> 157 * 158 * @param thatObj The object to compare 159 * 160 * @return <code>true</code> if the two objects are 161 * semantically equivalent, otherwise <code>false</code>. 162 */ 163 public boolean equals(Object thatObj) 164 { 165 Entry that = (Entry) thatObj; 166 167 return getPackageName().equals( that.getPackageName() ); 168 } 169 170 /*** 171 * <p> 172 * Consistent with {@link #equals}, this method creates a hashCode 173 * based on the packagename. 174 * </p> 175 */ 176 public int hashCode() 177 { 178 return getPackageName().hashCode(); 179 } 180 }

This page was automatically generated by Maven