KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > core > runtime > QualifiedName


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.core.runtime;
12
13 /**
14  * Qualified names are two-part names: qualifier and local name.
15  * The qualifier must be in URI form (see RFC2396).
16  * Note however that the qualifier may be <code>null</code> if
17  * the default name space is being used. The empty string is not
18  * a valid local name.
19  * <p>
20  * This class can be used without OSGi running.
21  * </p><p>
22  * This class is not intended to be subclassed by clients.
23  * </p>
24  */

25 public final class QualifiedName {
26
27     /** Qualifier part (potentially <code>null</code>). */
28     /*package*/
29     String JavaDoc qualifier = null;
30
31     /** Local name part. */
32     /*package*/
33     String JavaDoc localName = null;
34
35     /**
36      * Creates and returns a new qualified name with the given qualifier
37      * and local name. The local name must not be the empty string.
38      * The qualifier may be <code>null</code>.
39      * <p>
40      * Clients may instantiate.
41      * </p>
42      * @param qualifier the qualifier string, or <code>null</code>
43      * @param localName the local name string
44      */

45     public QualifiedName(String JavaDoc qualifier, String JavaDoc localName) {
46         Assert.isLegal(localName != null && localName.length() != 0);
47         this.qualifier = qualifier;
48         this.localName = localName;
49     }
50
51     /**
52      * Returns whether this qualified name is equivalent to the given object.
53      * <p>
54      * Qualified names are equal if and only if they have the same
55      * qualified parts and local parts.
56      * Qualified names are not equal to objects other than qualified names.
57      * </p>
58      *
59      * @param obj the object to compare to
60      * @return <code>true</code> if these are equivalent qualified
61      * names, and <code>false</code> otherwise
62      */

63     public boolean equals(Object JavaDoc obj) {
64         if (obj == this) {
65             return true;
66         }
67         if (!(obj instanceof QualifiedName)) {
68             return false;
69         }
70         QualifiedName qName = (QualifiedName) obj;
71         /* There may or may not be a qualifier */
72         if (qualifier == null && qName.getQualifier() != null) {
73             return false;
74         }
75         if (qualifier != null && !qualifier.equals(qName.getQualifier())) {
76             return false;
77         }
78         return localName.equals(qName.getLocalName());
79     }
80
81     /**
82      * Returns the local part of this name.
83      *
84      * @return the local name string
85      */

86     public String JavaDoc getLocalName() {
87         return localName;
88     }
89
90     /**
91      * Returns the qualifier part for this qualified name, or <code>null</code>
92      * if none.
93      *
94      * @return the qualifier string, or <code>null</code>
95      */

96     public String JavaDoc getQualifier() {
97         return qualifier;
98     }
99
100     /* (Intentionally omitted from javadoc)
101      * Implements the method <code>Object.hashCode</code>.
102      *
103      * Returns the hash code for this qualified name.
104      */

105     public int hashCode() {
106         return (qualifier == null ? 0 : qualifier.hashCode()) + localName.hashCode();
107     }
108
109     /**
110      * Converts this qualified name into a string, suitable for
111      * debug purposes only.
112      */

113     public String JavaDoc toString() {
114         return (getQualifier() == null ? "" : getQualifier() + ':') + getLocalName(); //$NON-NLS-1$
115
}
116 }
117
Popular Tags