1 package org.eclipse.aether.util.version;
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 GenericVersionConstraint
34 implements VersionConstraint
35 {
36
37 private final VersionRange range;
38
39 private final Version version;
40
41
42
43
44
45
46 GenericVersionConstraint( 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 GenericVersionConstraint( 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 GenericVersionConstraint that = (GenericVersionConstraint) obj;
104
105 return Objects.equals( range, that.range ) && Objects.equals( version, that.getVersion() );
106 }
107
108 @Override
109 public int hashCode()
110 {
111 int hash = 17;
112 hash = hash * 31 + hash( getRange() );
113 hash = hash * 31 + hash( getVersion() );
114 return hash;
115 }
116
117 private static int hash( Object obj )
118 {
119 return obj != null ? obj.hashCode() : 0;
120 }
121
122 }