Skip to main content
summaryrefslogtreecommitdiffstats
blob: 56f130a7f3ac8dd17424b97225d587a0a9cecd29 (plain) (blame)
1
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*******************************************************************************
 * Copyright (c) 2000, 2006 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.core.runtime;

/**
 * Qualified names are two-part names: qualifier and local name.
 * The qualifier must be in URI form (see RFC2396).  
 * Note however that the qualifier may be <code>null</code> if
 * the default name space is being used.  The empty string is not 
 * a valid local name.
 * <p>
 * This class can be used without the OSGi bundle present.
 * </p><p>
 * This class is not intended to be subclassed by clients.
 * </p>
 */
public final class QualifiedName {

	/** Qualifier part (potentially <code>null</code>). */
	/*package*/
	String qualifier = null;

	/** Local name part. */
	/*package*/
	String localName = null;

	/**
	 * Creates and returns a new qualified name with the given qualifier
	 * and local name.  The local name must not be the empty string.
	 * The qualifier may be <code>null</code>.
	 * <p>
	 * Clients may instantiate.
	 * </p>
	 * @param qualifier the qualifier string, or <code>null</code>
	 * @param localName the local name string
	 */
	public QualifiedName(String qualifier, String localName) {
		Assert.isLegal(localName != null && localName.length() != 0);
		this.qualifier = qualifier;
		this.localName = localName;
	}

	/**
	 * Returns whether this qualified name is equivalent to the given object.
	 * <p>
	 * Qualified names are equal if and only if they have the same
	 * qualified parts and local parts.
	 * Qualified names are not equal to objects other than qualified names.
	 * </p>
	 *
	 * @param obj the object to compare to
	 * @return <code>true</code> if these are equivalent qualified
	 *    names, and <code>false</code> otherwise
	 */
	public boolean equals(Object obj) {
		if (obj == this) {
			return true;
		}
		if (!(obj instanceof QualifiedName)) {
			return false;
		}
		QualifiedName qName = (QualifiedName) obj;
		/* There may or may not be a qualifier */
		if (qualifier == null && qName.getQualifier() != null) {
			return false;
		}
		if (qualifier != null && !qualifier.equals(qName.getQualifier())) {
			return false;
		}
		return localName.equals(qName.getLocalName());
	}

	/**
	 * Returns the local part of this name.
	 *
	 * @return the local name string
	 */
	public String getLocalName() {
		return localName;
	}

	/**
	 * Returns the qualifier part for this qualified name, or <code>null</code>
	 * if none.
	 *
	 * @return the qualifier string, or <code>null</code>
	 */
	public String getQualifier() {
		return qualifier;
	}

	/* (Intentionally omitted from javadoc)
	 * Implements the method <code>Object.hashCode</code>.
	 * 
	 * Returns the hash code for this qualified name.
	 */
	public int hashCode() {
		return (qualifier == null ? 0 : qualifier.hashCode()) + localName.hashCode();
	}

	/**
	 * Converts this qualified name into a string, suitable for 
	 * debug purposes only.
	 */
	public String toString() {
		return (getQualifier() == null ? "" : getQualifier() + ':') + getLocalName(); //$NON-NLS-1$
	}
}

Back to the top