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