001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.gsfpath.api.platform;
043:
044: import org.openide.modules.SpecificationVersion;
045:
046: /** Specification of the Java SDK
047: */
048: public final class Specification {
049:
050: private String name;
051: private SpecificationVersion version;
052: private Profile[] profiles;
053:
054: /**
055: * Creates new SDK Specification
056: * @param name of the specification e.g J2SE
057: * @param version of the specification e.g. 1.4
058: */
059: public Specification(String name, SpecificationVersion version) {
060: this (name, version, null);
061: }
062:
063: /**
064: * Creates new SDK Specification
065: * @param name of the specification e.g J2SE
066: * @param version of the specification e.g. 1.4
067: * @param profiles of the Java SDK
068: */
069: public Specification(String name, SpecificationVersion version,
070: Profile[] profiles) {
071: this .name = name;
072: this .version = version;
073: this .profiles = profiles;
074: }
075:
076: /**
077: * Returns the name of the Java specification e.g. J2SE
078: * @return String
079: */
080: public final String getName() {
081: return this .name;
082: }
083:
084: /**
085: * Returns the version of the Java specification e.g 1.4
086: * @return instance of SpecificationVersion
087: */
088: public final SpecificationVersion getVersion() {
089: return this .version;
090: }
091:
092: /**
093: * Returns profiles supported by the Java platform.
094: * @return list of profiles, or null if not applicable
095: */
096: public final Profile[] getProfiles() {
097: return this .profiles;
098: }
099:
100: public int hashCode() {
101: int hc = 0;
102: if (this .name != null)
103: hc = this .name.hashCode() << 16;
104: if (this .version != null)
105: hc += this .version.hashCode();
106: return hc;
107: }
108:
109: public boolean equals(Object other) {
110: if (other instanceof Specification) {
111: Specification os = (Specification) other;
112: boolean re = this .name == null ? os.name == null
113: : this .name.equals(os.name) && this .version == null ? os.version == null
114: : this .version.equals(os.version);
115: if (!re || this .profiles == null)
116: return re;
117: if (os.profiles == null
118: || this .profiles.length != os.profiles.length)
119: return false;
120: for (int i = 0; i < os.profiles.length; i++)
121: re &= this .profiles[i].equals(os.profiles[i]);
122: return re;
123: } else
124: return false;
125: }
126:
127: public String toString() {
128: String str = this .name == null ? "" : this .name + " "; // NOI18N
129: str += this .version == null ? "" : this .version + " "; // NOI18N
130: if (this .profiles != null) {
131: str += "["; // NOI18N
132: for (int i = 0; i < profiles.length; i++) {
133: str += profiles[i] + " "; // NOI18N
134: }
135: str += "]"; // NOI18N
136: }
137: return str;
138: }
139:
140: }
|