1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.eclipse.aether.internal.test.util;
20
21 import java.util.Objects;
22
23 import org.eclipse.aether.version.Version;
24 import org.eclipse.aether.version.VersionConstraint;
25 import org.eclipse.aether.version.VersionRange;
26
27 import static java.util.Objects.requireNonNull;
28
29
30
31
32 public final class TestVersionConstraint implements VersionConstraint {
33
34 private final VersionRange range;
35
36 private final Version version;
37
38
39
40
41
42
43 public TestVersionConstraint(VersionRange range) {
44 this.range = requireNonNull(range, "version range cannot be null");
45 this.version = null;
46 }
47
48
49
50
51
52
53 public TestVersionConstraint(Version version) {
54 this.version = requireNonNull(version, "version cannot be null");
55 this.range = null;
56 }
57
58 public VersionRange getRange() {
59 return range;
60 }
61
62 public Version getVersion() {
63 return version;
64 }
65
66 public boolean containsVersion(Version version) {
67 if (range == null) {
68 return version.equals(this.version);
69 } else {
70 return range.containsVersion(version);
71 }
72 }
73
74 @Override
75 public String toString() {
76 return String.valueOf((range == null) ? version : range);
77 }
78
79 @Override
80 public boolean equals(Object obj) {
81 if (this == obj) {
82 return true;
83 }
84 if (obj == null || !getClass().equals(obj.getClass())) {
85 return false;
86 }
87
88 TestVersionConstraint that = (TestVersionConstraint) obj;
89
90 return Objects.equals(range, that.range) && Objects.equals(version, that.getVersion());
91 }
92
93 @Override
94 public int hashCode() {
95 int hash = 17;
96 hash = hash * 31 + hash(getRange());
97 hash = hash * 31 + hash(getVersion());
98 return hash;
99 }
100
101 private static int hash(Object obj) {
102 return obj != null ? obj.hashCode() : 0;
103 }
104 }