View Javadoc
1   package org.eclipse.aether.graph;
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   * An exclusion of one or more transitive dependencies. <em>Note:</em> Instances of this class are immutable and the
24   * exposed mutators return new objects rather than changing the current instance.
25   * 
26   * @see Dependency#getExclusions()
27   */
28  public final class Exclusion
29  {
30  
31      private final String groupId;
32  
33      private final String artifactId;
34  
35      private final String classifier;
36  
37      private final String extension;
38  
39      /**
40       * Creates an exclusion for artifacts with the specified coordinates.
41       * 
42       * @param groupId The group identifier, may be {@code null}.
43       * @param artifactId The artifact identifier, may be {@code null}.
44       * @param classifier The classifier, may be {@code null}.
45       * @param extension The file extension, may be {@code null}.
46       */
47      public Exclusion( String groupId, String artifactId, String classifier, String extension )
48      {
49          this.groupId = ( groupId != null ) ? groupId : "";
50          this.artifactId = ( artifactId != null ) ? artifactId : "";
51          this.classifier = ( classifier != null ) ? classifier : "";
52          this.extension = ( extension != null ) ? extension : "";
53      }
54  
55      /**
56       * Gets the group identifier for artifacts to exclude.
57       * 
58       * @return The group identifier, never {@code null}.
59       */
60      public String getGroupId()
61      {
62          return groupId;
63      }
64  
65      /**
66       * Gets the artifact identifier for artifacts to exclude.
67       * 
68       * @return The artifact identifier, never {@code null}.
69       */
70      public String getArtifactId()
71      {
72          return artifactId;
73      }
74  
75      /**
76       * Gets the classifier for artifacts to exclude.
77       * 
78       * @return The classifier, never {@code null}.
79       */
80      public String getClassifier()
81      {
82          return classifier;
83      }
84  
85      /**
86       * Gets the file extension for artifacts to exclude.
87       * 
88       * @return The file extension of artifacts to exclude, never {@code null}.
89       */
90      public String getExtension()
91      {
92          return extension;
93      }
94  
95      @Override
96      public String toString()
97      {
98          return getGroupId() + ':' + getArtifactId() + ':' + getExtension()
99              + ( getClassifier().length() > 0 ? ':' + getClassifier() : "" );
100     }
101 
102     @Override
103     public boolean equals( Object obj )
104     {
105         if ( obj == this )
106         {
107             return true;
108         }
109         else if ( obj == null || !getClass().equals( obj.getClass() ) )
110         {
111             return false;
112         }
113 
114         Exclusion that = (Exclusion) obj;
115 
116         return artifactId.equals( that.artifactId ) && groupId.equals( that.groupId )
117             && extension.equals( that.extension ) && classifier.equals( that.classifier );
118     }
119 
120     @Override
121     public int hashCode()
122     {
123         int hash = 17;
124         hash = hash * 31 + artifactId.hashCode();
125         hash = hash * 31 + groupId.hashCode();
126         hash = hash * 31 + classifier.hashCode();
127         hash = hash * 31 + extension.hashCode();
128         return hash;
129     }
130 
131 }