comparison org.eclipse.equinox.common/src/org/eclipse/core/runtime/QualifiedName.d @ 105:bbe49769ec18

...
author Frank Benoit <benoit@tionex.de>
date Sun, 08 Nov 2009 12:42:30 +0100
parents bc29606a740c
children
comparison
equal deleted inserted replaced
104:88652073d1c2 105:bbe49769ec18
2 * Copyright (c) 2000, 2008 IBM Corporation and others. 2 * Copyright (c) 2000, 2008 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials 3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0 4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at 5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html 6 * http://www.eclipse.org/legal/epl-v10.html
7 * 7 *
8 * Contributors: 8 * Contributors:
9 * IBM Corporation - initial API and implementation 9 * IBM Corporation - initial API and implementation
10 * Port to the D programming language:
11 * Frank Benoit <benoit@tionex.de>
12 *******************************************************************************/ 10 *******************************************************************************/
13 module org.eclipse.core.runtime.QualifiedName; 11 // Port to the D programming language:
14 12 // Frank Benoit <benoit@tionex.de>
15 import org.eclipse.core.runtime.Assert; 13 module org.eclipse.core.runtimeQualifiedName;
16 14
17 import java.lang.all; 15 import java.lang.all;
18 16
17 import org.eclipse.core.runtimeAssert; // packageimport
18
19 /** 19 /**
20 * Qualified names are two-part names: qualifier and local name. 20 * Qualified names are two-part names: qualifier and local name.
21 * The qualifier must be in URI form (see RFC2396). 21 * The qualifier must be in URI form (see RFC2396).
22 * Note however that the qualifier may be <code>null</code> if 22 * Note however that the qualifier may be <code>null</code> if
23 * the default name space is being used. The empty string is not 23 * the default name space is being used. The empty string is not
24 * a valid local name. 24 * a valid local name.
25 * <p> 25 * <p>
26 * This class can be used without OSGi running. 26 * This class can be used without OSGi running.
27 * </p><p> 27 * </p><p>
28 * This class is not intended to be subclassed by clients. 28 * This class is not intended to be subclassed by clients.
48 * </p> 48 * </p>
49 * @param qualifier the qualifier string, or <code>null</code> 49 * @param qualifier the qualifier string, or <code>null</code>
50 * @param localName the local name string 50 * @param localName the local name string
51 */ 51 */
52 public this(String qualifier, String localName) { 52 public this(String qualifier, String localName) {
53 Assert.isLegal(localName !is null && localName.length !is 0); 53 Assert.isLegal(localName !is null && localName.length() !is 0);
54 this.qualifier = qualifier; 54 this.qualifier = qualifier;
55 this.localName = localName; 55 this.localName = localName;
56 } 56 }
57 57
58 /** 58 /**
65 * 65 *
66 * @param obj the object to compare to 66 * @param obj the object to compare to
67 * @return <code>true</code> if these are equivalent qualified 67 * @return <code>true</code> if these are equivalent qualified
68 * names, and <code>false</code> otherwise 68 * names, and <code>false</code> otherwise
69 */ 69 */
70 public override int opEquals(Object obj) { 70 public override equals_t opEquals(Object obj) {
71 if (obj is this) { 71 if (obj is this) {
72 return true; 72 return true;
73 } 73 }
74 if (!(cast(QualifiedName)obj )) { 74 if (!( null !is cast(QualifiedName)obj )) {
75 return false; 75 return false;
76 } 76 }
77 QualifiedName qName = cast(QualifiedName) obj; 77 QualifiedName qName = cast(QualifiedName) obj;
78 /* There may or may not be a qualifier */ 78 /* There may or may not be a qualifier */
79 if (qualifier is null && qName.getQualifier() !is null) { 79 if (qualifier is null && qName.getQualifier() !is null) {
80 return false; 80 return false;
81 } 81 }
82 if (qualifier !is null && !qualifier.equals(qName.getQualifier())) { 82 if (qualifier !is null && !qualifier.opEquals(qName.getQualifier())) {
83 return false; 83 return false;
84 } 84 }
85 return localName.equals(qName.getLocalName()); 85 return localName.opEquals(qName.getLocalName());
86 } 86 }
87 87
88 /** 88 /**
89 * Returns the local part of this name. 89 * Returns the local part of this name.
90 * 90 *
104 return qualifier; 104 return qualifier;
105 } 105 }
106 106
107 /* (Intentionally omitted from javadoc) 107 /* (Intentionally omitted from javadoc)
108 * Implements the method <code>Object.hashCode</code>. 108 * Implements the method <code>Object.hashCode</code>.
109 * 109 *
110 * Returns the hash code for this qualified name. 110 * Returns the hash code for this qualified name.
111 */ 111 */
112 public override hash_t toHash() { 112 public override hash_t toHash() {
113 return (qualifier is null ? 0 : .toHash(qualifier)) + .toHash(localName); 113 return (qualifier is null ? 0 : qualifier.toHash()) + localName.toHash();
114 } 114 }
115 115
116 /** 116 /**
117 * Converts this qualified name into a string, suitable for 117 * Converts this qualified name into a string, suitable for
118 * debug purposes only. 118 * debug purposes only.
119 */ 119 */
120 public override String toString() { 120 public String toString() {
121 return (getQualifier() is null ? "" : getQualifier() ~ ':') ~ getLocalName(); //$NON-NLS-1$ 121 return (getQualifier() is null ? "" : getQualifier() + ':') + getLocalName(); //$NON-NLS-1$
122 } 122 }
123 } 123 }