@@ -18,13 +18,47 @@ public final class VersionRange implements Comparable<VersionRange> {
18
18
19
19
private final boolean rightIsExclusive ;
20
20
21
+ private static final String VERSION_SEPARATOR = ">" ;
22
+
23
+ private static final String START_EXCLUDING_PREFIX = "(" ;
24
+
25
+ private static final String START_INCLUDING_PREFIX = "[" ;
26
+
27
+ private static final String END_EXCLUDING_SUFFIX = ")" ;
28
+
29
+ private static final String END_INCLUDING_SUFFIX = "]" ;
30
+
31
+ public static String getVersionSeparator () {
32
+
33
+ return VERSION_SEPARATOR ;
34
+ }
35
+
36
+ public static String getStartExcludingPrefix () {
37
+
38
+ return START_EXCLUDING_PREFIX ;
39
+ }
40
+
41
+ public static String getStartIncludingPrefix () {
42
+
43
+ return START_INCLUDING_PREFIX ;
44
+ }
45
+
46
+ public static String getEndExcludingSuffix () {
47
+
48
+ return END_EXCLUDING_SUFFIX ;
49
+ }
50
+
51
+ public static String getEndIncludingSuffix () {
52
+
53
+ return END_INCLUDING_SUFFIX ;
54
+ }
55
+
21
56
/**
22
57
* The constructor.
23
58
*
24
59
* @param min the {@link #getMin() minimum}.
25
- * @param max the {@link #getMax() maximum} (including) .
60
+ * @param max the {@link #getMax() maximum}.
26
61
*/
27
-
28
62
public VersionRange (VersionIdentifier min , VersionIdentifier max ) {
29
63
30
64
super ();
@@ -71,7 +105,6 @@ public VersionRange(VersionIdentifier min, VersionIdentifier max, boolean leftIs
71
105
/**
72
106
* @return the minimum {@link VersionIdentifier} or {@code null} for no lower bound.
73
107
*/
74
- // @JsonBackReference
75
108
public VersionIdentifier getMin () {
76
109
77
110
return this .min ;
@@ -80,7 +113,6 @@ public VersionIdentifier getMin() {
80
113
/**
81
114
* @return the maximum {@link VersionIdentifier} or {@code null} for no upper bound.
82
115
*/
83
- // @JsonBackReference
84
116
public VersionIdentifier getMax () {
85
117
86
118
return this .max ;
@@ -193,15 +225,15 @@ public boolean equals(Object obj) {
193
225
public String toString () {
194
226
195
227
StringBuilder sb = new StringBuilder ();
196
- sb .append (this .leftIsExclusive ? '(' : '[' );
228
+ sb .append (this .leftIsExclusive ? START_EXCLUDING_PREFIX : START_INCLUDING_PREFIX );
197
229
if (this .min != null ) {
198
230
sb .append (this .min );
199
231
}
200
- sb .append ('>' );
232
+ sb .append (VERSION_SEPARATOR );
201
233
if (this .max != null ) {
202
234
sb .append (this .max );
203
235
}
204
- sb .append (this .rightIsExclusive ? ')' : ']' );
236
+ sb .append (this .rightIsExclusive ? END_EXCLUDING_SUFFIX : END_INCLUDING_SUFFIX );
205
237
return sb .toString ();
206
238
}
207
239
@@ -215,22 +247,22 @@ public static VersionRange of(String value) {
215
247
boolean leftIsExclusive = false ;
216
248
boolean rightIsExclusive = false ;
217
249
218
- if (value .startsWith ("(" )) {
250
+ if (value .startsWith (START_EXCLUDING_PREFIX )) {
219
251
leftIsExclusive = true ;
220
- value = value .substring (1 );
252
+ value = value .substring (START_EXCLUDING_PREFIX . length () );
221
253
}
222
- if (value .startsWith ("[" )) {
223
- value = value .substring (1 );
254
+ if (value .startsWith (START_INCLUDING_PREFIX )) {
255
+ value = value .substring (START_INCLUDING_PREFIX . length () );
224
256
}
225
- if (value .endsWith (")" )) {
257
+ if (value .endsWith (END_EXCLUDING_SUFFIX )) {
226
258
rightIsExclusive = true ;
227
- value = value .substring (0 , value .length () - 1 );
259
+ value = value .substring (0 , value .length () - END_EXCLUDING_SUFFIX . length () );
228
260
}
229
- if (value .endsWith ("]" )) {
230
- value = value .substring (0 , value .length () - 1 );
261
+ if (value .endsWith (END_INCLUDING_SUFFIX )) {
262
+ value = value .substring (0 , value .length () - END_EXCLUDING_SUFFIX . length () );
231
263
}
232
264
233
- int index = value .indexOf ('>' );
265
+ int index = value .indexOf (VERSION_SEPARATOR );
234
266
if (index == -1 ) {
235
267
return null ; // log warning?
236
268
}
0 commit comments