001package org.apache.archiva.model; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022/** 023 * Class ArtifactReference. 024 * 025 * @version $Revision$ $Date$ 026 */ 027@SuppressWarnings( "all" ) 028public class ArtifactReference 029 implements java.io.Serializable 030{ 031 032 //--------------------------/ 033 //- Class/Member Variables -/ 034 //--------------------------/ 035 036 /** 037 * 038 * The Group ID of the repository content. 039 * 040 */ 041 private String groupId; 042 043 /** 044 * 045 * The Artifact ID of the repository content. 046 * 047 */ 048 private String artifactId; 049 050 /** 051 * 052 * The version of the repository content. 053 * 054 */ 055 private String version; 056 057 /** 058 * 059 * The classifier for this artifact. 060 * 061 */ 062 private String classifier; 063 064 /** 065 * 066 * The type of artifact. 067 * 068 */ 069 private String type; 070 071 072 //-----------/ 073 //- Methods -/ 074 //-----------/ 075 076 /** 077 * Get the Artifact ID of the repository content. 078 * 079 * @return String 080 */ 081 public String getArtifactId() 082 { 083 return this.artifactId; 084 } //-- String getArtifactId() 085 086 /** 087 * Get the classifier for this artifact. 088 * 089 * @return String 090 */ 091 public String getClassifier() 092 { 093 return this.classifier; 094 } //-- String getClassifier() 095 096 /** 097 * Get the Group ID of the repository content. 098 * 099 * @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 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}