This project has retired. For details please refer to its Attic page.
ArtifactReference xref
View Javadoc
1   package org.apache.archiva.model;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  /**
23   * Class ArtifactReference.
24   * 
25   * @version $Revision$ $Date$
26   */
27  @SuppressWarnings( "all" )
28  public class ArtifactReference
29      implements java.io.Serializable
30  {
31  
32        //--------------------------/
33       //- Class/Member Variables -/
34      //--------------------------/
35  
36      /**
37       * 
38       *             The Group ID of the repository content.
39       *           
40       */
41      private String groupId;
42  
43      /**
44       * 
45       *             The Artifact ID of the repository content.
46       *           
47       */
48      private String artifactId;
49  
50      /**
51       * 
52       *             The version of the repository content.
53       *           
54       */
55      private String version;
56  
57      /**
58       * 
59       *             The classifier for this artifact.
60       *           
61       */
62      private String classifier;
63  
64      /**
65       * 
66       *             The type of artifact.
67       *           
68       */
69      private String type;
70  
71  
72        //-----------/
73       //- Methods -/
74      //-----------/
75  
76      /**
77       * Get the Artifact ID of the repository content.
78       * 
79       * @return String
80       */
81      public String getArtifactId()
82      {
83          return this.artifactId;
84      } //-- String getArtifactId()
85  
86      /**
87       * Get the classifier for this artifact.
88       * 
89       * @return String
90       */
91      public String getClassifier()
92      {
93          return this.classifier;
94      } //-- String getClassifier()
95  
96      /**
97       * Get the Group ID of the repository content.
98       * 
99       * @return String
100      */
101     public String getGroupId()
102     {
103         return this.groupId;
104     } //-- String getGroupId()
105 
106     /**
107      * Get the type of artifact.
108      * 
109      * @return String
110      */
111     public String getType()
112     {
113         return this.type;
114     } //-- String getType()
115 
116     /**
117      * Get the version of the repository content.
118      * 
119      * @return String
120      */
121     public String getVersion()
122     {
123         return this.version;
124     } //-- String getVersion()
125 
126     /**
127      * Set the Artifact ID of the repository content.
128      * 
129      * @param artifactId
130      */
131     public void setArtifactId( String artifactId )
132     {
133         this.artifactId = artifactId;
134     } //-- void setArtifactId( String )
135 
136     /**
137      * Set the classifier for this artifact.
138      * 
139      * @param classifier
140      */
141     public void setClassifier( String classifier )
142     {
143         this.classifier = classifier;
144     } //-- void setClassifier( String )
145 
146     /**
147      * Set the Group ID of the repository content.
148      * 
149      * @param groupId
150      */
151     public void setGroupId( String groupId )
152     {
153         this.groupId = groupId;
154     } //-- void setGroupId( String )
155 
156     /**
157      * Set the type of artifact.
158      * 
159      * @param type
160      */
161     public void setType( String type )
162     {
163         this.type = type;
164     } //-- void setType( String )
165 
166     /**
167      * Set the version of the repository content.
168      * 
169      * @param version
170      */
171     public void setVersion( String version )
172     {
173         this.version = version;
174     } //-- void setVersion( String )
175 
176     
177     private static final long serialVersionUID = -6116764846682178732L;
178           
179     
180     private static String defaultString( String value )
181     {
182         if ( value == null )
183         {
184             return "";
185         }
186         
187         return value.trim();
188     }
189           
190     public static String toKey( ArtifactReference artifactReference )
191     {
192         StringBuilder key = new StringBuilder();
193 
194         key.append( defaultString( artifactReference.getGroupId() ) ).append( ":" );
195         key.append( defaultString( artifactReference.getArtifactId() ) ).append( ":" );
196         key.append( defaultString( artifactReference.getVersion() ) ).append( ":" );
197         key.append( defaultString( artifactReference.getClassifier() ) ).append( ":" );
198         key.append( defaultString( artifactReference.getType() ) );
199 
200         return key.toString();
201     }
202 
203     public static String toVersionlessKey( ArtifactReference artifactReference )
204     {
205         StringBuilder key = new StringBuilder();
206 
207         key.append( defaultString( artifactReference.getGroupId() ) ).append( ":" );
208         key.append( defaultString( artifactReference.getArtifactId() ) ).append( ":" );
209         key.append( defaultString( artifactReference.getClassifier() ) ).append( ":" );
210         key.append( defaultString( artifactReference.getType() ) );
211 
212         return key.toString();
213     }
214           
215     
216     public int hashCode()
217     {
218         final int PRIME = 31;
219         int result = 1;
220         result = PRIME * result + ( ( groupId == null ) ? 0 : groupId.hashCode() );
221         result = PRIME * result + ( ( artifactId == null ) ? 0 : artifactId.hashCode() );
222         result = PRIME * result + ( ( version == null ) ? 0 : version.hashCode() );
223         result = PRIME * result + ( ( classifier == null ) ? 0 : classifier.hashCode() );
224         result = PRIME * result + ( ( type == null ) ? 0 : type.hashCode() );
225         return result;
226     }
227 
228     public boolean equals( Object obj )
229     {
230         if ( this == obj )
231         {
232             return true;
233         }
234         
235         if ( obj == null )
236         {
237             return false;
238         }
239         
240         if ( getClass() != obj.getClass() )
241         {
242             return false;
243         }
244 
245         final ArtifactReference./org/apache/archiva/model/ArtifactReference.html#ArtifactReference">ArtifactReference other = (ArtifactReference) obj;
246 
247         if ( groupId == null )
248         {
249             if ( other.groupId != null )
250             {
251                 return false;
252             }
253         }
254         else if ( !groupId.equals( other.groupId ) )
255         {
256             return false;
257         }
258 
259         if ( artifactId == null )
260         {
261             if ( other.artifactId != null )
262             {
263                 return false;
264             }
265         }
266         else if ( !artifactId.equals( other.artifactId ) )
267         {
268             return false;
269         }
270 
271         if ( version == null )
272         {
273             if ( other.version != null )
274             {
275                 return false;
276             }
277         }
278         else if ( !version.equals( other.version ) )
279         {
280             return false;
281         }
282 
283         if ( classifier == null )
284         {
285             if ( other.classifier != null )
286             {
287                 return false;
288             }
289         }
290         else if ( !classifier.equals( other.classifier ) )
291         {
292             return false;
293         }
294         
295         if ( type == null )
296         {
297             if ( other.type != null )
298             {
299                 return false;
300             }
301         }
302         else if ( !type.equals( other.type ) )
303         {
304             return false;
305         }
306         
307         return true;
308     }          
309           
310 }