1
1
/*
2
- * Copyright 2015 the original author or authors.
2
+ * Copyright 2015-2016 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
15
15
*/
16
16
package org .springframework .data .domain ;
17
17
18
+ import lombok .Value ;
19
+
18
20
import org .springframework .util .Assert ;
19
21
20
22
/**
23
25
* @author Oliver Gierke
24
26
* @since 1.10
25
27
*/
28
+ @ Value
26
29
public class Range <T extends Comparable <T >> {
27
30
31
+ /**
32
+ * The lower bound of the range.
33
+ */
28
34
private final T lowerBound ;
35
+
36
+ /**
37
+ * The upper bound of the range.
38
+ */
29
39
private final T upperBound ;
40
+
41
+ /**
42
+ * Whether the lower bound is considered inclusive.
43
+ */
30
44
private final boolean lowerInclusive ;
45
+
46
+ /**
47
+ * Whether the lower bound is considered inclusive.
48
+ */
31
49
private final boolean upperInclusive ;
32
50
33
51
/**
@@ -43,7 +61,8 @@ public Range(T lowerBound, T upperBound) {
43
61
}
44
62
45
63
/**
46
- * Createsa new {@link Range} with the given lower and upper bound as well as the given inclusive/exclusive semantics.
64
+ * Creates a new {@link Range} with the given lower and upper bound as well as the given inclusive/exclusive
65
+ * semantics.
47
66
*
48
67
* @param lowerBound can be {@literal null}.
49
68
* @param upperBound can be {@literal null}.
@@ -58,24 +77,6 @@ public Range(T lowerBound, T upperBound, boolean lowerInclusive, boolean upperIn
58
77
this .upperInclusive = upperInclusive ;
59
78
}
60
79
61
- /**
62
- * Returns the lower bound of the range.
63
- *
64
- * @return can be {@literal null}.
65
- */
66
- public T getLowerBound () {
67
- return lowerBound ;
68
- }
69
-
70
- /**
71
- * Returns the upper bound of the range.
72
- *
73
- * @return can be {@literal null}.
74
- */
75
- public T getUpperBound () {
76
- return upperBound ;
77
- }
78
-
79
80
/**
80
81
* Returns whether the {@link Range} contains the given value.
81
82
*
@@ -86,10 +87,10 @@ public boolean contains(T value) {
86
87
87
88
Assert .notNull (value , "Reference value must not be null!" );
88
89
89
- boolean greaterThanLowerBound = lowerBound == null ? true : lowerInclusive ? lowerBound . compareTo ( value ) <= 0
90
- : lowerBound .compareTo (value ) < 0 ;
91
- boolean lessThanUpperBound = upperBound == null ? true : upperInclusive ? upperBound . compareTo ( value ) >= 0
92
- : upperBound .compareTo (value ) > 0 ;
90
+ boolean greaterThanLowerBound = lowerBound == null ? true
91
+ : lowerInclusive ? lowerBound . compareTo ( value ) <= 0 : lowerBound .compareTo (value ) < 0 ;
92
+ boolean lessThanUpperBound = upperBound == null ? true
93
+ : upperInclusive ? upperBound . compareTo ( value ) >= 0 : upperBound .compareTo (value ) > 0 ;
93
94
94
95
return greaterThanLowerBound && lessThanUpperBound ;
95
96
}
0 commit comments