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

Quick Search    Search Deep

Source code: javax/ide/extension/ExtensionDependency.java


1   package javax.ide.extension;
2   
3   import javax.ide.util.Version;
4   
5   /**
6    * Represents an extension's dependency on some other extension.
7    */
8   public final class ExtensionDependency 
9   {
10    private final String _id;
11    private final Version _minVersion;
12    private final Version _maxVersion;
13  
14    /**
15     * Constructs a dependency for any version of the specified extension id.
16     * 
17     * @param id an extension id. Must not be null.
18     */
19    public ExtensionDependency( String id )
20    {
21      this( id, null, null );
22    }
23    
24    /**
25     * Constructs a dependency between two versions of the specified extension id.
26     * 
27     * @param id an extension id. Must not be null.
28     * @param min the minimum required version of the specified extension. May
29     *    be null, which indicates that there is no minimum version.
30     * @param max the maximum required version of the specified extension. May
31     *    be null, which indicates that there is no maximum version.
32     */
33    public ExtensionDependency( String id, Version min, Version max )
34    {
35      if ( id == null )
36      {
37        throw new NullPointerException( "id is null" );
38      }
39      _id = id;
40      _minVersion = min;
41      _maxVersion = max;
42    }
43    
44    /**
45     * Get the id of the extension this dependency is for.
46     * 
47     * @return the id of an extension. Will not return null.
48     */
49    public String getID()
50    {
51      return _id;
52    }
53    
54    /**
55     * Get the minimum version of the extension this dependency is for.
56     * 
57     * @return the minimum version. May be null if there is no minimum required
58     *    version.
59     */
60    public Version getMinimumVersion()
61    {
62      return _minVersion;
63    }
64    
65    /**
66     * Get the maximum version of the extension this dependency is for.
67     * 
68     * @return the maximum version. May be null if there is no maximum required
69     *    version.
70     */
71    public Version getMaximumVersion()
72    {
73      return _maxVersion;
74    }
75    
76    /**
77     * Get a string representation of this dependency.
78     * 
79     * @return a string representation of this dependency.
80     */
81    public String toString()
82    {
83      return "ExtensionDependency[ id="+_id+
84        ", _minVersion="+String.valueOf( _minVersion )+
85        ", _maxVersion="+String.valueOf( _maxVersion )+
86        " ]";
87    }
88    
89    public int hashCode()
90    {
91      int result = 42;
92      result = 37 * result + _id.hashCode();
93      if ( _minVersion != null )
94      {
95        result = 37 * result + _minVersion.hashCode();
96      }
97      if ( _maxVersion != null )
98      {
99        result = 37 * result + _maxVersion.hashCode();
100     }
101     
102     return result;
103   }
104   
105   public boolean equals( Object o )
106   {
107     if ( o == this )
108     {
109       return true;
110     }
111     if ( !(o instanceof ExtensionDependency ) )
112     {
113       return false;
114     }
115     ExtensionDependency that = (ExtensionDependency) o;
116     
117     if ( !that.getID().equals( this.getID() ) )
118     {
119       return false;
120     }
121     
122     if ( that.getMinimumVersion() != this.getMinimumVersion() )
123     {
124       if ( that.getMinimumVersion() != null && 
125            !that.getMinimumVersion().equals( this.getMinimumVersion() ) )
126       {
127         return false;
128       }
129     }
130     
131     if ( that.getMaximumVersion() != this.getMaximumVersion() )
132     {
133       if ( that.getMaximumVersion() != null &&
134            !that.getMaximumVersion().equals( this.getMaximumVersion() ) )
135       {
136         return false;
137       }
138     }
139     
140     return true;
141   }
142 }