Skip to content

Commit b4518f0

Browse files
committed
DATACMNS-920 - Added accessors for Range.lowerInclusive / ….upperInclusive.
Generally improved Range to be a value type by using Lombok's @value.
1 parent 0005412 commit b4518f0

File tree

1 file changed

+25
-24
lines changed
  • src/main/java/org/springframework/data/domain

1 file changed

+25
-24
lines changed

src/main/java/org/springframework/data/domain/Range.java

+25-24
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2015 the original author or authors.
2+
* Copyright 2015-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -15,6 +15,8 @@
1515
*/
1616
package org.springframework.data.domain;
1717

18+
import lombok.Value;
19+
1820
import org.springframework.util.Assert;
1921

2022
/**
@@ -23,11 +25,27 @@
2325
* @author Oliver Gierke
2426
* @since 1.10
2527
*/
28+
@Value
2629
public class Range<T extends Comparable<T>> {
2730

31+
/**
32+
* The lower bound of the range.
33+
*/
2834
private final T lowerBound;
35+
36+
/**
37+
* The upper bound of the range.
38+
*/
2939
private final T upperBound;
40+
41+
/**
42+
* Whether the lower bound is considered inclusive.
43+
*/
3044
private final boolean lowerInclusive;
45+
46+
/**
47+
* Whether the lower bound is considered inclusive.
48+
*/
3149
private final boolean upperInclusive;
3250

3351
/**
@@ -43,7 +61,8 @@ public Range(T lowerBound, T upperBound) {
4361
}
4462

4563
/**
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.
4766
*
4867
* @param lowerBound can be {@literal null}.
4968
* @param upperBound can be {@literal null}.
@@ -58,24 +77,6 @@ public Range(T lowerBound, T upperBound, boolean lowerInclusive, boolean upperIn
5877
this.upperInclusive = upperInclusive;
5978
}
6079

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-
7980
/**
8081
* Returns whether the {@link Range} contains the given value.
8182
*
@@ -86,10 +87,10 @@ public boolean contains(T value) {
8687

8788
Assert.notNull(value, "Reference value must not be null!");
8889

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;
9394

9495
return greaterThanLowerBound && lessThanUpperBound;
9596
}

0 commit comments

Comments
 (0)