View Javadoc
1   /*
2    * Licensed under the Apache License, Version 2.0 (the "License");
3    * you may not use this file except in compliance with the License.
4    * You may obtain a copy of the License at
5    *
6    * http://www.apache.org/licenses/LICENSE-2.0
7    *
8    * Unless required by applicable law or agreed to in writing, software
9    * distributed under the License is distributed on an "AS IS" BASIS,
10   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11   * See the License for the specific language governing permissions and
12   * limitations under the License.
13   */
14  
15  package org.basepom.mojo.dvc.version;
16  
17  import org.basepom.mojo.dvc.QualifiedName;
18  
19  import java.util.Objects;
20  
21  import com.google.common.base.MoreObjects;
22  
23  public final class VersionResolutionElement
24          implements Comparable<VersionResolutionElement> {
25  
26      /**
27       * Requesting Dependency name.
28       */
29      private final QualifiedName requestingDependency;
30  
31      /**
32       * True if the dependency was managed to this version.
33       */
34      private final boolean managedDependency;
35  
36      /**
37       * True if this version resolution is directly from the root project.
38       */
39      private final boolean directDependency;
40  
41      private boolean conflict = false;
42  
43      VersionResolutionElement(final QualifiedName requestingDependency, final boolean managedDependency, final boolean directDependency) {
44          this.requestingDependency = requestingDependency;
45          this.managedDependency = managedDependency;
46          this.directDependency = directDependency;
47      }
48  
49      public QualifiedName getRequestingDependency() {
50          return requestingDependency;
51      }
52  
53      public boolean isManagedDependency() {
54          return managedDependency;
55      }
56  
57      public boolean isDirectDependency() {
58          return directDependency;
59      }
60  
61      public void conflict() {
62          this.conflict = true;
63      }
64  
65      public boolean hasConflict() {
66          return conflict;
67      }
68  
69      @Override
70      public boolean equals(final Object o) {
71          if (this == o) {
72              return true;
73          }
74          if (o == null || getClass() != o.getClass()) {
75              return false;
76          }
77          final VersionResolutionElement that = (VersionResolutionElement) o;
78          return managedDependency == that.managedDependency
79                  && directDependency == that.directDependency
80                  && requestingDependency.equals(that.requestingDependency);
81      }
82  
83      @Override
84      public int hashCode() {
85          return Objects.hash(requestingDependency, managedDependency, directDependency);
86      }
87  
88      @Override
89      public String toString() {
90          return MoreObjects.toStringHelper(this)
91                  .add("requestingDependency", requestingDependency)
92                  .add("managedDependency", managedDependency)
93                  .add("directDependency", directDependency)
94                  .add("conflict", conflict)
95                  .toString();
96      }
97  
98      @Override
99      public int compareTo(final VersionResolutionElement other) {
100         if (other == null) {
101             return 1;
102         } else if (other == this || equals(other)) {
103             return 0;
104         } else {
105             return getRequestingDependency().getMinimalName().compareTo(other.getRequestingDependency().getMinimalName());
106         }
107     }
108 }