alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

What this is

This file is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Other links

The source code

/*
 *                 Sun Public License Notice
 * 
 * The contents of this file are subject to the Sun Public License
 * Version 1.0 (the "License"). You may not use this file except in
 * compliance with the License. A copy of the License is available at
 * http://www.sun.com/
 * 
 * The Original Code is NetBeans. The Initial Developer of the Original
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2000 Sun
 * Microsystems, Inc. All Rights Reserved.
 */

package org.openide.src;

/** Represents one class or package import.
*
* @author Petr Hamernik
*/
public class Import extends Object implements java.io.Serializable {
    /** A package import. */
    public static final boolean PACKAGE = true;
    /** A class import. */
    public static final boolean CLASS = false;

    /** Kind of this Import element. It is true if the import means "whole package"
    * otherwise (if it is import just one class) false.
    */
    private boolean wholePackage;

    /** Identifier which is imported */
    private Identifier id;

    static final long serialVersionUID =-4111760314345461897L;

    /** Create an import.
    * @param id the name of the class or package imported
    * @param wholePackage one of {@link #PACKAGE} or {@link #CLASS}
    */
    public Import(Identifier id, boolean wholePackage) {
        this.wholePackage = wholePackage;
        this.id = id;
    }

    /** Is this a package import?
    * @return true if so
    */
    public boolean isPackage() {
        return wholePackage;
    }

    /** Is this a class import?
    * @return true if so
    */
    public boolean isClass() {
        return (!wholePackage);
    }

    /** Get the name of the import.
    * @return the identifier which is imported
    */
    public Identifier getIdentifier() {
        return id;
    }

    /** Get this import as a string.
    * @return e.g. import com.mycom.Class or import com.mycom.*
    */
    public String toString() {
        StringBuffer buf = new StringBuffer("import "); // NOI18N
        buf.append(id.getFullName());
        if (wholePackage)
            buf.append(".*"); // NOI18N
        return buf.toString();
    }

    /** @return the hash code for this import */
    public int hashCode() {
        return id.getFullName().hashCode();
    }

    /** @return true if the specified object is also Import of the same class or package.
    */
    public boolean equals(Object o) {
        if (o instanceof Import) {
            Import imp = (Import) o;
            return (wholePackage == imp.wholePackage) && (id.equals(imp.id));
        }
        return false;
    }
}
... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.