KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openide > src > Import


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.openide.src;
21
22 /** Represents one class or package import.
23 *
24 * @author Petr Hamernik
25 */

26 public class Import extends Object JavaDoc implements java.io.Serializable JavaDoc {
27     /** A package import. */
28     public static final boolean PACKAGE = true;
29     /** A class import. */
30     public static final boolean CLASS = false;
31
32     /** Kind of this Import element. It is true if the import means "whole package"
33     * otherwise (if it is import just one class) false.
34     */

35     private boolean wholePackage;
36
37     /** Identifier which is imported */
38     private Identifier id;
39
40     static final long serialVersionUID =-4111760314345461897L;
41
42     /** Create an import.
43     * @param id the name of the class or package imported
44     * @param wholePackage one of {@link #PACKAGE} or {@link #CLASS}
45     */

46     public Import(Identifier id, boolean wholePackage) {
47         this.wholePackage = wholePackage;
48         this.id = id;
49     }
50
51     /** Is this a package import?
52     * @return <code>true</code> if so
53     */

54     public boolean isPackage() {
55         return wholePackage;
56     }
57
58     /** Is this a class import?
59     * @return <code>true</code> if so
60     */

61     public boolean isClass() {
62         return (!wholePackage);
63     }
64
65     /** Get the name of the import.
66     * @return the identifier which is imported
67     */

68     public Identifier getIdentifier() {
69         return id;
70     }
71
72     /** Get this import as a string.
73     * @return e.g. <code>import com.mycom.Class</code> or <code>import com.mycom.*</code>
74     */

75     public String JavaDoc toString() {
76         StringBuffer JavaDoc buf = new StringBuffer JavaDoc("import "); // NOI18N
77
buf.append(id.getFullName());
78         if (wholePackage)
79             buf.append(".*"); // NOI18N
80
return buf.toString();
81     }
82
83     /** @return the hash code for this import */
84     public int hashCode() {
85         return id.getFullName().hashCode();
86     }
87
88     /** @return true if the specified object is also Import of the same class or package.
89     */

90     public boolean equals(Object JavaDoc o) {
91         if (o instanceof Import) {
92             Import imp = (Import) o;
93             return (wholePackage == imp.wholePackage) && (id.equals(imp.id));
94         }
95         return false;
96     }
97 }
98
Popular Tags