@Override public Point convert(Document source) { if (source == null) { return null; } Assert.isTrue(source.keySet().size() == 2, "Source must contain 2 elements"); if (source.containsKey("type")) { return DocumentToGeoJsonPointConverter.INSTANCE.convert(source); } return new Point(toPrimitiveDoubleValue(source.get("x")), toPrimitiveDoubleValue(source.get("y"))); } }
@Override public GeoResults<GeoLocation<byte[]>> geoRadius(byte[] key, Circle within) { RedisCommand<GeoResults<GeoLocation<byte[]>>> command = new RedisCommand<GeoResults<GeoLocation<byte[]>>>("GEORADIUS", new GeoResultsDecoder()); return read(key, ByteArrayCodec.INSTANCE, command, key, convert(within.getCenter().getX()), convert(within.getCenter().getY()), within.getRadius().getValue(), within.getRadius().getMetric().getAbbreviation()); }
/** * Returns the {@link Shape} as a list of usually {@link Double} or {@link List}s of {@link Double}s. Wildcard bound * to allow implementations to return a more concrete element type. * * @return */ public List<? extends Object> asList() { return Arrays.asList(Arrays.asList(center.getX(), center.getY()), this.radius.getValue()); }
@Override public Long geoAdd(byte[] key, Map<byte[], Point> memberCoordinateMap) { Assert.notNull(key, "Key must not be null!"); Assert.notNull(memberCoordinateMap, "MemberCoordinateMap must not be null!"); List<Object> values = new ArrayList<>(); for (Entry<byte[], Point> entry : memberCoordinateMap.entrySet()) { values.add(entry.getValue().getX()); values.add(entry.getValue().getY()); values.add(entry.getKey()); } return geoAdd(key, values); }
/** * Ensures that Points used in geospatial parts of non-nested properties are the same in case geospatial return type * is expected * * @param point */ private void checkUniquePoint(final Point point) { final boolean isStillUnique = (uniquePoint == null || uniquePoint.equals(point)); if (!isStillUnique) { isUnique = false; } if (!geoFields.isEmpty()) { Assert.isTrue(uniquePoint == null || uniquePoint.equals(point), "Different Points are used - Distance is ambiguous"); uniquePoint = point; } }
document.put("maxDistance", maxDistance.getNormalizedValue()); document.put("minDistance", minDistance.getNormalizedValue()); document.put("near", Arrays.asList(point.getX(), point.getY()));
/** * Returns the center of the {@link Circle}. * * @return will never be {@literal null}. */ public Point getCenter() { return new Point(this.center); }
/** * Creates a new {@link Circle} from the given coordinates and radius as {@link Distance} with a * {@link Metrics#NEUTRAL}. * * @param centerX * @param centerY * @param radius must be greater or equal to zero. */ public Circle(double centerX, double centerY, double radius) { this(new Point(centerX, centerY), new Distance(radius)); }
@Override public Long geoAdd(byte[] key, Point point, byte[] member) { Assert.notNull(key, "Key must not be null!"); Assert.notNull(point, "Point must not be null!"); Assert.notNull(member, "Member must not be null!"); try { return connection.getCluster().geoadd(key, point.getX(), point.getY(), member); } catch (Exception ex) { throw convertJedisAccessException(ex); } }
/** * Ensures that Points used in geospatial parts of non-nested properties are the same in case geospatial return type * is expected * * @param point */ private void checkUniquePoint(final Point point) { final boolean isStillUnique = (uniquePoint == null || uniquePoint.equals(point)); if (!isStillUnique) { isUnique = false; } if (!geoFields.isEmpty()) { Assert.isTrue(uniquePoint == null || uniquePoint.equals(point), "Different Points are used - Distance is ambiguous"); uniquePoint = point; } }
document.put("maxDistance", maxDistance.getNormalizedValue()); document.put("minDistance", minDistance.getNormalizedValue()); document.put("near", Arrays.asList(point.getX(), point.getY()));
/** * Returns the {@link Shape} as a list of usually {@link Double} or {@link List}s of {@link Double}s. Wildcard bound * to allow implementations to return a more concrete element type. * * @return */ public List<? extends Object> asList() { return Arrays.asList(Arrays.asList(center.getX(), center.getY()), this.radius.getValue()); }
@Override public Point decode(List<Object> parts, State state) { if (parts.isEmpty()) { return null; } Double longitude = (Double)parts.get(0); Double latitude = (Double)parts.get(1); return new Point(longitude, latitude); }