View Javadoc

1   package de.matthias_burbach.deputy.core.project;
2   
3   
4   /***
5    * @author Matthias Burbach
6    */
7   public class ProjectQualifierImpl implements ProjectQualifier {
8       /***
9        * The group id of the project.
10       */
11      private String groupId;
12  
13      /***
14       * The artifact id of the project.
15       */
16      private String artifactId;
17  
18      /***
19       * The version of the project.
20       */
21      private String version;
22  
23      /***
24       * @return The group id of the project.
25       */
26      public String getGroupId() {
27          return groupId;
28      }
29  
30      /***
31       * @param groupId The group id of the project.
32       */
33      public void setGroupId(final String groupId) {
34          this.groupId = groupId;
35      }
36  
37      /***
38       * @return The artifact id of the project.
39       */
40      public String getArtifactId() {
41          return artifactId;
42      }
43  
44      /***
45       * @param artifactId The artifact id of the project.
46       */
47      public void setArtifactId(final String artifactId) {
48          this.artifactId = artifactId;
49      }
50  
51      /***
52       * @return The version of the project.
53       */
54      public String getVersion() {
55          return version;
56      }
57  
58      /***
59       * @param version The version of the project.
60       */
61      public void setVersion(final String version) {
62          this.version = version;
63      }
64  
65  
66      /*(non-Javadoc)
67       * @see java.lang.Object#equals(java.lang.Object)
68       */
69      /***
70       * {@inheritDoc}
71       * Note: Does not use the group id but only the artifact id and the version
72       * to decide equality. This is because the group id is not always available
73       * and it is assumed that the artifact id and the version identify a project
74       * uniquely.
75       */
76      public boolean equals(final Object object) {
77          boolean result = false;
78          if (object instanceof ProjectQualifier) {
79              ProjectQualifier candidate = (ProjectQualifier) object;
80              if (candidate.getArtifactId().equals(artifactId)
81                      && candidate.getVersion().equals(version)) {
82                  result = true;
83              }
84          }
85          return result;
86      }
87  
88  
89      /*(non-Javadoc)
90       * @see java.lang.Object#hashCode()
91       */
92      /***
93       * {@inheritDoc}
94       */
95      public int hashCode() {
96          final int initialValue = 7;
97          final int shiftingMultiplier = 31;
98          int result = initialValue;
99          result = result * shiftingMultiplier + artifactId.hashCode();
100         result = result * shiftingMultiplier + version.hashCode();
101         return result;
102     }
103 }