Use Range class from spring-data-commons.

Original Pull Request #2137
Closes #2098
This commit is contained in:
Peter-Josef Meisch 2022-04-15 08:42:26 +02:00 committed by GitHub
parent 6a201b4e34
commit e1c926e134
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 15 additions and 10 deletions

View File

@ -25,7 +25,9 @@ import org.springframework.util.ObjectUtils;
* *
* @author Sascha Woo * @author Sascha Woo
* @since 4.3 * @since 4.3
* @deprecated use {org.springframework.data.domain.Range} instead.
*/ */
@Deprecated(since = "5.0", forRemoval = true)
public class Range<T> { public class Range<T> {
private final static Range<?> UNBOUNDED = Range.of(Bound.unbounded(), Bound.UNBOUNDED); private final static Range<?> UNBOUNDED = Range.of(Bound.unbounded(), Bound.UNBOUNDED);
@ -231,8 +233,8 @@ public class Range<T> {
} }
/** /**
* Value object representing a boundary. A boundary can either be {@link #unbounded() unbounded}, {@link #inclusive(Object)} * Value object representing a boundary. A boundary can either be {@link #unbounded() unbounded},
* including its value} or {@link #exclusive(Object)} its value}. * {@link #inclusive(Object)} including its value} or {@link #exclusive(Object)} its value}.
*/ */
public static final class Bound<T> { public static final class Bound<T> {

View File

@ -18,7 +18,7 @@ package org.springframework.data.elasticsearch.core.convert;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.Map; import java.util.Map;
import org.springframework.data.elasticsearch.core.Range; import org.springframework.data.domain.Range;
import org.springframework.data.mapping.PersistentProperty; import org.springframework.data.mapping.PersistentProperty;
import org.springframework.util.Assert; import org.springframework.util.Assert;
@ -44,6 +44,7 @@ public abstract class AbstractRangePropertyValueConverter<T> extends AbstractPro
Assert.isInstanceOf(Map.class, value, "value must be instance of Map."); Assert.isInstanceOf(Map.class, value, "value must be instance of Map.");
try { try {
// noinspection unchecked
Map<String, Object> source = (Map<String, Object>) value; Map<String, Object> source = (Map<String, Object>) value;
Range.Bound<T> lowerBound; Range.Bound<T> lowerBound;
Range.Bound<T> upperBound; Range.Bound<T> upperBound;
@ -82,12 +83,13 @@ public abstract class AbstractRangePropertyValueConverter<T> extends AbstractPro
} }
try { try {
// noinspection unchecked
Range<T> range = (Range<T>) value; Range<T> range = (Range<T>) value;
Range.Bound<T> lowerBound = range.getLowerBound(); Range.Bound<T> lowerBound = range.getLowerBound();
Range.Bound<T> upperBound = range.getUpperBound(); Range.Bound<T> upperBound = range.getUpperBound();
Map<String, Object> target = new LinkedHashMap<>(); Map<String, Object> target = new LinkedHashMap<>();
if (lowerBound.isBounded()) { if (lowerBound.getValue().isPresent()) {
String lowerBoundValue = format(lowerBound.getValue().get()); String lowerBoundValue = format(lowerBound.getValue().get());
if (lowerBound.isInclusive()) { if (lowerBound.isInclusive()) {
target.put(GTE_FIELD, lowerBoundValue); target.put(GTE_FIELD, lowerBoundValue);
@ -96,7 +98,7 @@ public abstract class AbstractRangePropertyValueConverter<T> extends AbstractPro
} }
} }
if (upperBound.isBounded()) { if (upperBound.getValue().isPresent()) {
String upperBoundValue = format(upperBound.getValue().get()); String upperBoundValue = format(upperBound.getValue().get());
if (upperBound.isInclusive()) { if (upperBound.isInclusive()) {
target.put(LTE_FIELD, upperBoundValue); target.put(LTE_FIELD, upperBoundValue);

View File

@ -24,6 +24,7 @@ import java.util.List;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.data.domain.Range;
import org.springframework.data.elasticsearch.annotations.DateFormat; import org.springframework.data.elasticsearch.annotations.DateFormat;
import org.springframework.data.elasticsearch.annotations.Field; import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType; import org.springframework.data.elasticsearch.annotations.FieldType;
@ -31,7 +32,6 @@ import org.springframework.data.elasticsearch.annotations.GeoPointField;
import org.springframework.data.elasticsearch.annotations.GeoShapeField; import org.springframework.data.elasticsearch.annotations.GeoShapeField;
import org.springframework.data.elasticsearch.annotations.MultiField; import org.springframework.data.elasticsearch.annotations.MultiField;
import org.springframework.data.elasticsearch.annotations.ValueConverter; import org.springframework.data.elasticsearch.annotations.ValueConverter;
import org.springframework.data.elasticsearch.core.Range;
import org.springframework.data.elasticsearch.core.convert.DatePropertyValueConverter; import org.springframework.data.elasticsearch.core.convert.DatePropertyValueConverter;
import org.springframework.data.elasticsearch.core.convert.DateRangePropertyValueConverter; import org.springframework.data.elasticsearch.core.convert.DateRangePropertyValueConverter;
import org.springframework.data.elasticsearch.core.convert.ElasticsearchDateConverter; import org.springframework.data.elasticsearch.core.convert.ElasticsearchDateConverter;

View File

@ -26,6 +26,7 @@ import org.junit.jupiter.api.Test;
* @author Sascha Woo * @author Sascha Woo
* @since 4.3 * @since 4.3
*/ */
@Deprecated(since = "5.0", forRemoval = true)
public class RangeUnitTests { public class RangeUnitTests {
@Test @Test

View File

@ -48,12 +48,12 @@ import org.springframework.data.annotation.Transient;
import org.springframework.data.annotation.TypeAlias; import org.springframework.data.annotation.TypeAlias;
import org.springframework.data.convert.ReadingConverter; import org.springframework.data.convert.ReadingConverter;
import org.springframework.data.convert.WritingConverter; import org.springframework.data.convert.WritingConverter;
import org.springframework.data.domain.Range;
import org.springframework.data.elasticsearch.annotations.DateFormat; import org.springframework.data.elasticsearch.annotations.DateFormat;
import org.springframework.data.elasticsearch.annotations.Field; import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType; import org.springframework.data.elasticsearch.annotations.FieldType;
import org.springframework.data.elasticsearch.annotations.GeoPointField; import org.springframework.data.elasticsearch.annotations.GeoPointField;
import org.springframework.data.elasticsearch.annotations.ValueConverter; import org.springframework.data.elasticsearch.annotations.ValueConverter;
import org.springframework.data.elasticsearch.core.Range;
import org.springframework.data.elasticsearch.core.document.Document; import org.springframework.data.elasticsearch.core.document.Document;
import org.springframework.data.elasticsearch.core.geo.GeoJsonEntity; import org.springframework.data.elasticsearch.core.geo.GeoJsonEntity;
import org.springframework.data.elasticsearch.core.geo.GeoJsonGeometryCollection; import org.springframework.data.elasticsearch.core.geo.GeoJsonGeometryCollection;

View File

@ -40,9 +40,9 @@ import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.data.annotation.Id; import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.Transient; import org.springframework.data.annotation.Transient;
import org.springframework.data.domain.Range;
import org.springframework.data.elasticsearch.annotations.*; import org.springframework.data.elasticsearch.annotations.*;
import org.springframework.data.elasticsearch.core.MappingContextBaseTests; import org.springframework.data.elasticsearch.core.MappingContextBaseTests;
import org.springframework.data.elasticsearch.core.Range;
import org.springframework.data.elasticsearch.core.geo.GeoPoint; import org.springframework.data.elasticsearch.core.geo.GeoPoint;
import org.springframework.data.elasticsearch.core.mapping.SimpleElasticsearchMappingContext; import org.springframework.data.elasticsearch.core.mapping.SimpleElasticsearchMappingContext;
import org.springframework.data.elasticsearch.core.query.SeqNoPrimaryTerm; import org.springframework.data.elasticsearch.core.query.SeqNoPrimaryTerm;
@ -167,7 +167,7 @@ public class MappingBuilderUnitTests extends MappingContextBaseTests {
" \"coerce\": true\n" + // " \"coerce\": true\n" + //
" }\n" + // " }\n" + //
" }\n" + // " }\n" + //
"}\n}"; // "}\n"; //
// when // when
String mapping; String mapping;