Coverage Report - de.smartics.properties.resource.domain.ArtifactId
 
Classes in this File Line Coverage Branch Coverage Complexity
ArtifactId
0%
0/57
0%
0/26
1.778
ArtifactId$1
N/A
N/A
N/A
N/A
1.778
ArtifactId$Builder
0%
0/18
N/A
N/A
1.778
 
 1  
 /*
 2  
  * Copyright 2012-2013 smartics, Kronseder & Reiner GmbH
 3  
  *
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  *     http://www.apache.org/licenses/LICENSE-2.0
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 package de.smartics.properties.resource.domain;
 17  
 
 18  
 import java.io.Serializable;
 19  
 
 20  
 import javax.annotation.concurrent.ThreadSafe;
 21  
 
 22  
 import org.apache.commons.lang.ObjectUtils;
 23  
 
 24  
 import de.smartics.util.lang.Arg;
 25  
 
 26  
 /**
 27  
  * Identifies an artifact of resources.
 28  
  */
 29  0
 @ThreadSafe
 30  0
 public final class ArtifactId implements Serializable, Comparable<ArtifactId>
 31  
 { // NOPMD
 32  
   // ********************************* Fields *********************************
 33  
 
 34  
   // --- constants ------------------------------------------------------------
 35  
 
 36  
   /**
 37  
    * The class version identifier.
 38  
    */
 39  
   private static final long serialVersionUID = 1L;
 40  
 
 41  
   // --- members --------------------------------------------------------------
 42  
 
 43  
   /**
 44  
    * The group the artifact belongs to.
 45  
    *
 46  
    * @serial
 47  
    */
 48  
   private final String groupId;
 49  
 
 50  
   /**
 51  
    * The name of the artifact.
 52  
    *
 53  
    * @serial
 54  
    */
 55  
   private final String name;
 56  
 
 57  
   /**
 58  
    * The version of the artifact.
 59  
    *
 60  
    * @serial
 61  
    */
 62  
   private final String version;
 63  
 
 64  
   /**
 65  
    * The artifact type that is expressed by the artifact's file name extension.
 66  
    *
 67  
    * @serial
 68  
    */
 69  
   private final String archiveType;
 70  
 
 71  
   /**
 72  
    * The classifier to the artifact. May be <code>null</code>.
 73  
    *
 74  
    * @serial
 75  
    */
 76  
   private final String classifier;
 77  
 
 78  
   // ****************************** Initializer *******************************
 79  
 
 80  
   // ****************************** Constructors ******************************
 81  
 
 82  
   private ArtifactId(final Builder builder)
 83  0
   {
 84  0
     this.groupId = builder.groupId;
 85  0
     this.name = builder.name;
 86  0
     this.version = builder.version;
 87  0
     this.archiveType = builder.archiveType;
 88  0
     this.classifier = builder.classifier;
 89  0
   }
 90  
 
 91  
   // ****************************** Inner Classes *****************************
 92  
 
 93  
   /**
 94  
    * Builder to create instances of {@link ArtifactId}.
 95  
    */
 96  0
   public static final class Builder
 97  
   {
 98  
     // ******************************** Fields ********************************
 99  
 
 100  
     // --- constants ----------------------------------------------------------
 101  
 
 102  
     // --- members ------------------------------------------------------------
 103  
 
 104  
     /**
 105  
      * The group the artifact belongs to.
 106  
      */
 107  
     private String groupId;
 108  
 
 109  
     /**
 110  
      * The name of the artifact.
 111  
      */
 112  
     private String name;
 113  
 
 114  
     /**
 115  
      * The version of the artifact.
 116  
      */
 117  
     private String version;
 118  
 
 119  
     /**
 120  
      * The artifact type that is expressed by the artifact's file name
 121  
      * extension.
 122  
      */
 123  
     private String archiveType;
 124  
 
 125  
     /**
 126  
      * The classifier to the artifact. May be <code>null</code>.
 127  
      */
 128  
     private String classifier;
 129  
 
 130  
     // ***************************** Initializer ******************************
 131  
 
 132  
     // ***************************** Constructors *****************************
 133  
 
 134  
     // ***************************** Inner Classes ****************************
 135  
 
 136  
     // ******************************** Methods *******************************
 137  
 
 138  
     // --- init ---------------------------------------------------------------
 139  
 
 140  
     // --- get&set ------------------------------------------------------------
 141  
 
 142  
     /**
 143  
      * Sets the group the artifact belongs to.
 144  
      *
 145  
      * @param groupId the group the artifact belongs to.
 146  
      * @return a reference to this builder instance.
 147  
      * @throws IllegalArgumentException if {@code groupId} is blank.
 148  
      */
 149  
     public Builder withGroupId(final String groupId)
 150  
       throws IllegalArgumentException
 151  
     {
 152  0
       this.groupId = Arg.checkNotBlank("groupId", groupId);
 153  0
       return this;
 154  
     }
 155  
 
 156  
     /**
 157  
      * Sets the name of the artifact.
 158  
      *
 159  
      * @param name the name of the artifact.
 160  
      * @return a reference to this builder instance.
 161  
      * @throws IllegalArgumentException if {@code name} is blank.
 162  
      */
 163  
     public Builder withName(final String name) throws IllegalArgumentException
 164  
     {
 165  0
       this.name = Arg.checkNotBlank("name", name);
 166  0
       return this;
 167  
     }
 168  
 
 169  
     /**
 170  
      * Sets the version of the artifact.
 171  
      *
 172  
      * @param version the version of the artifact.
 173  
      * @return a reference to this builder instance.
 174  
      * @throws IllegalArgumentException if {@code version} is blank.
 175  
      */
 176  
     public Builder withVersion(final String version)
 177  
       throws IllegalArgumentException
 178  
     {
 179  0
       this.version = Arg.checkNotBlank("version", version);
 180  0
       return this;
 181  
     }
 182  
 
 183  
     /**
 184  
      * Sets the artifact type that is expressed by the artifact's file name
 185  
      * extension.
 186  
      *
 187  
      * @param archiveType the artifact type that is expressed by the artifact's
 188  
      *          file name extension.
 189  
      * @return a reference to this builder instance.
 190  
      * @throws IllegalArgumentException if {@code archiveType} is blank.
 191  
      */
 192  
     public Builder withArchiveType(final String archiveType)
 193  
       throws IllegalArgumentException
 194  
     {
 195  0
       this.archiveType = Arg.checkNotBlank("archiveType", archiveType);
 196  0
       return this;
 197  
     }
 198  
 
 199  
     /**
 200  
      * Sets the classifier to the artifact.
 201  
      *
 202  
      * @param classifier the classifier to the artifact. May be
 203  
      *          <code>null</code>.
 204  
      * @return a reference to this builder instance.
 205  
      * @throws IllegalArgumentException if classifier is blank except
 206  
      *           <code>null</code>.
 207  
      */
 208  
     public Builder withClassifier(final String classifier)
 209  
       throws IllegalArgumentException
 210  
     {
 211  0
       this.classifier = Arg.checkNotBlankExceptNull("classifier", classifier);
 212  0
       return this;
 213  
     }
 214  
 
 215  
     // --- business -----------------------------------------------------------
 216  
 
 217  
     /**
 218  
      * Creates an instance of {@link ArtifactId}.
 219  
      *
 220  
      * @return an instance.
 221  
      */
 222  
     public ArtifactId build()
 223  
     {
 224  0
       Arg.checkNotBlank("groupId", groupId);
 225  0
       Arg.checkNotBlank("name", name);
 226  0
       Arg.checkNotBlank("version", version);
 227  0
       Arg.checkNotBlank("archiveType", archiveType);
 228  0
       Arg.checkNotBlankExceptNull("classifier", classifier);
 229  
 
 230  0
       final ArtifactId instance = new ArtifactId(this);
 231  0
       return instance;
 232  
     }
 233  
 
 234  
     // --- object basics ------------------------------------------------------
 235  
   }
 236  
 
 237  
   // ********************************* Methods ********************************
 238  
 
 239  
   // --- init -----------------------------------------------------------------
 240  
 
 241  
   // --- factory --------------------------------------------------------------
 242  
 
 243  
   /**
 244  
    * Helper to create instances of {@link ArtifactId} instead of using the
 245  
    * {@link ArtifactId.Builder}.
 246  
    *
 247  
    * @param groupId the group the artifact belongs to.
 248  
    * @param name the identifier of the artifact.
 249  
    * @param version the version of the artifact.
 250  
    * @param archiveType the artifact type that is expressed by the artifact's
 251  
    *          file name extension.
 252  
    * @param classifier the classifier to the artifact.
 253  
    * @return the instance.
 254  
    * @throws IllegalArgumentException if any of the arguments (except
 255  
    *           {@code classifier}) is blank or {@code classifier} is blank
 256  
    *           except being <code>null</code>.
 257  
    */
 258  
   public static ArtifactId create(final String groupId, final String name,
 259  
       final String version, final String archiveType, final String classifier)
 260  
     throws IllegalArgumentException
 261  
   {
 262  0
     final Builder builder = new Builder();
 263  0
     builder.withGroupId(groupId).withName(name).withVersion(version)
 264  
         .withArchiveType(archiveType).withClassifier(classifier);
 265  0
     return builder.build();
 266  
   }
 267  
 
 268  
   // --- get&set --------------------------------------------------------------
 269  
 
 270  
   /**
 271  
    * Returns the group the artifact belongs to.
 272  
    *
 273  
    * @return the group the artifact belongs to.
 274  
    */
 275  
   public String getGroupId()
 276  
   {
 277  0
     return groupId;
 278  
   }
 279  
 
 280  
   /**
 281  
    * Returns the name of the artifact.
 282  
    *
 283  
    * @return the name of the artifact.
 284  
    */
 285  
   public String getName()
 286  
   {
 287  0
     return name;
 288  
   }
 289  
 
 290  
   /**
 291  
    * Returns the version of the artifact.
 292  
    *
 293  
    * @return the version of the artifact.
 294  
    */
 295  
   public String getVersion()
 296  
   {
 297  0
     return version;
 298  
   }
 299  
 
 300  
   /**
 301  
    * Returns the artifact type that is expressed by the artifact's file name
 302  
    * extension.
 303  
    *
 304  
    * @return the artifact type that is expressed by the artifact's file name
 305  
    *         extension.
 306  
    */
 307  
   public String getArchiveType()
 308  
   {
 309  0
     return archiveType;
 310  
   }
 311  
 
 312  
   /**
 313  
    * Returns the classifier to the artifact. May be <code>null</code>.
 314  
    *
 315  
    * @return the classifier to the artifact.
 316  
    */
 317  
   public String getClassifier()
 318  
   {
 319  0
     return classifier;
 320  
   }
 321  
 
 322  
   // --- business -------------------------------------------------------------
 323  
 
 324  
   // --- object basics --------------------------------------------------------
 325  
 
 326  
   /**
 327  
    * Returns the hash code of the object.
 328  
    *
 329  
    * @return the hash code.
 330  
    */
 331  
   @Override
 332  
   public int hashCode()
 333  
   {
 334  0
     int result = 17;
 335  0
     result = 37 * result + ObjectUtils.hashCode(name);
 336  0
     result = 37 * result + ObjectUtils.hashCode(groupId);
 337  0
     result = 37 * result + ObjectUtils.hashCode(version);
 338  0
     return result;
 339  
   }
 340  
 
 341  
   /**
 342  
    * Returns <code>true</code> if the given object is semantically equal to the
 343  
    * given object, <code>false</code> otherwise.
 344  
    *
 345  
    * @param object the instance to compare to.
 346  
    * @return <code>true</code> if the given object is semantically equal to the
 347  
    *         given object, <code>false</code> otherwise.
 348  
    */
 349  
   @Override
 350  
   public boolean equals(final Object object)
 351  
   {
 352  0
     if (this == object)
 353  
     {
 354  0
       return true;
 355  
     }
 356  0
     else if (object == null || getClass() != object.getClass())
 357  
     {
 358  0
       return false;
 359  
     }
 360  
 
 361  0
     final ArtifactId other = (ArtifactId) object;
 362  
 
 363  0
     return (ObjectUtils.equals(name, other.name)
 364  
             && ObjectUtils.equals(groupId, other.groupId)
 365  
             && ObjectUtils.equals(version, other.version)
 366  
             && ObjectUtils.equals(archiveType, other.archiveType) && ObjectUtils
 367  
         .equals(classifier, other.classifier));
 368  
   }
 369  
 
 370  
   /**
 371  
    * {@inheritDoc}
 372  
    *
 373  
    * @see java.lang.Comparable#compareTo(java.lang.Object)
 374  
    */
 375  
   @Override
 376  
   public int compareTo(final ArtifactId o)
 377  
   {
 378  0
     int result = ObjectUtils.compare(name, o.name);
 379  0
     if (result == 0)
 380  
     {
 381  0
       result = ObjectUtils.compare(groupId, o.groupId);
 382  0
       if (result == 0)
 383  
       {
 384  0
         result = ObjectUtils.compare(version, o.version);
 385  0
         if (result == 0)
 386  
         {
 387  0
           result = ObjectUtils.compare(archiveType, o.archiveType);
 388  
           // CHECKSTYLE:OFF
 389  0
           if (result == 0) // NOPMD
 390  
           {
 391  0
             result = ObjectUtils.compare(classifier, o.classifier);
 392  
           }
 393  
           // CHECKSTYLE:ON
 394  
         }
 395  
       }
 396  
     }
 397  
 
 398  0
     return result;
 399  
   }
 400  
 
 401  
   /**
 402  
    * Returns the short string representation of the object.
 403  
    *
 404  
    * @return the short string representation of the object.
 405  
    */
 406  
   public String toShortString()
 407  
   {
 408  0
     final StringBuilder buffer = new StringBuilder();
 409  
 
 410  0
     buffer.append(groupId);
 411  0
     buffer.append(':');
 412  0
     buffer.append(name);
 413  0
     buffer.append(':');
 414  0
     buffer.append(version);
 415  
 
 416  0
     return buffer.toString();
 417  
   }
 418  
 
 419  
   /**
 420  
    * Returns the string representation of the object.
 421  
    *
 422  
    * @return the string representation of the object.
 423  
    */
 424  
   @Override
 425  
   public String toString()
 426  
   {
 427  0
     final StringBuilder buffer = new StringBuilder();
 428  
 
 429  0
     buffer.append(groupId);
 430  0
     buffer.append(':');
 431  0
     buffer.append(name);
 432  0
     buffer.append(':');
 433  0
     buffer.append(version);
 434  0
     buffer.append(':');
 435  0
     buffer.append(archiveType);
 436  0
     if (classifier != null)
 437  
     {
 438  0
       buffer.append(':');
 439  0
       buffer.append(classifier);
 440  
     }
 441  
 
 442  0
     return buffer.toString();
 443  
   }
 444  
 }