1 package org.codehaus.mojo.jaxb2.shared.version;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.codehaus.mojo.jaxb2.shared.Validate;
23
24
25
26
27
28
29
30 public class DependencyInfo implements Comparable<DependencyInfo> {
31
32
33 private static final String GROUP_ARTIFACT_SEPARATOR = "/";
34 private String groupId;
35 private String artifactId;
36 private String version;
37 private String scope = "compile";
38 private String type = "jar";
39
40 public DependencyInfo(final String groupId, final String artifactId, final String version) {
41 this.groupId = groupId;
42 this.artifactId = artifactId;
43 this.version = version;
44 }
45
46
47
48
49 public String getGroupId() {
50 return groupId;
51 }
52
53
54
55
56 public String getArtifactId() {
57 return artifactId;
58 }
59
60
61
62
63 public String getVersion() {
64 return version;
65 }
66
67
68
69
70 public String getType() {
71 return type;
72 }
73
74
75
76
77 public String getScope() {
78 return scope;
79 }
80
81
82
83
84
85
86 public void setType(final String type) {
87
88
89 Validate.notEmpty(type, "type");
90
91
92 this.type = type;
93 }
94
95
96
97
98
99
100 public void setScope(final String scope) {
101
102
103 Validate.notEmpty(scope, "scope");
104
105
106 this.scope = scope;
107 }
108
109
110
111
112 public String getGroupArtifactKey() {
113 return getGroupId() + GROUP_ARTIFACT_SEPARATOR + getArtifactId();
114 }
115
116
117
118
119 @Override
120 public int hashCode() {
121 return groupId.hashCode() + artifactId.hashCode() + version.hashCode() + type.hashCode();
122 }
123
124
125
126
127 @Override
128 public String toString() {
129 return groupId + GROUP_ARTIFACT_SEPARATOR
130 + artifactId + GROUP_ARTIFACT_SEPARATOR
131 + version + GROUP_ARTIFACT_SEPARATOR
132 + scope + GROUP_ARTIFACT_SEPARATOR
133 + type;
134 }
135
136
137
138
139 @Override
140 public int compareTo(final DependencyInfo that) {
141
142
143 if (that == this) {
144 return 0;
145 }
146 if (that == null) {
147 return -1;
148 }
149
150
151 int toReturn = this.getGroupId().compareTo(that.getGroupId());
152 if (toReturn == 0) {
153 toReturn = this.getArtifactId().compareTo(that.getArtifactId());
154 }
155 if (toReturn == 0) {
156 toReturn = this.getVersion().compareTo(that.getVersion());
157 }
158 if (toReturn == 0) {
159 toReturn = this.getType().compareTo(that.getType());
160 }
161
162
163 return toReturn;
164 }
165 }