Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: javax/ide/util/ID.java


1   package javax.ide.util;
2   
3   
4   /**
5    * Class used to identify objects. A <code>ID</code> is made up of the
6    * object type and a object name. In general, the object type is a generic
7    * type identifying similar objects and the object name is the specific
8    * name of the object. By convention, the object type identifier is a
9    * dash or dot separated string whose uniqueness comes from following
10   * the package naming scheme of an extension.<p>
11   *
12   * In general, an IDE has a set of objects that extensions need to get a
13   * hold of. Such objects, which include actions and views for example, 
14   * implment the {@link javax.ide.Identifiable} interface and have an
15   * <code>ID</code> that uniquely identifies them.
16   */
17  public final class ID 
18  {
19    private String _type;
20    private String _name;
21  
22    /**
23     * Constructor.
24     *
25     * @param type the object type. In general, the object type is a generic
26     * type identifying a class of objects. The type may be null.<p>
27     *
28     * By convention, the object type identifier is a dash or dot separated 
29     * string whose uniqueness comes from following the package naming scheme 
30     * of an extension.
31     *
32     * @param name the object name. In general, the object name is specific
33     * to the object instance. The name cannot be null.
34     */
35    public ID( String type, String name )
36    {
37      if ( type == null )
38      {
39        type = "";
40      }
41  
42      _type = type;
43  
44      _name = name;
45    }
46  
47    /**
48     * Construct an <code>ID</code> with the specified name. The id type is
49     * undefined.
50     */
51    public ID( String name )
52    {
53      this( null, name );
54    }
55  
56    /**
57     * Get the object type identifier. The type may <code>null</code>.<p>
58     *
59     * By convention, the object type identifier is a dash or dot separated 
60     * string whose uniqueness comes from following the package naming scheme 
61     * of an extension.
62     * @return the type part of the object id.
63     */
64    public String getType()
65    {
66      return _type;
67    }
68  
69    /**
70     * Get the object name. In general, the object name is what identifies
71     * instances with the same type identifier. The name cannot be 
72     * <code>null</code>.
73     * @return the name part of the object id. 
74     */
75    public String getName()
76    {
77      return _name;
78    }
79  
80    //--------------------------------------------------------------------------
81    // Object overrides...
82    //--------------------------------------------------------------------------
83  
84    public String toString()
85    {
86      final String type = getType();
87  
88      return type.length() != 0 
89             ? type + "-:-" + getName()
90             : getName();
91    }
92  
93    public boolean equals( Object object ) 
94    {
95      if ( object == this )
96      {
97        return true;
98      }
99  
100     if ( ! (object instanceof ID ) )
101     {
102       return false;
103     }
104     final ID id = (ID) object;
105 
106     return _type.equals( id._type ) && _name.equals( id._name );
107   }
108 
109   public int hashCode()
110   {
111     return toString().hashCode();
112   }
113 }