Skip to content

Commit e1c926e

Browse files
authored
Use Range class from spring-data-commons.
Original Pull Request #2137 Closes #2098
1 parent 6a201b4 commit e1c926e

File tree

6 files changed

+15
-10
lines changed

6 files changed

+15
-10
lines changed

src/main/java/org/springframework/data/elasticsearch/core/Range.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@
2525
*
2626
* @author Sascha Woo
2727
* @since 4.3
28+
* @deprecated use {org.springframework.data.domain.Range} instead.
2829
*/
30+
@Deprecated(since = "5.0", forRemoval = true)
2931
public class Range<T> {
3032

3133
private final static Range<?> UNBOUNDED = Range.of(Bound.unbounded(), Bound.UNBOUNDED);
@@ -58,7 +60,7 @@ public static <T> Range<T> closed(T from, T to) {
5860
* @param <T>
5961
* @param value must not be {@literal null}.
6062
* @return
61-
* @see Range#closed(Object, Object)
63+
* @see Range#closed(Object, Object)
6264
*/
6365
public static <T> Range<T> just(T value) {
6466
return Range.closed(value, value);
@@ -231,8 +233,8 @@ public String toString() {
231233
}
232234

233235
/**
234-
* Value object representing a boundary. A boundary can either be {@link #unbounded() unbounded}, {@link #inclusive(Object)}
235-
* including its value} or {@link #exclusive(Object)} its value}.
236+
* Value object representing a boundary. A boundary can either be {@link #unbounded() unbounded},
237+
* {@link #inclusive(Object)} including its value} or {@link #exclusive(Object)} its value}.
236238
*/
237239
public static final class Bound<T> {
238240

src/main/java/org/springframework/data/elasticsearch/core/convert/AbstractRangePropertyValueConverter.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import java.util.LinkedHashMap;
1919
import java.util.Map;
2020

21-
import org.springframework.data.elasticsearch.core.Range;
21+
import org.springframework.data.domain.Range;
2222
import org.springframework.data.mapping.PersistentProperty;
2323
import org.springframework.util.Assert;
2424

@@ -44,6 +44,7 @@ public Object read(Object value) {
4444
Assert.isInstanceOf(Map.class, value, "value must be instance of Map.");
4545

4646
try {
47+
// noinspection unchecked
4748
Map<String, Object> source = (Map<String, Object>) value;
4849
Range.Bound<T> lowerBound;
4950
Range.Bound<T> upperBound;
@@ -82,12 +83,13 @@ public Object write(Object value) {
8283
}
8384

8485
try {
86+
// noinspection unchecked
8587
Range<T> range = (Range<T>) value;
8688
Range.Bound<T> lowerBound = range.getLowerBound();
8789
Range.Bound<T> upperBound = range.getUpperBound();
8890
Map<String, Object> target = new LinkedHashMap<>();
8991

90-
if (lowerBound.isBounded()) {
92+
if (lowerBound.getValue().isPresent()) {
9193
String lowerBoundValue = format(lowerBound.getValue().get());
9294
if (lowerBound.isInclusive()) {
9395
target.put(GTE_FIELD, lowerBoundValue);
@@ -96,7 +98,7 @@ public Object write(Object value) {
9698
}
9799
}
98100

99-
if (upperBound.isBounded()) {
101+
if (upperBound.getValue().isPresent()) {
100102
String upperBoundValue = format(upperBound.getValue().get());
101103
if (upperBound.isInclusive()) {
102104
target.put(LTE_FIELD, upperBoundValue);

src/main/java/org/springframework/data/elasticsearch/core/mapping/SimpleElasticsearchPersistentProperty.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@
2424
import org.apache.commons.logging.Log;
2525
import org.apache.commons.logging.LogFactory;
2626
import org.springframework.beans.BeanUtils;
27+
import org.springframework.data.domain.Range;
2728
import org.springframework.data.elasticsearch.annotations.DateFormat;
2829
import org.springframework.data.elasticsearch.annotations.Field;
2930
import org.springframework.data.elasticsearch.annotations.FieldType;
3031
import org.springframework.data.elasticsearch.annotations.GeoPointField;
3132
import org.springframework.data.elasticsearch.annotations.GeoShapeField;
3233
import org.springframework.data.elasticsearch.annotations.MultiField;
3334
import org.springframework.data.elasticsearch.annotations.ValueConverter;
34-
import org.springframework.data.elasticsearch.core.Range;
3535
import org.springframework.data.elasticsearch.core.convert.DatePropertyValueConverter;
3636
import org.springframework.data.elasticsearch.core.convert.DateRangePropertyValueConverter;
3737
import org.springframework.data.elasticsearch.core.convert.ElasticsearchDateConverter;

src/test/java/org/springframework/data/elasticsearch/core/RangeUnitTests.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
* @author Sascha Woo
2727
* @since 4.3
2828
*/
29+
@Deprecated(since = "5.0", forRemoval = true)
2930
public class RangeUnitTests {
3031

3132
@Test

src/test/java/org/springframework/data/elasticsearch/core/convert/MappingElasticsearchConverterUnitTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,12 @@
4848
import org.springframework.data.annotation.TypeAlias;
4949
import org.springframework.data.convert.ReadingConverter;
5050
import org.springframework.data.convert.WritingConverter;
51+
import org.springframework.data.domain.Range;
5152
import org.springframework.data.elasticsearch.annotations.DateFormat;
5253
import org.springframework.data.elasticsearch.annotations.Field;
5354
import org.springframework.data.elasticsearch.annotations.FieldType;
5455
import org.springframework.data.elasticsearch.annotations.GeoPointField;
5556
import org.springframework.data.elasticsearch.annotations.ValueConverter;
56-
import org.springframework.data.elasticsearch.core.Range;
5757
import org.springframework.data.elasticsearch.core.document.Document;
5858
import org.springframework.data.elasticsearch.core.geo.GeoJsonEntity;
5959
import org.springframework.data.elasticsearch.core.geo.GeoJsonGeometryCollection;

src/test/java/org/springframework/data/elasticsearch/core/index/MappingBuilderUnitTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@
4040
import org.junit.jupiter.api.Test;
4141
import org.springframework.data.annotation.Id;
4242
import org.springframework.data.annotation.Transient;
43+
import org.springframework.data.domain.Range;
4344
import org.springframework.data.elasticsearch.annotations.*;
4445
import org.springframework.data.elasticsearch.core.MappingContextBaseTests;
45-
import org.springframework.data.elasticsearch.core.Range;
4646
import org.springframework.data.elasticsearch.core.geo.GeoPoint;
4747
import org.springframework.data.elasticsearch.core.mapping.SimpleElasticsearchMappingContext;
4848
import org.springframework.data.elasticsearch.core.query.SeqNoPrimaryTerm;
@@ -167,7 +167,7 @@ void shouldBuildMappingsForGeoTypes() throws JSONException {
167167
" \"coerce\": true\n" + //
168168
" }\n" + //
169169
" }\n" + //
170-
"}\n}"; //
170+
"}\n"; //
171171

172172
// when
173173
String mapping;

0 commit comments

Comments
 (0)