1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.repository.metadata;
20
21 import org.apache.maven.artifact.ArtifactScopeEnum;
22
23
24
25
26
27 @Deprecated
28 public class MetadataGraphVertex implements Comparable<MetadataGraphVertex> {
29 ArtifactMetadata md;
30
31
32 private boolean compareVersion = false;
33 private boolean compareScope = false;
34
35 public MetadataGraphVertex(ArtifactMetadata md) {
36 super();
37 this.md = md;
38 }
39
40 public MetadataGraphVertex(ArtifactMetadata md, boolean compareVersion, boolean compareScope) {
41 this(md);
42 this.compareVersion = compareVersion;
43 this.compareScope = compareScope;
44 }
45
46 public ArtifactMetadata getMd() {
47 return md;
48 }
49
50 public void setMd(ArtifactMetadata md) {
51 this.md = md;
52 }
53
54
55 public boolean isCompareVersion() {
56 return compareVersion;
57 }
58
59 public void setCompareVersion(boolean compareVersion) {
60 this.compareVersion = compareVersion;
61 }
62
63 public boolean isCompareScope() {
64 return compareScope;
65 }
66
67 public void setCompareScope(boolean compareScope) {
68 this.compareScope = compareScope;
69 }
70
71
72 @Override
73 public String toString() {
74 return "[" + (md == null ? "no metadata" : md.toString()) + "]";
75 }
76
77
78 private static int compareStrings(String s1, String s2) {
79 if (s1 == null && s2 == null) {
80 return 0;
81 }
82
83 if (s1 == null ) {
84 return -1;
85 }
86
87 if (
88 s2 == null) {
89 return 1;
90 }
91
92 return s1.compareTo(s2);
93 }
94
95
96 public int compareTo(MetadataGraphVertex vertex) {
97 if (vertex == null || vertex.getMd() == null) {
98 return 1;
99 }
100
101 ArtifactMetadata vmd = vertex.getMd();
102
103 if (vmd == null) {
104 if (md == null) {
105 return 0;
106 } else {
107 return 1;
108 }
109 }
110
111 int g = compareStrings(md.groupId, vmd.groupId);
112
113 if (g == 0) {
114 int a = compareStrings(md.artifactId, vmd.artifactId);
115 if (a == 0) {
116 if (compareVersion) {
117 int v = compareStrings(md.version, vmd.version);
118 if (v == 0) {
119 if (compareScope) {
120 String s1 = ArtifactScopeEnum.checkScope(md.artifactScope)
121 .getScope();
122 String s2 = ArtifactScopeEnum.checkScope(vmd.artifactScope)
123 .getScope();
124 return s1.compareTo(s2);
125 } else {
126 return 0;
127 }
128 } else {
129 return v;
130 }
131 } else {
132 return 0;
133 }
134 } else {
135 return a;
136 }
137 }
138
139 return g;
140 }
141
142
143 @Override
144 public boolean equals(Object vo) {
145 if (!(vo instanceof MetadataGraphVertex)) {
146 return false;
147 }
148 return compareTo((MetadataGraphVertex) vo) == 0;
149 }
150
151
152
153 @Override
154 public int hashCode() {
155 if (md == null) {
156 return super.hashCode();
157 }
158 StringBuilder hashString = new StringBuilder(128);
159 hashString.append(md.groupId).append('|');
160 hashString.append(md.artifactId).append('|');
161
162 if (compareVersion) {
163 hashString.append(md.version).append('|');
164 }
165
166 if (compareScope) {
167 hashString.append(md.getArtifactScope()).append('|');
168 }
169
170 return hashString.toString().hashCode();
171
172
173
174 }
175
176
177
178 }