View Javadoc

1   package org.sonatype.aether.graph;
2   
3   /*******************************************************************************
4    * Copyright (c) 2010-2011 Sonatype, Inc.
5    * All rights reserved. This program and the accompanying materials
6    * are made available under the terms of the Eclipse Public License v1.0
7    * which accompanies this distribution, and is available at
8    *   http://www.eclipse.org/legal/epl-v10.html
9    *******************************************************************************/
10  
11  /**
12   * An exclusion of one or more transitive dependencies. <em>Note:</em> Instances of this class are immutable and the
13   * exposed mutators return new objects rather than changing the current instance.
14   * 
15   * @author Benjamin Bentmann
16   * @see Dependency#getExclusions()
17   */
18  public final class Exclusion
19  {
20  
21      private final String groupId;
22  
23      private final String artifactId;
24  
25      private final String classifier;
26  
27      private final String extension;
28  
29      /**
30       * Creates an exclusion for artifacts with the specified coordinates.
31       * 
32       * @param groupId The group identifier, may be {@code null}.
33       * @param artifactId The artifact identifier, may be {@code null}.
34       * @param classifier The classifier, may be {@code null}.
35       * @param extension The file extension, may be {@code null}.
36       */
37      public Exclusion( String groupId, String artifactId, String classifier, String extension )
38      {
39          this.groupId = ( groupId != null ) ? groupId : "";
40          this.artifactId = ( artifactId != null ) ? artifactId : "";
41          this.classifier = ( classifier != null ) ? classifier : "";
42          this.extension = ( extension != null ) ? extension : "";
43      }
44  
45      /**
46       * Gets the group identifier for artifacts to exclude.
47       * 
48       * @return The group identifier, never {@code null}.
49       */
50      public String getGroupId()
51      {
52          return groupId;
53      }
54  
55      /**
56       * Gets the artifact identifier for artifacts to exclude.
57       * 
58       * @return The artifact identifier, never {@code null}.
59       */
60      public String getArtifactId()
61      {
62          return artifactId;
63      }
64  
65      /**
66       * Gets the classifier for artifacts to exclude.
67       * 
68       * @return The classifier, never {@code null}.
69       */
70      public String getClassifier()
71      {
72          return classifier;
73      }
74  
75      /**
76       * Gets the file extension for artifacts to exclude.
77       * 
78       * @return The file extension of artifacts to exclude, never {@code null}.
79       */
80      public String getExtension()
81      {
82          return extension;
83      }
84  
85      @Override
86      public String toString()
87      {
88          return getGroupId() + ':' + getArtifactId() + ':' + getExtension()
89              + ( getClassifier().length() > 0 ? ':' + getClassifier() : "" );
90      }
91  
92      @Override
93      public boolean equals( Object obj )
94      {
95          if ( obj == this )
96          {
97              return true;
98          }
99          else if ( obj == null || !getClass().equals( obj.getClass() ) )
100         {
101             return false;
102         }
103 
104         Exclusion that = (Exclusion) obj;
105 
106         return artifactId.equals( that.artifactId ) && groupId.equals( that.groupId )
107             && extension.equals( that.extension ) && classifier.equals( that.classifier );
108     }
109 
110     @Override
111     public int hashCode()
112     {
113         int hash = 17;
114         hash = hash * 31 + artifactId.hashCode();
115         hash = hash * 31 + groupId.hashCode();
116         hash = hash * 31 + classifier.hashCode();
117         hash = hash * 31 + extension.hashCode();
118         return hash;
119     }
120 
121 }