KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > api > java > platform > Specification


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.api.java.platform;
21
22 import org.openide.modules.SpecificationVersion;
23
24 /** Specification of the Java SDK
25  */

26 public final class Specification {
27
28     private String JavaDoc name;
29     private SpecificationVersion version;
30     private Profile[] profiles;
31
32
33     /**
34      * Creates new SDK Specification
35      * @param name of the specification e.g J2SE
36      * @param version of the specification e.g. 1.4
37      */

38     public Specification (String JavaDoc name, SpecificationVersion version) {
39         this (name, version, null);
40     }
41
42     /**
43      * Creates new SDK Specification
44      * @param name of the specification e.g J2SE
45      * @param version of the specification e.g. 1.4
46      * @param profiles of the Java SDK
47      */

48     public Specification (String JavaDoc name, SpecificationVersion version, Profile[] profiles) {
49         this.name = name;
50         this.version = version;
51         this.profiles = profiles;
52     }
53
54     /**
55      * Returns the name of the Java specification e.g. J2SE
56      * @return String
57      */

58     public final String JavaDoc getName () {
59         return this.name;
60     }
61
62     /**
63      * Returns the version of the Java specification e.g 1.4
64      * @return instance of SpecificationVersion
65      */

66     public final SpecificationVersion getVersion () {
67         return this.version;
68     }
69
70     /**
71      * Returns profiles supported by the Java platform.
72      * @return list of profiles, or null if not applicable
73      */

74     public final Profile[] getProfiles () {
75         return this.profiles;
76     }
77
78     public int hashCode () {
79         int hc = 0;
80         if (this.name != null)
81             hc = this.name.hashCode() << 16;
82         if (this.version != null)
83             hc += this.version.hashCode();
84         return hc;
85     }
86
87     public boolean equals (Object JavaDoc other) {
88         if (other instanceof Specification) {
89             Specification os = (Specification) other;
90             boolean re = this.name == null ? os.name == null : this.name.equals(os.name) &&
91                          this.version == null ? os.version == null : this.version.equals (os.version);
92             if (!re || this.profiles == null)
93                 return re;
94             if (os.profiles == null || this.profiles.length != os.profiles.length)
95                 return false;
96             for (int i=0; i<os.profiles.length; i++)
97                 re &= this.profiles[i].equals(os.profiles[i]);
98             return re;
99         }
100         else
101             return false;
102     }
103
104     public String JavaDoc toString () {
105         String JavaDoc str = this.name == null ? "" : this.name + " "; // NOI18N
106
str += this.version == null ? "" : this.version + " "; // NOI18N
107
if (this.profiles != null) {
108             str+="["; // NOI18N
109
for (int i = 0; i < profiles.length; i++) {
110                 str+= profiles[i]+ " "; // NOI18N
111
}
112             str+="]"; // NOI18N
113
}
114         return str;
115     }
116
117 }
118
Popular Tags