1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
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  
28  
29      private final QualifiedName requestingDependency;
30  
31      
32  
33  
34      private final boolean managedDependency;
35  
36      
37  
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 }