KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > update > core > VersionedIdentifier


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.update.core;
12
13 import org.eclipse.core.runtime.*;
14 import org.eclipse.osgi.util.NLS;
15 import org.eclipse.update.internal.core.*;
16
17 /**
18  * Versioned Identifier. This is a utility class combining an identification
19  * string with a version.
20  * <p>
21  * Clients may instantiate; not intended to be subclassed by clients.
22  * </p>
23  * <p>
24  * <b>Note:</b> This class/interface is part of an interim API that is still under development and expected to
25  * change significantly before reaching stability. It is being made available at this early stage to solicit feedback
26  * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken
27  * (repeatedly) as the API evolves.
28  * </p>
29  * @see org.eclipse.core.runtime.PluginVersionIdentifier
30  * @since 2.0
31  */

32 public class VersionedIdentifier {
33     private String JavaDoc id;
34     private PluginVersionIdentifier version;
35     private static final String JavaDoc SEPARATOR = "_"; //$NON-NLS-1$
36

37     /**
38      * Construct a versioned identifier from an identifier and a string
39      * representation of a version
40      *
41      * @see org.eclipse.core.runtime.PluginVersionIdentifier#toString()
42      * @param id identifier string
43      * @param versionName string representation of version
44      * @since 2.0
45      */

46     public VersionedIdentifier(String JavaDoc id, String JavaDoc versionName) {
47         if (id == null || (id = id.trim()).equals("")) //$NON-NLS-1$
48
throw new IllegalArgumentException JavaDoc(
49                 NLS.bind(Messages.VersionedIdentifier_IdOrVersionNull, (new String JavaDoc[] { id, versionName })));
50         this.id = id;
51         // 15707
52
if (versionName != null){
53             // if (PluginVersionIdentifier.validateVersionIdentifier(versionName).isOk())
54
try {
55                 this.version = new PluginVersionIdentifier(versionName);
56             } catch (RuntimeException JavaDoc e){
57                 UpdateCore.warn("Invalid Version:"+versionName,e); //$NON-NLS-1$
58
}
59         }
60         if (this.version==null)
61             version = new PluginVersionIdentifier(0, 0, 0);
62     }
63
64     /**
65      * Returns the identifier
66      *
67      * @return identifier
68      * @since 2.0
69      */

70     public String JavaDoc getIdentifier() {
71         return id;
72     }
73
74     /**
75      * Returns the version
76      *
77      * @return version
78      * @since 2.0
79      */

80     public PluginVersionIdentifier getVersion() {
81         return version;
82     }
83
84     /**
85      * Returns a string representation of the versioned identifier.
86      *
87      * @return string representation of versioned identifier. The resulting
88      * string is <id>_<version>, where <id> is the identifier and
89      * <version> is the string representation of the version
90      * @since 2.0
91      */

92     public String JavaDoc toString() {
93         return id.equals("") ? "" : id + SEPARATOR + version.toString(); //$NON-NLS-1$ //$NON-NLS-2$
94
}
95
96     /**
97      * Compares two versioned identifiers for equality
98      *
99      * @param obj other versioned identifier to compare to
100      * @return <code>true</code> if the two objects are equal,
101      * <code>false</code> otherwise
102      * @since 2.0
103      */

104     public boolean equals(Object JavaDoc obj) {
105         if (!(obj instanceof VersionedIdentifier))
106             return false;
107         VersionedIdentifier vid = (VersionedIdentifier) obj;
108         if (!this.id.equals(vid.id))
109             return false;
110         return this.version.equals(vid.version);
111     }
112
113     /**
114      * Returns a computed hashcode for the versioned identifier.
115      *
116      * @return hash code
117      * @since 2.0
118      */

119     public int hashCode() {
120         return toString().hashCode();
121     }
122
123 }
124
Popular Tags