diff --git a/src/main/java/org/springframework/data/redis/connection/DefaultStringRedisConnection.java b/src/main/java/org/springframework/data/redis/connection/DefaultStringRedisConnection.java index 0d6f10d2f..79a59dcc6 100644 --- a/src/main/java/org/springframework/data/redis/connection/DefaultStringRedisConnection.java +++ b/src/main/java/org/springframework/data/redis/connection/DefaultStringRedisConnection.java @@ -53,6 +53,9 @@ import org.springframework.data.redis.core.Cursor; import org.springframework.data.redis.core.ScanOptions; import org.springframework.data.redis.core.types.Expiration; import org.springframework.data.redis.core.types.RedisClientInfo; +import org.springframework.data.redis.domain.geo.GeoReference; +import org.springframework.data.redis.domain.geo.GeoReference.GeoMemberReference; +import org.springframework.data.redis.domain.geo.GeoShape; import org.springframework.data.redis.serializer.RedisSerializer; import org.springframework.data.redis.serializer.StringRedisSerializer; import org.springframework.lang.Nullable; @@ -2122,9 +2125,9 @@ public class DefaultStringRedisConnection implements StringRedisConnection, Deco @SuppressWarnings("unchecked") private GeoReference serialize(GeoReference data) { - return data instanceof GeoReference.GeoSearchMemberReference + return data instanceof GeoReference.GeoMemberReference ? GeoReference - .fromMember(serializer.serialize(((GeoReference.GeoSearchMemberReference) data).getMember())) + .fromMember(serializer.serialize(((GeoMemberReference) data).getMember())) : (GeoReference) data; } diff --git a/src/main/java/org/springframework/data/redis/connection/DefaultedRedisConnection.java b/src/main/java/org/springframework/data/redis/connection/DefaultedRedisConnection.java index 27c823e71..5c232c7d2 100644 --- a/src/main/java/org/springframework/data/redis/connection/DefaultedRedisConnection.java +++ b/src/main/java/org/springframework/data/redis/connection/DefaultedRedisConnection.java @@ -44,6 +44,8 @@ import org.springframework.data.redis.core.Cursor; import org.springframework.data.redis.core.ScanOptions; import org.springframework.data.redis.core.types.Expiration; import org.springframework.data.redis.core.types.RedisClientInfo; +import org.springframework.data.redis.domain.geo.GeoReference; +import org.springframework.data.redis.domain.geo.GeoShape; import org.springframework.lang.Nullable; /** diff --git a/src/main/java/org/springframework/data/redis/connection/ReactiveGeoCommands.java b/src/main/java/org/springframework/data/redis/connection/ReactiveGeoCommands.java index 5cc385e90..5ef6c2818 100644 --- a/src/main/java/org/springframework/data/redis/connection/ReactiveGeoCommands.java +++ b/src/main/java/org/springframework/data/redis/connection/ReactiveGeoCommands.java @@ -17,6 +17,8 @@ package org.springframework.data.redis.connection; import static org.springframework.data.redis.connection.RedisGeoCommands.*; +import org.springframework.data.redis.domain.geo.GeoReference; +import org.springframework.data.redis.domain.geo.GeoShape; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; diff --git a/src/main/java/org/springframework/data/redis/connection/RedisGeoCommands.java b/src/main/java/org/springframework/data/redis/connection/RedisGeoCommands.java index f4176f7b6..796a143ac 100644 --- a/src/main/java/org/springframework/data/redis/connection/RedisGeoCommands.java +++ b/src/main/java/org/springframework/data/redis/connection/RedisGeoCommands.java @@ -21,6 +21,7 @@ import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.stream.Collectors; import org.springframework.data.domain.Sort.Direction; import org.springframework.data.geo.Circle; @@ -28,10 +29,10 @@ import org.springframework.data.geo.Distance; import org.springframework.data.geo.GeoResults; import org.springframework.data.geo.Metric; import org.springframework.data.geo.Point; -import org.springframework.data.geo.Shape; +import org.springframework.data.redis.domain.geo.GeoReference; +import org.springframework.data.redis.domain.geo.GeoShape; import org.springframework.lang.Nullable; import org.springframework.util.Assert; -import org.springframework.util.ObjectUtils; /** * Geo-specific Redis commands. @@ -251,139 +252,84 @@ public interface RedisGeoCommands { GeoSearchStoreCommandArgs args); /** - * Search predicate for {@code GEOSEARCH} and {@code GEOSEARCHSTORE} commands. + * Arguments to be used with {@link RedisGeoCommands}. * + * @author Christoph Strobl * @since 2.6 */ - interface GeoShape extends Shape { - - /** - * Create a shape used as predicate for geo queries from a {@link Distance radius} around the query center point. - * - * @param radius - * @return - */ - static GeoShape byRadius(Distance radius) { - return new RadiusShape(radius); - } - - /** - * Create a shape used as predicate for geo queries from a bounding box with specified by {@code width} and - * {@code height}. - * - * @param width must not be {@literal null}. - * @param height must not be {@literal null}. - * @param distanceUnit must not be {@literal null}. - * @return - */ - static GeoShape byBox(double width, double height, DistanceUnit distanceUnit) { - return byBox(new BoundingBox(width, height, distanceUnit)); - } - - /** - * Create a shape used as predicate for geo queries from a {@link BoundingBox}. - * - * @param boundingBox must not be {@literal null}. - * @return - */ - static GeoShape byBox(BoundingBox boundingBox) { - return new BoxShape(boundingBox); - } - - /** - * The metric used for this geo predicate. - * - * @return - */ - Metric getMetric(); - } - - /** - * Radius defined by {@link Distance}. - * - * @since 2.6 - */ - class RadiusShape implements GeoShape { - - private final Distance radius; - - public RadiusShape(Distance radius) { - - Assert.notNull(radius, "Distance must not be null"); - - this.radius = radius; - } - - public Distance getRadius() { - return radius; - } - - @Override - public Metric getMetric() { - return radius.getMetric(); - } - } - - /** - * Bounding box defined by width and height. - * - * @since 2.6 - */ - class BoxShape implements GeoShape { - - private final BoundingBox boundingBox; - - public BoxShape(BoundingBox boundingBox) { - - Assert.notNull(boundingBox, "BoundingBox must not be null"); - - this.boundingBox = boundingBox; - } - - public BoundingBox getBoundingBox() { - return boundingBox; - } - - @Override - public Metric getMetric() { - return boundingBox.getHeight().getMetric(); - } - } - interface GeoCommandArgs { + /** + * @return can be {@literal null}. + */ @Nullable public Direction getSortDirection(); + /** + * @return can be {@literal null}. + */ @Nullable Long getLimit(); + /** + * @return never {@literal null}. + */ Set getFlags(); + /** + * @return {@literal true} if {@literal limit} has been set. + */ default boolean hasLimit() { return getLimit() != null; } + /** + * @return {@literal true} if {@literal sort} has been set. + */ default boolean hasSortDirection() { return getSortDirection() != null; } + /** + * @return {@literal true} if {@literal flags} is not empty. + */ default boolean hasFlags() { return !getFlags().isEmpty(); } - public interface GeoCommandFlag {} + /** + * A flag to be used. + */ + interface GeoCommandFlag { + + static GeoCommandFlag any() { + return Flag.ANY; + } + + static GeoCommandFlag withCord() { + return Flag.WITHCOORD; + } + + static GeoCommandFlag withDist() { + return Flag.WITHDIST; + } + + static GeoCommandFlag storeDist() { + return Flag.STOREDIST; + } + } } /** * Additional arguments (like count/sort/...) to be used with {@link RedisGeoCommands}. * * @author Mark Paluch + * @author Christoph Strobl * @since 2.6 */ class GeoSearchCommandArgs implements GeoCommandArgs, Cloneable { - protected final Set flags = new LinkedHashSet<>(2, 1); + protected final Set flags = new LinkedHashSet<>(2, 1); @Nullable protected Long limit; @@ -407,7 +353,7 @@ public interface RedisGeoCommands { */ public GeoSearchCommandArgs includeCoordinates() { - flags.add(Flag.WITHCOORD); + flags.add(GeoCommandFlag.withCord()); return this; } @@ -418,7 +364,7 @@ public interface RedisGeoCommands { */ public GeoSearchCommandArgs includeDistance() { - flags.add(Flag.WITHDIST); + flags.add(GeoCommandFlag.withDist()); return this; } @@ -475,7 +421,7 @@ public interface RedisGeoCommands { Assert.isTrue(count > 0, "Count has to positive value."); limit = count; if (any) { - flags.add(Flag.ANY); + flags.add(GeoCommandFlag.any()); } return this; } @@ -483,7 +429,7 @@ public interface RedisGeoCommands { /** * @return never {@literal null}. */ - public Set getFlags() { + public Set getFlags() { return flags; } @@ -504,7 +450,7 @@ public interface RedisGeoCommands { } public boolean hasAnyLimit() { - return hasLimit() && flags.contains(Flag.ANY); + return hasLimit() && flags.contains(GeoCommandFlag.any()); } @Override @@ -526,7 +472,7 @@ public interface RedisGeoCommands { */ class GeoSearchStoreCommandArgs implements GeoCommandArgs, Cloneable { - private final Set flags = new LinkedHashSet<>(2, 1); + private final Set flags = new LinkedHashSet<>(2, 1); @Nullable private Long limit; @@ -607,7 +553,7 @@ public interface RedisGeoCommands { Assert.isTrue(count > 0, "Count has to positive value."); this.limit = count; if (any) { - flags.add(Flag.ANY); + flags.add(GeoCommandFlag.any()); } return this; } @@ -615,7 +561,7 @@ public interface RedisGeoCommands { /** * @return never {@literal null}. */ - public Set getFlags() { + public Set getFlags() { return flags; } @@ -636,11 +582,11 @@ public interface RedisGeoCommands { } public boolean isStoreDistance() { - return flags.contains(Flag.STOREDIST); + return flags.contains(GeoCommandFlag.storeDist()); } public boolean hasAnyLimit() { - return hasLimit() && flags.contains(Flag.ANY); + return hasLimit() && flags.contains(GeoCommandFlag.any()); } @Override @@ -736,6 +682,10 @@ public interface RedisGeoCommands { return this; } + public Set getFlags() { + return flags.stream().map(it -> (Flag) it).collect(Collectors.toSet()); + } + public enum Flag implements GeoCommandFlag { WITHCOORD, WITHDIST, ANY, STOREDIST } @@ -751,193 +701,6 @@ public interface RedisGeoCommands { } } - /** - * Reference point for {@code GEOSEARCH} and {@code GEOSEARCHSTORE} commands. Provides factory methods to create - * {@link GeoReference} from geo-set members or reference points. - * - * @param - * @since 2.6 - */ - class GeoReference { - - /** - * Creates a {@link GeoReference} from a geoset member. - * - * @param member must not be {@literal null}. - * @param - * @return - */ - public static GeoReference fromMember(T member) { - - Assert.notNull(member, "Geoset member must not be null"); - - return new GeoSearchMemberReference<>(member); - } - - /** - * Creates a {@link GeoReference} from a {@link GeoLocation geoset member}. - * - * @param member must not be {@literal null}. - * @param - * @return - */ - public static GeoReference fromMember(GeoLocation member) { - - Assert.notNull(member, "GeoLocation must not be null"); - - return new GeoSearchMemberReference<>(member.getName()); - } - - /** - * Creates a {@link GeoReference} from a {@link Circle#getCenter() circle center point} . - * - * @param within must not be {@literal null}. - * @param - * @return - */ - public static GeoReference fromCircle(Circle within) { - - Assert.notNull(within, "Circle must not be null"); - - return fromCoordinate(within.getCenter()); - } - - /** - * Creates a {@link GeoReference} from a WGS84 longitude/latitude coordinate. - * - * @param longitude - * @param latitude - * @param - * @return - */ - public static GeoReference fromCoordinate(double longitude, double latitude) { - return new GeoSearchCoordinateReference<>(longitude, latitude); - } - - /** - * Creates a {@link GeoReference} from a WGS84 longitude/latitude coordinate. - * - * @param location must not be {@literal null}. - * @param - * @return - */ - public static GeoReference fromCoordinate(GeoLocation location) { - - Assert.notNull(location, "GeoLocation must not be null"); - Assert.notNull(location.getPoint(), "GeoLocation point must not be null"); - - return fromCoordinate(location.getPoint()); - } - - /** - * Creates a {@link GeoReference} from a WGS84 longitude/latitude coordinate. - * - * @param point must not be {@literal null}. - * @param - * @return - */ - public static GeoReference fromCoordinate(Point point) { - - Assert.notNull(point, "Reference point must not be null"); - - return fromCoordinate(point.getX(), point.getY()); - } - - public static class GeoSearchMemberReference extends GeoReference { - - private final T member; - - public GeoSearchMemberReference(T member) { - this.member = member; - } - - public T getMember() { - return member; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (!(o instanceof GeoSearchMemberReference)) { - return false; - } - GeoSearchMemberReference that = (GeoSearchMemberReference) o; - return ObjectUtils.nullSafeEquals(member, that.member); - } - - @Override - public int hashCode() { - return ObjectUtils.nullSafeHashCode(member); - } - - @Override - public String toString() { - final StringBuffer sb = new StringBuffer(); - sb.append(getClass().getSimpleName()); - sb.append(" [member=").append(member); - sb.append(']'); - return sb.toString(); - } - } - - public static class GeoSearchCoordinateReference extends GeoReference { - - private final double longitude; - private final double latitude; - - public GeoSearchCoordinateReference(double longitude, double latitude) { - this.longitude = longitude; - this.latitude = latitude; - } - - public double getLongitude() { - return longitude; - } - - public double getLatitude() { - return latitude; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (!(o instanceof GeoSearchCoordinateReference)) { - return false; - } - GeoSearchCoordinateReference that = (GeoSearchCoordinateReference) o; - if (longitude != that.longitude) { - return false; - } - return latitude == that.latitude; - } - - @Override - public int hashCode() { - int result; - long temp; - temp = Double.doubleToLongBits(longitude); - result = (int) (temp ^ (temp >>> 32)); - temp = Double.doubleToLongBits(latitude); - result = 31 * result + (int) (temp ^ (temp >>> 32)); - return result; - } - - @Override - public String toString() { - final StringBuffer sb = new StringBuffer(); - sb.append(getClass().getSimpleName()); - sb.append(" [").append(longitude); - sb.append(",").append(latitude); - sb.append(']'); - return sb.toString(); - } - } - } - /** * {@link GeoLocation} representing a {@link Point} associated with a {@literal name}. * @@ -945,53 +708,10 @@ public interface RedisGeoCommands { * @param * @since 1.8 */ - class GeoLocation { - - private final T name; - private final Point point; + class GeoLocation extends org.springframework.data.redis.domain.geo.GeoLocation { public GeoLocation(T name, Point point) { - this.name = name; - this.point = point; - } - - public T getName() { - return this.name; - } - - public Point getPoint() { - return this.point; - } - - @Override - public boolean equals(Object o) { - - if (this == o) { - return true; - } - - if (!(o instanceof GeoLocation)) { - return false; - } - - GeoLocation that = (GeoLocation) o; - - if (!ObjectUtils.nullSafeEquals(name, that.name)) { - return false; - } - - return ObjectUtils.nullSafeEquals(point, that.point); - } - - @Override - public int hashCode() { - int result = ObjectUtils.nullSafeHashCode(name); - result = 31 * result + ObjectUtils.nullSafeHashCode(point); - return result; - } - - protected boolean canEqual(Object other) { - return other instanceof GeoLocation; + super(name, point); } public String toString() { @@ -1040,100 +760,4 @@ public interface RedisGeoCommands { return abbreviation; } } - - /** - * Represents a geospatial bounding box defined by width and height. - * - * @author Mark Paluch - * @since 2.6 - */ - class BoundingBox implements Shape { - - private static final long serialVersionUID = 5215611530535947924L; - - private final Distance width; - private final Distance height; - - /** - * Creates a new {@link BoundingBox} from the given width and height. Both distances must use the same - * {@link Metric}. - * - * @param width must not be {@literal null}. - * @param height must not be {@literal null}. - */ - public BoundingBox(Distance width, Distance height) { - - Assert.notNull(width, "Width must not be null!"); - Assert.notNull(height, "Height must not be null!"); - Assert.isTrue(width.getMetric().equals(height.getMetric()), "Metric for width and height must be the same!"); - - this.width = width; - this.height = height; - } - - /** - * Creates a new {@link BoundingBox} from the given width, height and {@link Metric}. - * - * @param width - * @param height - * @param metric must not be {@literal null}. - */ - public BoundingBox(double width, double height, Metric metric) { - this(new Distance(width, metric), new Distance(height, metric)); - } - - /** - * Returns the width of this bounding box. - * - * @return will never be {@literal null}. - */ - public Distance getWidth() { - return height; - } - - /** - * Returns the height of this bounding box. - * - * @return will never be {@literal null}. - */ - public Distance getHeight() { - return height; - } - - /* - * (non-Javadoc) - * @see java.lang.Object#hashCode() - */ - @Override - public int hashCode() { - int result = ObjectUtils.nullSafeHashCode(width); - result = 31 * result + ObjectUtils.nullSafeHashCode(height); - return result; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (!(o instanceof BoundingBox)) { - return false; - } - BoundingBox that = (BoundingBox) o; - if (!ObjectUtils.nullSafeEquals(width, that.width)) { - return false; - } - return ObjectUtils.nullSafeEquals(height, that.height); - } - - /* - * (non-Javadoc) - * @see java.lang.Object#toString() - */ - @Override - public String toString() { - return String.format("Bounding box: [width=%s, height=%s]", width, height); - } - } - } diff --git a/src/main/java/org/springframework/data/redis/connection/StringRedisConnection.java b/src/main/java/org/springframework/data/redis/connection/StringRedisConnection.java index d9f6cb12e..d4640e886 100644 --- a/src/main/java/org/springframework/data/redis/connection/StringRedisConnection.java +++ b/src/main/java/org/springframework/data/redis/connection/StringRedisConnection.java @@ -47,6 +47,8 @@ import org.springframework.data.redis.core.ScanOptions; import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.data.redis.core.types.Expiration; import org.springframework.data.redis.core.types.RedisClientInfo; +import org.springframework.data.redis.domain.geo.GeoReference; +import org.springframework.data.redis.domain.geo.GeoShape; import org.springframework.data.redis.serializer.RedisSerializer; import org.springframework.lang.Nullable; import org.springframework.util.CollectionUtils; @@ -2428,7 +2430,7 @@ public interface StringRedisConnection extends RedisConnection { /** * Return the members of a geo set which are within the borders of the area specified by a given {@link GeoShape * shape}. The query's center point is provided by - * {@link org.springframework.data.redis.connection.RedisGeoCommands.GeoReference}. + * {@link GeoReference}. * * @param key must not be {@literal null}. * @param reference must not be {@literal null}. @@ -2445,7 +2447,7 @@ public interface StringRedisConnection extends RedisConnection { /** * Query the members of a geo set which are within the borders of the area specified by a given {@link GeoShape shape} * and store the result at {@code destKey}. The query's center point is provided by - * {@link org.springframework.data.redis.connection.RedisGeoCommands.GeoReference}. + * {@link GeoReference}. * * @param key must not be {@literal null}. * @param reference must not be {@literal null}. diff --git a/src/main/java/org/springframework/data/redis/connection/jedis/JedisClusterGeoCommands.java b/src/main/java/org/springframework/data/redis/connection/jedis/JedisClusterGeoCommands.java index 1902ace60..8ee7a8132 100644 --- a/src/main/java/org/springframework/data/redis/connection/jedis/JedisClusterGeoCommands.java +++ b/src/main/java/org/springframework/data/redis/connection/jedis/JedisClusterGeoCommands.java @@ -30,6 +30,8 @@ import org.springframework.data.geo.GeoResults; import org.springframework.data.geo.Metric; import org.springframework.data.geo.Point; import org.springframework.data.redis.connection.RedisGeoCommands; +import org.springframework.data.redis.domain.geo.GeoReference; +import org.springframework.data.redis.domain.geo.GeoShape; import org.springframework.util.Assert; /** diff --git a/src/main/java/org/springframework/data/redis/connection/jedis/JedisGeoCommands.java b/src/main/java/org/springframework/data/redis/connection/jedis/JedisGeoCommands.java index 0e4d3ed8c..f5cb4ca4b 100644 --- a/src/main/java/org/springframework/data/redis/connection/jedis/JedisGeoCommands.java +++ b/src/main/java/org/springframework/data/redis/connection/jedis/JedisGeoCommands.java @@ -15,6 +15,8 @@ */ package org.springframework.data.redis.connection.jedis; +import org.springframework.data.redis.domain.geo.GeoReference; +import org.springframework.data.redis.domain.geo.GeoShape; import redis.clients.jedis.BinaryJedis; import redis.clients.jedis.GeoCoordinate; import redis.clients.jedis.GeoUnit; diff --git a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConverters.java b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConverters.java index c92dd653c..d0ef93f88 100644 --- a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConverters.java +++ b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConverters.java @@ -16,7 +16,7 @@ package org.springframework.data.redis.connection.lettuce; import static org.springframework.data.redis.connection.RedisGeoCommands.*; -import static org.springframework.data.redis.connection.RedisGeoCommands.GeoReference.*; +import static org.springframework.data.redis.domain.geo.GeoReference.*; import io.lettuce.core.*; import io.lettuce.core.cluster.models.partitions.Partitions; @@ -30,7 +30,6 @@ import java.util.stream.Collectors; import org.springframework.core.convert.converter.Converter; import org.springframework.dao.DataAccessException; -import org.springframework.data.domain.Sort; import org.springframework.data.geo.Distance; import org.springframework.data.geo.GeoResult; import org.springframework.data.geo.GeoResults; @@ -61,6 +60,11 @@ import org.springframework.data.redis.core.KeyScanOptions; import org.springframework.data.redis.core.ScanOptions; import org.springframework.data.redis.core.types.Expiration; import org.springframework.data.redis.core.types.RedisClientInfo; +import org.springframework.data.redis.domain.geo.BoundingBox; +import org.springframework.data.redis.domain.geo.BoxShape; +import org.springframework.data.redis.domain.geo.GeoReference; +import org.springframework.data.redis.domain.geo.GeoShape; +import org.springframework.data.redis.domain.geo.RadiusShape; import org.springframework.data.redis.util.ByteUtils; import org.springframework.lang.Nullable; import org.springframework.util.Assert; @@ -1147,13 +1151,13 @@ public abstract class LettuceConverters extends Converters { static GeoSearch.GeoRef toGeoRef(GeoReference reference) { - if (reference instanceof GeoSearchMemberReference) { - return GeoSearch.fromMember(((GeoSearchMemberReference) reference).getMember()); + if (reference instanceof GeoReference.GeoMemberReference) { + return GeoSearch.fromMember(((GeoMemberReference) reference).getMember()); } - if (reference instanceof GeoSearchCoordinateReference) { + if (reference instanceof GeoReference.GeoCoordinateReference) { - GeoSearchCoordinateReference coordinates = (GeoSearchCoordinateReference) reference; + GeoCoordinateReference coordinates = (GeoCoordinateReference) reference; return GeoSearch.fromCoordinates(coordinates.getLongitude(), coordinates.getLatitude()); } diff --git a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceGeoCommands.java b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceGeoCommands.java index 4acaf2438..d86074ba8 100644 --- a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceGeoCommands.java +++ b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceGeoCommands.java @@ -34,6 +34,8 @@ import org.springframework.data.geo.GeoResults; import org.springframework.data.geo.Metric; import org.springframework.data.geo.Point; import org.springframework.data.redis.connection.RedisGeoCommands; +import org.springframework.data.redis.domain.geo.GeoReference; +import org.springframework.data.redis.domain.geo.GeoShape; import org.springframework.lang.Nullable; import org.springframework.util.Assert; diff --git a/src/main/java/org/springframework/data/redis/core/BoundGeoOperations.java b/src/main/java/org/springframework/data/redis/core/BoundGeoOperations.java index 202e2618d..9e308d62d 100644 --- a/src/main/java/org/springframework/data/redis/core/BoundGeoOperations.java +++ b/src/main/java/org/springframework/data/redis/core/BoundGeoOperations.java @@ -25,7 +25,9 @@ import org.springframework.data.geo.Distance; import org.springframework.data.geo.GeoResults; import org.springframework.data.geo.Metric; import org.springframework.data.geo.Point; -import org.springframework.data.redis.connection.RedisGeoCommands; +import org.springframework.data.redis.domain.geo.BoundingBox; +import org.springframework.data.redis.domain.geo.GeoReference; +import org.springframework.data.redis.domain.geo.GeoShape; import org.springframework.lang.Nullable; /** @@ -437,7 +439,7 @@ public interface BoundGeoOperations extends BoundKeyOperations { * @see Redis Documentation: GEOSEARCH */ @Nullable - default GeoResults> search(RedisGeoCommands.GeoReference reference, Distance radius) { + default GeoResults> search(GeoReference reference, Distance radius) { return search(reference, radius, GeoSearchCommandArgs.newGeoSearchArgs()); } @@ -453,7 +455,7 @@ public interface BoundGeoOperations extends BoundKeyOperations { * @see Redis Documentation: GEOSEARCH */ @Nullable - default GeoResults> search(RedisGeoCommands.GeoReference reference, Distance radius, + default GeoResults> search(GeoReference reference, Distance radius, GeoSearchCommandArgs args) { return search(reference, GeoShape.byRadius(radius), args); } @@ -469,7 +471,7 @@ public interface BoundGeoOperations extends BoundKeyOperations { * @see Redis Documentation: GEOSEARCH */ @Nullable - default GeoResults> search(RedisGeoCommands.GeoReference reference, BoundingBox boundingBox) { + default GeoResults> search(GeoReference reference, BoundingBox boundingBox) { return search(reference, boundingBox, GeoSearchCommandArgs.newGeoSearchArgs()); } @@ -485,7 +487,7 @@ public interface BoundGeoOperations extends BoundKeyOperations { * @see Redis Documentation: GEOSEARCH */ @Nullable - default GeoResults> search(RedisGeoCommands.GeoReference reference, BoundingBox boundingBox, + default GeoResults> search(GeoReference reference, BoundingBox boundingBox, GeoSearchCommandArgs args) { return search(reference, GeoShape.byBox(boundingBox), args); } @@ -502,7 +504,7 @@ public interface BoundGeoOperations extends BoundKeyOperations { * @see Redis Documentation: GEOSEARCH */ @Nullable - GeoResults> search(RedisGeoCommands.GeoReference reference, GeoShape geoPredicate, + GeoResults> search(GeoReference reference, GeoShape geoPredicate, GeoSearchCommandArgs args); /** @@ -530,7 +532,7 @@ public interface BoundGeoOperations extends BoundKeyOperations { * @see Redis Documentation: GEOSEARCHSTORE */ @Nullable - default Long searchAndStore(K destKey, RedisGeoCommands.GeoReference reference, Distance radius) { + default Long searchAndStore(K destKey, GeoReference reference, Distance radius) { return searchAndStore(destKey, reference, radius, GeoSearchStoreCommandArgs.newGeoSearchStoreArgs()); } @@ -546,7 +548,7 @@ public interface BoundGeoOperations extends BoundKeyOperations { * @see Redis Documentation: GEOSEARCHSTORE */ @Nullable - default Long searchAndStore(K destKey, RedisGeoCommands.GeoReference reference, Distance radius, + default Long searchAndStore(K destKey, GeoReference reference, Distance radius, GeoSearchStoreCommandArgs args) { return searchAndStore(destKey, reference, GeoShape.byRadius(radius), args); } @@ -562,7 +564,7 @@ public interface BoundGeoOperations extends BoundKeyOperations { * @see Redis Documentation: GEOSEARCHSTORE */ @Nullable - default Long searchAndStore(K destKey, RedisGeoCommands.GeoReference reference, BoundingBox boundingBox) { + default Long searchAndStore(K destKey, GeoReference reference, BoundingBox boundingBox) { return searchAndStore(destKey, reference, boundingBox, GeoSearchStoreCommandArgs.newGeoSearchStoreArgs()); } @@ -578,7 +580,7 @@ public interface BoundGeoOperations extends BoundKeyOperations { * @see Redis Documentation: GEOSEARCHSTORE */ @Nullable - default Long searchAndStore(K destKey, RedisGeoCommands.GeoReference reference, BoundingBox boundingBox, + default Long searchAndStore(K destKey, GeoReference reference, BoundingBox boundingBox, GeoSearchStoreCommandArgs args) { return searchAndStore(destKey, reference, GeoShape.byBox(boundingBox), args); } @@ -595,7 +597,7 @@ public interface BoundGeoOperations extends BoundKeyOperations { * @see Redis Documentation: GEOSEARCHSTORE */ @Nullable - Long searchAndStore(K destKey, RedisGeoCommands.GeoReference reference, GeoShape geoPredicate, + Long searchAndStore(K destKey, GeoReference reference, GeoShape geoPredicate, GeoSearchStoreCommandArgs args); } diff --git a/src/main/java/org/springframework/data/redis/core/DefaultBoundGeoOperations.java b/src/main/java/org/springframework/data/redis/core/DefaultBoundGeoOperations.java index 92533dd83..a528f7d0e 100644 --- a/src/main/java/org/springframework/data/redis/core/DefaultBoundGeoOperations.java +++ b/src/main/java/org/springframework/data/redis/core/DefaultBoundGeoOperations.java @@ -27,6 +27,8 @@ import org.springframework.data.redis.connection.DataType; import org.springframework.data.redis.connection.RedisGeoCommands; import org.springframework.data.redis.connection.RedisGeoCommands.GeoLocation; import org.springframework.data.redis.connection.RedisGeoCommands.GeoRadiusCommandArgs; +import org.springframework.data.redis.domain.geo.GeoReference; +import org.springframework.data.redis.domain.geo.GeoShape; /** * Default implementation of {@link BoundGeoOperations}. @@ -183,8 +185,8 @@ class DefaultBoundGeoOperations extends DefaultBoundKeyOperations imple * @see org.springframework.data.redis.core.BoundGeoOperations#search(org.springframework.data.redis.connection.RedisGeoCommands.GeoReference, org.springframework.data.redis.connection.RedisGeoCommands.GeoShape, org.springframework.data.redis.connection.RedisGeoCommands.GeoSearchCommandArgs) */ @Override - public GeoResults> search(RedisGeoCommands.GeoReference reference, - RedisGeoCommands.GeoShape geoPredicate, RedisGeoCommands.GeoSearchCommandArgs args) { + public GeoResults> search(GeoReference reference, + GeoShape geoPredicate, RedisGeoCommands.GeoSearchCommandArgs args) { return ops.search(getKey(), reference, geoPredicate, args); } @@ -193,8 +195,8 @@ class DefaultBoundGeoOperations extends DefaultBoundKeyOperations imple * @see org.springframework.data.redis.core.BoundGeoOperations#searchAndStore(java.lang.Object, org.springframework.data.redis.connection.RedisGeoCommands.GeoReference, org.springframework.data.redis.connection.RedisGeoCommands.GeoShape, org.springframework.data.redis.connection.RedisGeoCommands.GeoSearchStoreCommandArgs) */ @Override - public Long searchAndStore(K destKey, RedisGeoCommands.GeoReference reference, - RedisGeoCommands.GeoShape geoPredicate, RedisGeoCommands.GeoSearchStoreCommandArgs args) { + public Long searchAndStore(K destKey, GeoReference reference, + GeoShape geoPredicate, RedisGeoCommands.GeoSearchStoreCommandArgs args) { return ops.searchAndStore(getKey(), destKey, reference, geoPredicate, args); } diff --git a/src/main/java/org/springframework/data/redis/core/DefaultGeoOperations.java b/src/main/java/org/springframework/data/redis/core/DefaultGeoOperations.java index edd71a95b..deb2009d9 100644 --- a/src/main/java/org/springframework/data/redis/core/DefaultGeoOperations.java +++ b/src/main/java/org/springframework/data/redis/core/DefaultGeoOperations.java @@ -28,6 +28,9 @@ import org.springframework.data.geo.Point; import org.springframework.data.redis.connection.RedisGeoCommands; import org.springframework.data.redis.connection.RedisGeoCommands.GeoLocation; import org.springframework.data.redis.connection.RedisGeoCommands.GeoRadiusCommandArgs; +import org.springframework.data.redis.domain.geo.GeoReference; +import org.springframework.data.redis.domain.geo.GeoReference.GeoMemberReference; +import org.springframework.data.redis.domain.geo.GeoShape; /** * Default implementation of {@link GeoOperations}. @@ -248,11 +251,11 @@ class DefaultGeoOperations extends AbstractOperations implements Geo * @see org.springframework.data.redis.core.GeoOperations#search(java.lang.Object, org.springframework.data.redis.connection.RedisGeoCommands.GeoReference, org.springframework.data.redis.connection.RedisGeoCommands.GeoShape, org.springframework.data.redis.connection.RedisGeoCommands.GeoSearchCommandArgs) */ @Override - public GeoResults> search(K key, RedisGeoCommands.GeoReference reference, - RedisGeoCommands.GeoShape geoPredicate, RedisGeoCommands.GeoSearchCommandArgs args) { + public GeoResults> search(K key, GeoReference reference, + GeoShape geoPredicate, RedisGeoCommands.GeoSearchCommandArgs args) { byte[] rawKey = rawKey(key); - RedisGeoCommands.GeoReference rawMember = getGeoReference(reference); + GeoReference rawMember = getGeoReference(reference); GeoResults> raw = execute( connection -> connection.geoSearch(rawKey, rawMember, geoPredicate, args), true); @@ -265,21 +268,21 @@ class DefaultGeoOperations extends AbstractOperations implements Geo * @see org.springframework.data.redis.core.GeoOperations#searchAndStore(java.lang.Object, java.lang.Object, org.springframework.data.redis.connection.RedisGeoCommands.GeoReference, org.springframework.data.redis.connection.RedisGeoCommands.GeoShape, org.springframework.data.redis.connection.RedisGeoCommands.GeoSearchStoreCommandArgs) */ @Override - public Long searchAndStore(K key, K destKey, RedisGeoCommands.GeoReference reference, - RedisGeoCommands.GeoShape geoPredicate, RedisGeoCommands.GeoSearchStoreCommandArgs args) { + public Long searchAndStore(K key, K destKey, GeoReference reference, + GeoShape geoPredicate, RedisGeoCommands.GeoSearchStoreCommandArgs args) { byte[] rawKey = rawKey(key); byte[] rawDestKey = rawKey(destKey); - RedisGeoCommands.GeoReference rawMember = getGeoReference(reference); + GeoReference rawMember = getGeoReference(reference); return execute(connection -> connection.geoSearchStore(rawDestKey, rawKey, rawMember, geoPredicate, args), true); } @SuppressWarnings("unchecked") - private RedisGeoCommands.GeoReference getGeoReference(RedisGeoCommands.GeoReference reference) { - return reference instanceof RedisGeoCommands.GeoReference.GeoSearchMemberReference - ? RedisGeoCommands.GeoReference - .fromMember(rawValue(((RedisGeoCommands.GeoReference.GeoSearchMemberReference) reference).getMember())) - : (RedisGeoCommands.GeoReference) reference; + private GeoReference getGeoReference(GeoReference reference) { + return reference instanceof GeoReference.GeoMemberReference + ? GeoReference + .fromMember(rawValue(((GeoMemberReference) reference).getMember())) + : (GeoReference) reference; } } diff --git a/src/main/java/org/springframework/data/redis/core/DefaultReactiveGeoOperations.java b/src/main/java/org/springframework/data/redis/core/DefaultReactiveGeoOperations.java index 51eb04896..4131a5230 100644 --- a/src/main/java/org/springframework/data/redis/core/DefaultReactiveGeoOperations.java +++ b/src/main/java/org/springframework/data/redis/core/DefaultReactiveGeoOperations.java @@ -15,6 +15,8 @@ */ package org.springframework.data.redis.core; +import org.springframework.data.redis.domain.geo.GeoReference; +import org.springframework.data.redis.domain.geo.GeoReference.GeoMemberReference; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -35,6 +37,7 @@ import org.springframework.data.redis.connection.ReactiveGeoCommands; import org.springframework.data.redis.connection.RedisGeoCommands; import org.springframework.data.redis.connection.RedisGeoCommands.GeoLocation; import org.springframework.data.redis.connection.RedisGeoCommands.GeoRadiusCommandArgs; +import org.springframework.data.redis.domain.geo.GeoShape; import org.springframework.data.redis.serializer.RedisSerializationContext; import org.springframework.util.Assert; @@ -340,12 +343,12 @@ class DefaultReactiveGeoOperations implements ReactiveGeoOperations * @see org.springframework.data.redis.core.ReactiveGeoOperations#search(K, RedisGeoCommands.GeoReference, GeoShape, GeoSearchCommandArgs) */ @Override - public Flux>> search(K key, RedisGeoCommands.GeoReference reference, - RedisGeoCommands.GeoShape geoPredicate, RedisGeoCommands.GeoSearchCommandArgs args) { + public Flux>> search(K key, GeoReference reference, + GeoShape geoPredicate, RedisGeoCommands.GeoSearchCommandArgs args) { Assert.notNull(key, "Key must not be null!"); Assert.notNull(reference, "GeoReference must not be null!"); - RedisGeoCommands.GeoReference rawReference = getGeoReference(reference); + GeoReference rawReference = getGeoReference(reference); return template.createFlux(connection -> connection.geoCommands() .geoSearch(rawKey(key), rawReference, geoPredicate, args).map(this::readGeoResult)); @@ -356,12 +359,12 @@ class DefaultReactiveGeoOperations implements ReactiveGeoOperations * @see org.springframework.data.redis.core.ReactiveGeoOperations#searchAndStore(K, K, RedisGeoCommands.GeoReference, GeoShape, GeoSearchStoreCommandArgs) */ @Override - public Mono searchAndStore(K key, K destKey, RedisGeoCommands.GeoReference reference, - RedisGeoCommands.GeoShape geoPredicate, RedisGeoCommands.GeoSearchStoreCommandArgs args) { + public Mono searchAndStore(K key, K destKey, GeoReference reference, + GeoShape geoPredicate, RedisGeoCommands.GeoSearchStoreCommandArgs args) { Assert.notNull(key, "Key must not be null!"); Assert.notNull(reference, "GeoReference must not be null!"); - RedisGeoCommands.GeoReference rawReference = getGeoReference(reference); + GeoReference rawReference = getGeoReference(reference); return template.createMono(connection -> connection.geoCommands().geoSearchStore(rawKey(destKey), rawKey(key), rawReference, geoPredicate, args)); @@ -382,11 +385,11 @@ class DefaultReactiveGeoOperations implements ReactiveGeoOperations } @SuppressWarnings("unchecked") - private RedisGeoCommands.GeoReference getGeoReference(RedisGeoCommands.GeoReference reference) { - return reference instanceof RedisGeoCommands.GeoReference.GeoSearchMemberReference - ? RedisGeoCommands.GeoReference - .fromMember(rawValue(((RedisGeoCommands.GeoReference.GeoSearchMemberReference) reference).getMember())) - : (RedisGeoCommands.GeoReference) reference; + private GeoReference getGeoReference(GeoReference reference) { + return reference instanceof GeoReference.GeoMemberReference + ? GeoReference + .fromMember(rawValue(((GeoMemberReference) reference).getMember())) + : (GeoReference) reference; } private ByteBuffer rawKey(K key) { diff --git a/src/main/java/org/springframework/data/redis/core/GeoOperations.java b/src/main/java/org/springframework/data/redis/core/GeoOperations.java index 2f51b0872..a1315e1b7 100644 --- a/src/main/java/org/springframework/data/redis/core/GeoOperations.java +++ b/src/main/java/org/springframework/data/redis/core/GeoOperations.java @@ -15,8 +15,6 @@ */ package org.springframework.data.redis.core; -import static org.springframework.data.redis.connection.RedisGeoCommands.*; - import java.util.List; import java.util.Map; @@ -25,8 +23,13 @@ import org.springframework.data.geo.Distance; import org.springframework.data.geo.GeoResults; import org.springframework.data.geo.Metric; import org.springframework.data.geo.Point; -import org.springframework.data.redis.connection.RedisGeoCommands; -import org.springframework.data.redis.connection.RedisGeoCommands.*; +import org.springframework.data.redis.connection.RedisGeoCommands.GeoLocation; +import org.springframework.data.redis.connection.RedisGeoCommands.GeoRadiusCommandArgs; +import org.springframework.data.redis.connection.RedisGeoCommands.GeoSearchCommandArgs; +import org.springframework.data.redis.connection.RedisGeoCommands.GeoSearchStoreCommandArgs; +import org.springframework.data.redis.domain.geo.BoundingBox; +import org.springframework.data.redis.domain.geo.GeoReference; +import org.springframework.data.redis.domain.geo.GeoShape; import org.springframework.lang.Nullable; /** @@ -467,7 +470,7 @@ public interface GeoOperations { * @see Redis Documentation: GEOSEARCH */ @Nullable - default GeoResults> search(K key, RedisGeoCommands.GeoReference reference, Distance radius) { + default GeoResults> search(K key, GeoReference reference, Distance radius) { return search(key, reference, radius, GeoSearchCommandArgs.newGeoSearchArgs()); } @@ -484,7 +487,7 @@ public interface GeoOperations { * @see Redis Documentation: GEOSEARCH */ @Nullable - default GeoResults> search(K key, RedisGeoCommands.GeoReference reference, Distance radius, + default GeoResults> search(K key, GeoReference reference, Distance radius, GeoSearchCommandArgs args) { return search(key, reference, GeoShape.byRadius(radius), args); } @@ -501,7 +504,7 @@ public interface GeoOperations { * @see Redis Documentation: GEOSEARCH */ @Nullable - default GeoResults> search(K key, RedisGeoCommands.GeoReference reference, + default GeoResults> search(K key, GeoReference reference, BoundingBox boundingBox) { return search(key, reference, boundingBox, GeoSearchCommandArgs.newGeoSearchArgs()); } @@ -519,7 +522,7 @@ public interface GeoOperations { * @see Redis Documentation: GEOSEARCH */ @Nullable - default GeoResults> search(K key, RedisGeoCommands.GeoReference reference, BoundingBox boundingBox, + default GeoResults> search(K key, GeoReference reference, BoundingBox boundingBox, GeoSearchCommandArgs args) { return search(key, reference, GeoShape.byBox(boundingBox), args); } @@ -537,7 +540,7 @@ public interface GeoOperations { * @see Redis Documentation: GEOSEARCH */ @Nullable - GeoResults> search(K key, RedisGeoCommands.GeoReference reference, + GeoResults> search(K key, GeoReference reference, GeoShape geoPredicate, GeoSearchCommandArgs args); /** @@ -567,7 +570,7 @@ public interface GeoOperations { * @see Redis Documentation: GEOSEARCHSTORE */ @Nullable - default Long searchAndStore(K key, K destKey, RedisGeoCommands.GeoReference reference, Distance radius) { + default Long searchAndStore(K key, K destKey, GeoReference reference, Distance radius) { return searchAndStore(key, destKey, reference, radius, GeoSearchStoreCommandArgs.newGeoSearchStoreArgs()); } @@ -584,7 +587,7 @@ public interface GeoOperations { * @see Redis Documentation: GEOSEARCHSTORE */ @Nullable - default Long searchAndStore(K key, K destKey, RedisGeoCommands.GeoReference reference, Distance radius, + default Long searchAndStore(K key, K destKey, GeoReference reference, Distance radius, GeoSearchStoreCommandArgs args) { return searchAndStore(key, destKey, reference, GeoShape.byRadius(radius), args); } @@ -601,7 +604,7 @@ public interface GeoOperations { * @see Redis Documentation: GEOSEARCHSTORE */ @Nullable - default Long searchAndStore(K key, K destKey, RedisGeoCommands.GeoReference reference, BoundingBox boundingBox) { + default Long searchAndStore(K key, K destKey, GeoReference reference, BoundingBox boundingBox) { return searchAndStore(key, destKey, reference, boundingBox, GeoSearchStoreCommandArgs.newGeoSearchStoreArgs()); } @@ -618,7 +621,7 @@ public interface GeoOperations { * @see Redis Documentation: GEOSEARCHSTORE */ @Nullable - default Long searchAndStore(K key, K destKey, RedisGeoCommands.GeoReference reference, BoundingBox boundingBox, + default Long searchAndStore(K key, K destKey, GeoReference reference, BoundingBox boundingBox, GeoSearchStoreCommandArgs args) { return searchAndStore(key, destKey, reference, GeoShape.byBox(boundingBox), args); } @@ -636,7 +639,7 @@ public interface GeoOperations { * @see Redis Documentation: GEOSEARCHSTORE */ @Nullable - Long searchAndStore(K key, K destKey, RedisGeoCommands.GeoReference reference, GeoShape geoPredicate, + Long searchAndStore(K key, K destKey, GeoReference reference, GeoShape geoPredicate, GeoSearchStoreCommandArgs args); } diff --git a/src/main/java/org/springframework/data/redis/core/ReactiveGeoOperations.java b/src/main/java/org/springframework/data/redis/core/ReactiveGeoOperations.java index cfba328bd..17c64f88a 100644 --- a/src/main/java/org/springframework/data/redis/core/ReactiveGeoOperations.java +++ b/src/main/java/org/springframework/data/redis/core/ReactiveGeoOperations.java @@ -25,13 +25,14 @@ import java.util.List; import java.util.Map; import org.reactivestreams.Publisher; - import org.springframework.data.geo.Circle; import org.springframework.data.geo.Distance; import org.springframework.data.geo.GeoResult; import org.springframework.data.geo.Metric; import org.springframework.data.geo.Point; -import org.springframework.data.redis.connection.RedisGeoCommands; +import org.springframework.data.redis.domain.geo.BoundingBox; +import org.springframework.data.redis.domain.geo.GeoReference; +import org.springframework.data.redis.domain.geo.GeoShape; /** * Reactive Redis operations for geo commands. @@ -256,7 +257,7 @@ public interface ReactiveGeoOperations { * @since 2.6 * @see Redis Documentation: GEOSEARCH */ - default Flux>> search(K key, RedisGeoCommands.GeoReference reference, Distance radius) { + default Flux>> search(K key, GeoReference reference, Distance radius) { return search(key, reference, radius, GeoSearchCommandArgs.newGeoSearchArgs()); } @@ -272,7 +273,7 @@ public interface ReactiveGeoOperations { * @since 2.6 * @see Redis Documentation: GEOSEARCH */ - default Flux>> search(K key, RedisGeoCommands.GeoReference reference, Distance radius, + default Flux>> search(K key, GeoReference reference, Distance radius, GeoSearchCommandArgs args) { return search(key, reference, GeoShape.byRadius(radius), args); } @@ -288,7 +289,7 @@ public interface ReactiveGeoOperations { * @since 2.6 * @see Redis Documentation: GEOSEARCH */ - default Flux>> search(K key, RedisGeoCommands.GeoReference reference, + default Flux>> search(K key, GeoReference reference, BoundingBox boundingBox) { return search(key, reference, boundingBox, GeoSearchCommandArgs.newGeoSearchArgs()); } @@ -305,7 +306,7 @@ public interface ReactiveGeoOperations { * @since 2.6 * @see Redis Documentation: GEOSEARCH */ - default Flux>> search(K key, RedisGeoCommands.GeoReference reference, + default Flux>> search(K key, GeoReference reference, BoundingBox boundingBox, GeoSearchCommandArgs args) { return search(key, reference, GeoShape.byBox(boundingBox), args); } @@ -322,7 +323,7 @@ public interface ReactiveGeoOperations { * @since 2.6 * @see Redis Documentation: GEOSEARCH */ - Flux>> search(K key, RedisGeoCommands.GeoReference reference, GeoShape geoPredicate, + Flux>> search(K key, GeoReference reference, GeoShape geoPredicate, GeoSearchCommandArgs args); /** @@ -350,7 +351,7 @@ public interface ReactiveGeoOperations { * @since 2.6 * @see Redis Documentation: GEOSEARCHSTORE */ - default Mono searchAndStore(K key, K destKey, RedisGeoCommands.GeoReference reference, Distance radius) { + default Mono searchAndStore(K key, K destKey, GeoReference reference, Distance radius) { return searchAndStore(key, destKey, reference, radius, GeoSearchStoreCommandArgs.newGeoSearchStoreArgs()); } @@ -366,7 +367,7 @@ public interface ReactiveGeoOperations { * @since 2.6 * @see Redis Documentation: GEOSEARCHSTORE */ - default Mono searchAndStore(K key, K destKey, RedisGeoCommands.GeoReference reference, Distance radius, + default Mono searchAndStore(K key, K destKey, GeoReference reference, Distance radius, GeoSearchStoreCommandArgs args) { return searchAndStore(key, destKey, reference, GeoShape.byRadius(radius), args); } @@ -382,7 +383,7 @@ public interface ReactiveGeoOperations { * @since 2.6 * @see Redis Documentation: GEOSEARCHSTORE */ - default Mono searchAndStore(K key, K destKey, RedisGeoCommands.GeoReference reference, + default Mono searchAndStore(K key, K destKey, GeoReference reference, BoundingBox boundingBox) { return searchAndStore(key, destKey, reference, boundingBox, GeoSearchStoreCommandArgs.newGeoSearchStoreArgs()); } @@ -399,7 +400,7 @@ public interface ReactiveGeoOperations { * @since 2.6 * @see Redis Documentation: GEOSEARCHSTORE */ - default Mono searchAndStore(K key, K destKey, RedisGeoCommands.GeoReference reference, + default Mono searchAndStore(K key, K destKey, GeoReference reference, BoundingBox boundingBox, GeoSearchStoreCommandArgs args) { return searchAndStore(key, destKey, reference, GeoShape.byBox(boundingBox), args); } @@ -416,7 +417,7 @@ public interface ReactiveGeoOperations { * @since 2.6 * @see Redis Documentation: GEOSEARCHSTORE */ - Mono searchAndStore(K key, K destKey, RedisGeoCommands.GeoReference reference, GeoShape geoPredicate, + Mono searchAndStore(K key, K destKey, GeoReference reference, GeoShape geoPredicate, GeoSearchStoreCommandArgs args); } diff --git a/src/main/java/org/springframework/data/redis/domain/geo/BoundingBox.java b/src/main/java/org/springframework/data/redis/domain/geo/BoundingBox.java new file mode 100644 index 000000000..9c8690f32 --- /dev/null +++ b/src/main/java/org/springframework/data/redis/domain/geo/BoundingBox.java @@ -0,0 +1,118 @@ +/* + * Copyright 2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.redis.domain.geo; + +import org.springframework.data.geo.Distance; +import org.springframework.data.geo.Metric; +import org.springframework.data.geo.Shape; +import org.springframework.data.redis.connection.RedisGeoCommands; +import org.springframework.util.Assert; +import org.springframework.util.ObjectUtils; + +/** + * Represents a geospatial bounding box defined by width and height. + * + * @author Mark Paluch + * @since 2.6 + */ +public class BoundingBox implements Shape { + + private static final long serialVersionUID = 5215611530535947924L; + + private final Distance width; + private final Distance height; + + /** + * Creates a new {@link BoundingBox} from the given width and height. Both distances must use the same + * {@link Metric}. + * + * @param width must not be {@literal null}. + * @param height must not be {@literal null}. + */ + public BoundingBox(Distance width, Distance height) { + + Assert.notNull(width, "Width must not be null!"); + Assert.notNull(height, "Height must not be null!"); + Assert.isTrue(width.getMetric().equals(height.getMetric()), "Metric for width and height must be the same!"); + + this.width = width; + this.height = height; + } + + /** + * Creates a new {@link BoundingBox} from the given width, height and {@link Metric}. + * + * @param width + * @param height + * @param metric must not be {@literal null}. + */ + public BoundingBox(double width, double height, Metric metric) { + this(new Distance(width, metric), new Distance(height, metric)); + } + + /** + * Returns the width of this bounding box. + * + * @return will never be {@literal null}. + */ + public Distance getWidth() { + return height; + } + + /** + * Returns the height of this bounding box. + * + * @return will never be {@literal null}. + */ + public Distance getHeight() { + return height; + } + + /* + * (non-Javadoc) + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + int result = ObjectUtils.nullSafeHashCode(width); + result = 31 * result + ObjectUtils.nullSafeHashCode(height); + return result; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof BoundingBox)) { + return false; + } + BoundingBox that = (BoundingBox) o; + if (!ObjectUtils.nullSafeEquals(width, that.width)) { + return false; + } + return ObjectUtils.nullSafeEquals(height, that.height); + } + + /* + * (non-Javadoc) + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + return String.format("Bounding box: [width=%s, height=%s]", width, height); + } +} diff --git a/src/main/java/org/springframework/data/redis/domain/geo/BoxShape.java b/src/main/java/org/springframework/data/redis/domain/geo/BoxShape.java new file mode 100644 index 000000000..e40c6ecc4 --- /dev/null +++ b/src/main/java/org/springframework/data/redis/domain/geo/BoxShape.java @@ -0,0 +1,47 @@ +/* + * Copyright 2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.redis.domain.geo; + +import org.springframework.data.geo.Metric; +import org.springframework.util.Assert; + +/** + * Bounding box defined by width and height. + * + * @author Mark Paluch + * @since 2.6 + * + */ +public class BoxShape implements GeoShape { + + private final BoundingBox boundingBox; + + public BoxShape(BoundingBox boundingBox) { + + Assert.notNull(boundingBox, "BoundingBox must not be null"); + + this.boundingBox = boundingBox; + } + + public BoundingBox getBoundingBox() { + return boundingBox; + } + + @Override + public Metric getMetric() { + return boundingBox.getHeight().getMetric(); + } +} diff --git a/src/main/java/org/springframework/data/redis/domain/geo/GeoLocation.java b/src/main/java/org/springframework/data/redis/domain/geo/GeoLocation.java new file mode 100644 index 000000000..59606a3bb --- /dev/null +++ b/src/main/java/org/springframework/data/redis/domain/geo/GeoLocation.java @@ -0,0 +1,74 @@ +/* + * Copyright 2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.redis.domain.geo; + +import org.springframework.data.geo.Point; +import org.springframework.data.redis.connection.RedisGeoCommands; +import org.springframework.util.ObjectUtils; + +/** + * @author Christoph Strobl + * @since 2.6 + */ +public class GeoLocation { + + private final T name; + private final Point point; + + public GeoLocation(T name, Point point) { + this.name = name; + this.point = point; + } + + public T getName() { + return this.name; + } + + public Point getPoint() { + return this.point; + } + + @Override + public boolean equals(Object o) { + + if (this == o) { + return true; + } + + if (!(o instanceof GeoLocation)) { + return false; + } + + GeoLocation that = (GeoLocation) o; + + if (!ObjectUtils.nullSafeEquals(name, that.name)) { + return false; + } + + return ObjectUtils.nullSafeEquals(point, that.point); + } + + @Override + public int hashCode() { + int result = ObjectUtils.nullSafeHashCode(name); + result = 31 * result + ObjectUtils.nullSafeHashCode(point); + return result; + } + + public String toString() { + return "GeoLocation(name=" + this.getName() + ", point=" + this.getPoint() + ")"; + } +} diff --git a/src/main/java/org/springframework/data/redis/domain/geo/GeoReference.java b/src/main/java/org/springframework/data/redis/domain/geo/GeoReference.java new file mode 100644 index 000000000..1423da1d3 --- /dev/null +++ b/src/main/java/org/springframework/data/redis/domain/geo/GeoReference.java @@ -0,0 +1,211 @@ +/* + * Copyright 2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.redis.domain.geo; + +import org.springframework.data.geo.Circle; +import org.springframework.data.geo.Point; +import org.springframework.data.redis.connection.RedisGeoCommands; +import org.springframework.util.Assert; +import org.springframework.util.ObjectUtils; + +/** + * Reference point for {@code GEOSEARCH} and {@code GEOSEARCHSTORE} commands. Provides factory methods to create + * {@link GeoReference} from geo-set members or reference points. + * + * @param + * @author Mark Paluch + * @author Christoph Strobl + * @since 2.6 + */ +public interface GeoReference { + + /** + * Creates a {@link GeoReference} from a geoset member. + * + * @param member must not be {@literal null}. + * @param + * @return + */ + static GeoReference fromMember(T member) { + + Assert.notNull(member, "Geoset member must not be null"); + + return new GeoMemberReference<>(member); + } + + /** + * Creates a {@link GeoReference} from a {@link RedisGeoCommands.GeoLocation geoset member}. + * + * @param member must not be {@literal null}. + * @param + * @return + */ + static GeoReference fromMember(RedisGeoCommands.GeoLocation member) { + + Assert.notNull(member, "GeoLocation must not be null"); + + return new GeoMemberReference<>(member.getName()); + } + + /** + * Creates a {@link GeoReference} from a {@link Circle#getCenter() circle center point} . + * + * @param within must not be {@literal null}. + * @param + * @return + */ + static GeoReference fromCircle(Circle within) { + + Assert.notNull(within, "Circle must not be null"); + + return fromCoordinate(within.getCenter()); + } + + /** + * Creates a {@link GeoReference} from a WGS84 longitude/latitude coordinate. + * + * @param longitude + * @param latitude + * @param + * @return + */ + static GeoReference fromCoordinate(double longitude, double latitude) { + return new GeoCoordinateReference<>(longitude, latitude); + } + + /** + * Creates a {@link GeoReference} from a WGS84 longitude/latitude coordinate. + * + * @param location must not be {@literal null}. + * @param + * @return + */ + static GeoReference fromCoordinate(RedisGeoCommands.GeoLocation location) { + + Assert.notNull(location, "GeoLocation must not be null"); + Assert.notNull(location.getPoint(), "GeoLocation point must not be null"); + + return fromCoordinate(location.getPoint()); + } + + /** + * Creates a {@link GeoReference} from a WGS84 longitude/latitude coordinate. + * + * @param point must not be {@literal null}. + * @param + * @return + */ + static GeoReference fromCoordinate(Point point) { + + Assert.notNull(point, "Reference point must not be null"); + + return fromCoordinate(point.getX(), point.getY()); + } + + class GeoMemberReference implements GeoReference { + + private final T member; + + public GeoMemberReference(T member) { + this.member = member; + } + + public T getMember() { + return member; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof GeoReference.GeoMemberReference)) { + return false; + } + GeoMemberReference that = (GeoMemberReference) o; + return ObjectUtils.nullSafeEquals(member, that.member); + } + + @Override + public int hashCode() { + return ObjectUtils.nullSafeHashCode(member); + } + + @Override + public String toString() { + final StringBuffer sb = new StringBuffer(); + sb.append(getClass().getSimpleName()); + sb.append(" [member=").append(member); + sb.append(']'); + return sb.toString(); + } + } + + class GeoCoordinateReference implements GeoReference { + + private final double longitude; + private final double latitude; + + public GeoCoordinateReference(double longitude, double latitude) { + this.longitude = longitude; + this.latitude = latitude; + } + + public double getLongitude() { + return longitude; + } + + public double getLatitude() { + return latitude; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof GeoReference.GeoCoordinateReference)) { + return false; + } + GeoCoordinateReference that = (GeoCoordinateReference) o; + if (longitude != that.longitude) { + return false; + } + return latitude == that.latitude; + } + + @Override + public int hashCode() { + int result; + long temp; + temp = Double.doubleToLongBits(longitude); + result = (int) (temp ^ (temp >>> 32)); + temp = Double.doubleToLongBits(latitude); + result = 31 * result + (int) (temp ^ (temp >>> 32)); + return result; + } + + @Override + public String toString() { + final StringBuffer sb = new StringBuffer(); + sb.append(getClass().getSimpleName()); + sb.append(" [").append(longitude); + sb.append(",").append(latitude); + sb.append(']'); + return sb.toString(); + } + } +} diff --git a/src/main/java/org/springframework/data/redis/domain/geo/GeoShape.java b/src/main/java/org/springframework/data/redis/domain/geo/GeoShape.java new file mode 100644 index 000000000..d31e7a894 --- /dev/null +++ b/src/main/java/org/springframework/data/redis/domain/geo/GeoShape.java @@ -0,0 +1,70 @@ +/* + * Copyright 2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.redis.domain.geo; + +import org.springframework.data.geo.Distance; +import org.springframework.data.geo.Metric; +import org.springframework.data.geo.Shape; +import org.springframework.data.redis.connection.RedisGeoCommands; +import org.springframework.data.redis.connection.RedisGeoCommands.DistanceUnit; + +/** + * Search predicate for {@code GEOSEARCH} and {@code GEOSEARCHSTORE} commands. + * + * @since 2.6 + */ +public interface GeoShape extends Shape { + + /** + * Create a shape used as predicate for geo queries from a {@link Distance radius} around the query center point. + * + * @param radius + * @return + */ + static GeoShape byRadius(Distance radius) { + return new RadiusShape(radius); + } + + /** + * Create a shape used as predicate for geo queries from a bounding box with specified by {@code width} and + * {@code height}. + * + * @param width must not be {@literal null}. + * @param height must not be {@literal null}. + * @param distanceUnit must not be {@literal null}. + * @return + */ + static GeoShape byBox(double width, double height, DistanceUnit distanceUnit) { + return byBox(new BoundingBox(width, height, distanceUnit)); + } + + /** + * Create a shape used as predicate for geo queries from a {@link BoundingBox}. + * + * @param boundingBox must not be {@literal null}. + * @return + */ + static GeoShape byBox(BoundingBox boundingBox) { + return new BoxShape(boundingBox); + } + + /** + * The metric used for this geo predicate. + * + * @return + */ + Metric getMetric(); +} diff --git a/src/main/java/org/springframework/data/redis/domain/geo/Metrics.java b/src/main/java/org/springframework/data/redis/domain/geo/Metrics.java new file mode 100644 index 000000000..1fe9cc90e --- /dev/null +++ b/src/main/java/org/springframework/data/redis/domain/geo/Metrics.java @@ -0,0 +1,61 @@ +/* + * Copyright 2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.redis.domain.geo; + +import org.springframework.data.geo.Metric; +import org.springframework.data.redis.connection.RedisGeoCommands; + +/** + * {@link Metric}s supported by Redis. + * + * @author Christoph Strobl + * @since 2.6 + */ +public enum Metrics implements Metric { + + METERS(6378137, "m"), KILOMETERS(6378.137, "km"), MILES(3963.191, "mi"), FEET(20925646.325, "ft"); + + private final double multiplier; + private final String abbreviation; + + /** + * Creates a new {@link RedisGeoCommands.DistanceUnit} using the given muliplier. + * + * @param multiplier the earth radius at equator. + */ + Metrics(double multiplier, String abbreviation) { + + this.multiplier = multiplier; + this.abbreviation = abbreviation; + } + + /* + * (non-Javadoc) + * @see org.springframework.data.geo.Metric#getMultiplier() + */ + public double getMultiplier() { + return multiplier; + } + + /* + * (non-Javadoc) + * @see org.springframework.data.geo.Metric#getAbbreviation() + */ + @Override + public String getAbbreviation() { + return abbreviation; + } +} diff --git a/src/main/java/org/springframework/data/redis/domain/geo/RadiusShape.java b/src/main/java/org/springframework/data/redis/domain/geo/RadiusShape.java new file mode 100644 index 000000000..da5884698 --- /dev/null +++ b/src/main/java/org/springframework/data/redis/domain/geo/RadiusShape.java @@ -0,0 +1,47 @@ +/* + * Copyright 2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.redis.domain.geo; + +import org.springframework.data.geo.Distance; +import org.springframework.data.geo.Metric; +import org.springframework.util.Assert; + +/** + * Radius defined by {@link Distance}. + * + * @author Mark Paluch + * @since 2.6 + */ +public class RadiusShape implements GeoShape { + + private final Distance radius; + + public RadiusShape(Distance radius) { + + Assert.notNull(radius, "Distance must not be null"); + + this.radius = radius; + } + + public Distance getRadius() { + return radius; + } + + @Override + public Metric getMetric() { + return radius.getMetric(); + } +} diff --git a/src/test/java/org/springframework/data/redis/connection/AbstractConnectionIntegrationTests.java b/src/test/java/org/springframework/data/redis/connection/AbstractConnectionIntegrationTests.java index 8d1e58e4f..cc542172e 100644 --- a/src/test/java/org/springframework/data/redis/connection/AbstractConnectionIntegrationTests.java +++ b/src/test/java/org/springframework/data/redis/connection/AbstractConnectionIntegrationTests.java @@ -81,6 +81,8 @@ import org.springframework.data.redis.core.ScanOptions; import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.data.redis.core.types.Expiration; import org.springframework.data.redis.core.types.RedisClientInfo; +import org.springframework.data.redis.domain.geo.GeoReference; +import org.springframework.data.redis.domain.geo.GeoShape; import org.springframework.data.redis.serializer.RedisSerializer; import org.springframework.data.redis.test.condition.EnabledOnCommand; import org.springframework.data.redis.test.condition.EnabledOnRedisDriver; @@ -3292,8 +3294,8 @@ public abstract class AbstractConnectionIntegrationTests { String key = "geo-" + UUID.randomUUID(); actual.add(connection.geoAdd(key, Arrays.asList(ARIGENTO, CATANIA, PALERMO))); - actual.add(connection.geoSearch(key, RedisGeoCommands.GeoReference.fromMember(PALERMO), - RedisGeoCommands.GeoShape.byRadius(new Distance(200, KILOMETERS)), newGeoSearchArgs().limit(2))); + actual.add(connection.geoSearch(key, GeoReference.fromMember(PALERMO), + GeoShape.byRadius(new Distance(200, KILOMETERS)), newGeoSearchArgs().limit(2))); List results = getResults(); List>> content = ((GeoResults>) results.get(1)).getContent(); @@ -3310,8 +3312,8 @@ public abstract class AbstractConnectionIntegrationTests { String key = "geo-" + UUID.randomUUID(); actual.add(connection.geoAdd(key, Arrays.asList(ARIGENTO, CATANIA, PALERMO))); - actual.add(connection.geoSearch(key, RedisGeoCommands.GeoReference.fromCoordinate(PALERMO), - RedisGeoCommands.GeoShape.byRadius(new Distance(200, KILOMETERS)), newGeoSearchArgs().limit(2))); + actual.add(connection.geoSearch(key, GeoReference.fromCoordinate(PALERMO), + GeoShape.byRadius(new Distance(200, KILOMETERS)), newGeoSearchArgs().limit(2))); List results = getResults(); List>> content = ((GeoResults>) results.get(1)).getContent(); @@ -3329,8 +3331,8 @@ public abstract class AbstractConnectionIntegrationTests { actual.add(connection.geoAdd(key, Arrays.asList(ARIGENTO, CATANIA, PALERMO))); actual.add( - connection.geoSearch(key, RedisGeoCommands.GeoReference.fromMember(PALERMO), - RedisGeoCommands.GeoShape.byRadius(new Distance(200, KILOMETERS)), + connection.geoSearch(key, GeoReference.fromMember(PALERMO), + GeoShape.byRadius(new Distance(200, KILOMETERS)), newGeoSearchArgs().limit(2).includeDistance().includeCoordinates())); List results = getResults(); @@ -3348,8 +3350,8 @@ public abstract class AbstractConnectionIntegrationTests { String key = "geo-" + UUID.randomUUID(); actual.add(connection.geoAdd(key, Arrays.asList(ARIGENTO, CATANIA, PALERMO))); - actual.add(connection.geoSearchStore("georesults", key, RedisGeoCommands.GeoReference.fromMember(PALERMO), - RedisGeoCommands.GeoShape.byRadius(new Distance(200, KILOMETERS)), + actual.add(connection.geoSearchStore("georesults", key, GeoReference.fromMember(PALERMO), + GeoShape.byRadius(new Distance(200, KILOMETERS)), newGeoSearchStoreArgs().limit(2).storeDistance())); actual.add(connection.zScore("georesults", PALERMO.getName())); actual.add(connection.zScore("georesults", ARIGENTO.getName())); @@ -3368,8 +3370,8 @@ public abstract class AbstractConnectionIntegrationTests { String key = "geo-" + UUID.randomUUID(); actual.add(connection.geoAdd(key, Arrays.asList(ARIGENTO, CATANIA, PALERMO))); - actual.add(connection.geoSearchStore("georesults", key, RedisGeoCommands.GeoReference.fromCoordinate(PALERMO), - RedisGeoCommands.GeoShape.byRadius(new Distance(200, KILOMETERS)), + actual.add(connection.geoSearchStore("georesults", key, GeoReference.fromCoordinate(PALERMO), + GeoShape.byRadius(new Distance(200, KILOMETERS)), newGeoSearchStoreArgs().limit(2).storeDistance())); actual.add(connection.zScore("georesults", PALERMO.getName())); actual.add(connection.zScore("georesults", ARIGENTO.getName())); diff --git a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveGeoCommandsIntegrationTests.java b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveGeoCommandsIntegrationTests.java index 376a70576..b43e44e1e 100644 --- a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveGeoCommandsIntegrationTests.java +++ b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveGeoCommandsIntegrationTests.java @@ -32,6 +32,8 @@ import org.springframework.data.geo.Circle; import org.springframework.data.geo.Distance; import org.springframework.data.geo.Metrics; import org.springframework.data.geo.Point; +import org.springframework.data.redis.domain.geo.GeoReference; +import org.springframework.data.redis.domain.geo.GeoShape; import org.springframework.data.redis.test.condition.EnabledOnCommand; import org.springframework.data.redis.test.extension.parametrized.ParameterizedRedisTest; diff --git a/src/test/java/org/springframework/data/redis/core/DefaultGeoOperationsIntegrationTests.java b/src/test/java/org/springframework/data/redis/core/DefaultGeoOperationsIntegrationTests.java index c365df0d3..4c9705f92 100644 --- a/src/test/java/org/springframework/data/redis/core/DefaultGeoOperationsIntegrationTests.java +++ b/src/test/java/org/springframework/data/redis/core/DefaultGeoOperationsIntegrationTests.java @@ -37,6 +37,8 @@ import org.springframework.data.redis.connection.RedisGeoCommands; import org.springframework.data.redis.connection.RedisGeoCommands.DistanceUnit; import org.springframework.data.redis.connection.RedisGeoCommands.GeoLocation; import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; +import org.springframework.data.redis.domain.geo.BoundingBox; +import org.springframework.data.redis.domain.geo.GeoReference; import org.springframework.data.redis.test.condition.EnabledOnCommand; import org.springframework.data.redis.test.extension.parametrized.MethodSource; import org.springframework.data.redis.test.extension.parametrized.ParameterizedRedisTest; @@ -449,7 +451,7 @@ public class DefaultGeoOperationsIntegrationTests { geoOperations.add(key, POINT_ARIGENTO, member3); GeoResults> result = geoOperations.search(key, - RedisGeoCommands.GeoReference.fromCoordinate(POINT_PALERMO), new Distance(150, KILOMETERS), + GeoReference.fromCoordinate(POINT_PALERMO), new Distance(150, KILOMETERS), newGeoSearchArgs().includeCoordinates().sortAscending()); assertThat(result.getContent()).hasSize(2); @@ -479,7 +481,7 @@ public class DefaultGeoOperationsIntegrationTests { geoOperations.add(key, POINT_CATANIA, member2); geoOperations.add(key, POINT_ARIGENTO, member3); - GeoResults> result = geoOperations.search(key, RedisGeoCommands.GeoReference.fromMember(member1), + GeoResults> result = geoOperations.search(key, GeoReference.fromMember(member1), new Distance(150, KILOMETERS), newGeoSearchArgs().includeCoordinates().sortAscending()); @@ -511,8 +513,8 @@ public class DefaultGeoOperationsIntegrationTests { geoOperations.add(key, POINT_ARIGENTO, member3); GeoResults> result = geoOperations.search(key, - RedisGeoCommands.GeoReference.fromCoordinate(POINT_PALERMO), - new RedisGeoCommands.BoundingBox(180, 180, KILOMETERS), + GeoReference.fromCoordinate(POINT_PALERMO), + new BoundingBox(180, 180, KILOMETERS), newGeoSearchArgs().includeCoordinates().sortAscending()); assertThat(result.getContent()).hasSize(2); @@ -542,8 +544,8 @@ public class DefaultGeoOperationsIntegrationTests { geoOperations.add(key, POINT_CATANIA, member2); geoOperations.add(key, POINT_ARIGENTO, member3); - GeoResults> result = geoOperations.search(key, RedisGeoCommands.GeoReference.fromMember(member1), - new RedisGeoCommands.BoundingBox(180, 180, KILOMETERS), + GeoResults> result = geoOperations.search(key, GeoReference.fromMember(member1), + new BoundingBox(180, 180, KILOMETERS), newGeoSearchArgs().includeCoordinates().sortAscending()); assertThat(result.getContent()).hasSize(2); @@ -575,7 +577,7 @@ public class DefaultGeoOperationsIntegrationTests { geoOperations.add(key, POINT_ARIGENTO, member3); Long result = geoOperations.searchAndStore(key, destKey, - RedisGeoCommands.GeoReference.fromCoordinate(POINT_PALERMO), new Distance(150, KILOMETERS), + GeoReference.fromCoordinate(POINT_PALERMO), new Distance(150, KILOMETERS), RedisGeoCommands.GeoSearchStoreCommandArgs.newGeoSearchStoreArgs().sortAscending()); assertThat(result).isEqualTo(2); diff --git a/src/test/java/org/springframework/data/redis/core/DefaultReactiveGeoOperationsIntegrationTests.java b/src/test/java/org/springframework/data/redis/core/DefaultReactiveGeoOperationsIntegrationTests.java index 78f0128b1..f6001fda0 100644 --- a/src/test/java/org/springframework/data/redis/core/DefaultReactiveGeoOperationsIntegrationTests.java +++ b/src/test/java/org/springframework/data/redis/core/DefaultReactiveGeoOperationsIntegrationTests.java @@ -20,6 +20,7 @@ import static org.springframework.data.redis.connection.RedisGeoCommands.*; import static org.springframework.data.redis.connection.RedisGeoCommands.DistanceUnit.*; import static org.springframework.data.redis.connection.RedisGeoCommands.GeoRadiusCommandArgs.*; +import org.springframework.data.redis.domain.geo.GeoReference; import reactor.core.publisher.Flux; import reactor.test.StepVerifier; @@ -30,7 +31,6 @@ import java.util.List; import java.util.Map; import org.junit.jupiter.api.BeforeEach; - import org.springframework.data.geo.Circle; import org.springframework.data.geo.Distance; import org.springframework.data.geo.Metrics; @@ -39,6 +39,7 @@ import org.springframework.data.redis.ObjectFactory; import org.springframework.data.redis.connection.RedisConnection; import org.springframework.data.redis.connection.RedisConnectionFactory; import org.springframework.data.redis.core.ReactiveOperationsTestParams.Fixture; +import org.springframework.data.redis.domain.geo.GeoShape; import org.springframework.data.redis.test.condition.EnabledOnCommand; import org.springframework.data.redis.test.extension.parametrized.MethodSource; import org.springframework.data.redis.test.extension.parametrized.ParameterizedRedisTest;