/** * Converts the given {@link Range} into an array of values. * * @param range must not be {@literal null}. * @return */ public static List<Long> toRangeValues(Range<Long> range) { Assert.notNull(range, "Range must not be null!"); List<Long> result = new ArrayList<Long>(2); result.add(range.getLowerBound().getValue() .orElseThrow(() -> new IllegalArgumentException("Lower bound of range must be bounded!"))); range.getUpperBound().getValue().ifPresent(it -> result.add(it)); return result; } }
private static <T extends Comparable<T>> T getLowerValue(Range<T> range) { return range.getLowerBound().getValue() .orElseThrow(() -> new IllegalArgumentException("Range does not contain lower bound value!")); } }
private static <T extends Comparable<T>> T getLowerValue(Range<T> range) { return range.getLowerBound().getValue() .orElseThrow(() -> new IllegalArgumentException("Range does not contain lower bound value!")); } }
@SuppressWarnings({ "unchecked", "rawtypes" }) protected Flux<GeoResult<Object>> doExecuteQuery(@Nullable Query query, Class<?> type, String collection) { Point nearLocation = accessor.getGeoNearLocation(); NearQuery nearQuery = NearQuery.near(nearLocation); if (query != null) { nearQuery.query(query); } Range<Distance> distances = accessor.getDistanceRange(); distances.getUpperBound().getValue().ifPresent(it -> nearQuery.maxDistance(it).in(it.getMetric())); distances.getLowerBound().getValue().ifPresent(it -> nearQuery.minDistance(it).in(it.getMetric())); Pageable pageable = accessor.getPageable(); nearQuery.with(pageable); return (Flux) operations.geoNear(nearQuery, type, collection); }
@SuppressWarnings("unchecked") GeoResults<Object> doExecuteQuery(Query query) { Point nearLocation = accessor.getGeoNearLocation(); NearQuery nearQuery = NearQuery.near(nearLocation); if (query != null) { nearQuery.query(query); } Range<Distance> distances = accessor.getDistanceRange(); distances.getLowerBound().getValue().ifPresent(it -> nearQuery.minDistance(it).in(it.getMetric())); distances.getUpperBound().getValue().ifPresent(it -> nearQuery.maxDistance(it).in(it.getMetric())); Pageable pageable = accessor.getPageable(); nearQuery.with(pageable); return (GeoResults<Object>) operation.near(nearQuery).all(); }
@Override public Document toDocument() { Document doc = new Document(super.toDocument()); if (length != null) { length.getLowerBound().getValue().ifPresent(it -> doc.append("minLength", it)); length.getUpperBound().getValue().ifPresent(it -> doc.append("maxLength", it)); } if (!StringUtils.isEmpty(pattern)) { doc.append("pattern", pattern); } return doc; }
@Nullable @Override public Long bitPos(byte[] key, boolean bit, Range<Long> range) { Assert.notNull(key, "Key must not be null!"); Assert.notNull(range, "Range must not be null! Use Range.unbounded() instead."); BitPosParams params = null; if (range.getLowerBound().isBounded()) { params = range.getUpperBound().isBounded() ? new BitPosParams(range.getLowerBound().getValue().get(), range.getUpperBound().getValue().get()) : new BitPosParams(range.getLowerBound().getValue().get()); } try { if (isPipelined()) { pipeline(connection.newJedisResult(params != null ? connection.getRequiredPipeline().bitpos(key, bit, params) : connection.getRequiredPipeline().bitpos(key, bit))); return null; } if (isQueueing()) { transaction( connection.newJedisResult(params != null ? connection.getRequiredTransaction().bitpos(key, bit, params) : connection.getRequiredTransaction().bitpos(key, bit))); return null; } return params != null ? connection.getJedis().bitpos(key, bit, params) : connection.getJedis().bitpos(key, bit); } catch (Exception ex) { throw convertJedisAccessException(ex); } }
@Override public Document toDocument() { Document doc = new Document(super.toDocument()); if (!CollectionUtils.isEmpty(requiredProperties)) { doc.append("required", requiredProperties); } if (propertiesCount != null) { propertiesCount.getLowerBound().getValue().ifPresent(it -> doc.append("minProperties", it)); propertiesCount.getUpperBound().getValue().ifPresent(it -> doc.append("maxProperties", it)); } if (!CollectionUtils.isEmpty(properties)) { doc.append("properties", reduceToDocument(properties)); } if (!CollectionUtils.isEmpty(patternProperties)) { doc.append("patternProperties", reduceToDocument(patternProperties)); } if (additionalProperties != null) { doc.append("additionalProperties", additionalProperties instanceof JsonSchemaObject ? ((JsonSchemaObject) additionalProperties).toDocument() : additionalProperties); } return doc; }
@Override public Document toDocument() { Document doc = new Document(super.toDocument()); if (multipleOf != null) { doc.append("multipleOf", multipleOf); } if (range != null) { if (range.getLowerBound().isBounded()) { range.getLowerBound().getValue().ifPresent(it -> doc.append("minimum", it)); if (!range.getLowerBound().isInclusive()) { doc.append("exclusiveMinimum", true); } } if (range.getUpperBound().isBounded()) { range.getUpperBound().getValue().ifPresent(it -> doc.append("maximum", it)); if (!range.getUpperBound().isInclusive()) { doc.append("exclusiveMaximum", true); } } } return doc; }
@Override public Document toDocument() { Document doc = new Document(super.toDocument()); if (!CollectionUtils.isEmpty(items)) { doc.append("items", items.size() == 1 ? items.iterator().next() : items.stream().map(JsonSchemaObject::toDocument).collect(Collectors.toList())); } if (range != null) { range.getLowerBound().getValue().ifPresent(it -> doc.append("minItems", it)); range.getUpperBound().getValue().ifPresent(it -> doc.append("maxItems", it)); } if (ObjectUtils.nullSafeEquals(uniqueItems, Boolean.TRUE)) { doc.append("uniqueItems", true); } if (additionalItems != null) { doc.append("additionalItems", additionalItems); } return doc; }
@SuppressWarnings("unchecked") GeoResults<Object> doExecuteQuery(Query query) { Point nearLocation = accessor.getGeoNearLocation(); NearQuery nearQuery = NearQuery.near(nearLocation); if (query != null) { nearQuery.query(query); } Range<Distance> distances = accessor.getDistanceRange(); distances.getLowerBound().getValue().ifPresent(it -> nearQuery.minDistance(it).in(it.getMetric())); distances.getUpperBound().getValue().ifPresent(it -> nearQuery.maxDistance(it).in(it.getMetric())); Pageable pageable = accessor.getPageable(); nearQuery.with(pageable); return (GeoResults<Object>) operation.near(nearQuery).all(); }
@SuppressWarnings({ "unchecked", "rawtypes" }) protected Flux<GeoResult<Object>> doExecuteQuery(@Nullable Query query, Class<?> type, String collection) { Point nearLocation = accessor.getGeoNearLocation(); NearQuery nearQuery = NearQuery.near(nearLocation); if (query != null) { nearQuery.query(query); } Range<Distance> distances = accessor.getDistanceRange(); distances.getUpperBound().getValue().ifPresent(it -> nearQuery.maxDistance(it).in(it.getMetric())); distances.getLowerBound().getValue().ifPresent(it -> nearQuery.minDistance(it).in(it.getMetric())); Pageable pageable = accessor.getPageable(); nearQuery.with(pageable); return (Flux) operations.geoNear(nearQuery, type, collection); }
@Override public Long bitPos(byte[] key, boolean bit, Range<Long> range) { Assert.notNull(key, "Key must not be null!"); Assert.notNull(range, "Range must not be null! Use Range.unbounded() instead."); List<byte[]> args = new ArrayList<>(3); args.add(LettuceConverters.toBit(bit)); if (range.getLowerBound().isBounded()) { args.add(range.getLowerBound().getValue().map(LettuceConverters::toBytes).get()); } if (range.getUpperBound().isBounded()) { args.add(range.getUpperBound().getValue().map(LettuceConverters::toBytes).get()); } return Long.class.cast(connection.execute("BITPOS", key, args)); }
private static <T extends Comparable<T>> T getUpperValue(Range<T> range) { return range.getUpperBound().getValue() .orElseThrow(() -> new IllegalArgumentException("Range does not contain upper bound value!")); }
private static <T extends Comparable<T>> T getUpperValue(Range<T> range) { return range.getUpperBound().getValue() .orElseThrow(() -> new IllegalArgumentException("Range does not contain upper bound value!")); }
/** * Return {@link Optional} upper bound from {@link Range}. * * @param range * @param <T> * @return * @since 2.0.9 */ static <T extends Comparable<T>> Optional<T> getUpperBound(org.springframework.data.domain.Range<T> range) { return range.getUpperBound().getValue(); }
/** * Return {@link Optional} lower bound from {@link Range}. * * @param range * @param <T> * @return * @since 2.0.9 */ static <T extends Comparable<T>> Optional<T> getLowerBound(org.springframework.data.domain.Range<T> range) { return range.getLowerBound().getValue(); }
@Override public Document toDocument() { Document doc = new Document(super.toDocument()); if (length != null) { length.getLowerBound().getValue().ifPresent(it -> doc.append("minLength", it)); length.getUpperBound().getValue().ifPresent(it -> doc.append("maxLength", it)); } if (!StringUtils.isEmpty(pattern)) { doc.append("pattern", pattern); } return doc; }