KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > update > internal > configurator > VersionedIdentifier


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 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.update.internal.configurator;
12
13 import org.osgi.framework.Version;
14
15 public class VersionedIdentifier {
16     private String JavaDoc identifier;
17     private Version version;
18
19     public VersionedIdentifier(String JavaDoc id, String JavaDoc version) {
20         this.identifier = id;
21         this.version = Version.parseVersion(version);
22     }
23
24     public Version getVersion() {
25         return version;
26     }
27
28     public String JavaDoc getIdentifier() {
29         return identifier;
30     }
31
32     private boolean equalIdentifiers(VersionedIdentifier id) {
33         if (id == null)
34             return identifier == null;
35         return id.identifier.equals(identifier);
36     }
37
38     /* (non-Javadoc)
39      * @see java.lang.Object#equals(java.lang.Object)
40      */

41     public boolean equals(Object JavaDoc obj) {
42         if (this == obj)
43             return true;
44         if (!(obj instanceof VersionedIdentifier))
45             return false;
46
47         VersionedIdentifier other = (VersionedIdentifier) obj;
48         if (!equalIdentifiers(other))
49             return false;
50         return version.equals(other.getVersion());
51     }
52
53     /* (non-Javadoc)
54      * @see java.lang.Object#hashCode()
55      */

56     public int hashCode() {
57         return (identifier + "_" + getVersion()).hashCode(); //$NON-NLS-1$
58
}
59
60     /* (non-Javadoc)
61      * @see java.lang.Object#toString()
62      */

63     public String JavaDoc toString() {
64         return identifier + "_" + getVersion(); //$NON-NLS-1$
65
}
66 }
Popular Tags