/** * 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(); }
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!")); }
/** * 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; } }
@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)); }
@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; }
@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; }
/** * Set {@literal minimum} to given {@code min} value and {@literal exclusiveMinimum} to {@literal true}. * * @param min must not be {@literal null}. * @return new instance of {@link NumericJsonSchemaObject}. */ @SuppressWarnings("unchecked") public NumericJsonSchemaObject gt(Number min) { Assert.notNull(min, "Min must not be null!"); Bound upper = this.range != null ? this.range.getUpperBound() : Bound.unbounded(); return within(Range.of(createBound(min, false), upper)); }
/** * Set {@literal minimum} to given {@code min} value and {@literal exclusiveMinimum} to {@literal false}. * * @param min must not be {@literal null}. * @return new instance of {@link NumericJsonSchemaObject}. */ @SuppressWarnings("unchecked") public NumericJsonSchemaObject gte(Number min) { Assert.notNull(min, "Min must not be null!"); Bound upper = this.range != null ? this.range.getUpperBound() : Bound.unbounded(); return within(Range.of(createBound(min, true), upper)); }
/** * Define the {@literal minProperties}. * * @param count the allowed minimal number of properties. * @return new instance of {@link ObjectJsonSchemaObject}. */ public ObjectJsonSchemaObject minProperties(int count) { Bound<Integer> upper = this.propertiesCount != null ? this.propertiesCount.getUpperBound() : Bound.unbounded(); return propertiesCount(Range.of(Bound.inclusive(count), upper)); }
/** * Define the {@literal maxItems}. * * @param count the allowed minimal number of array items. * @return new instance of {@link ArrayJsonSchemaObject}. */ public ArrayJsonSchemaObject minItems(int count) { Bound<Integer> upper = this.range != null ? this.range.getUpperBound() : Bound.unbounded(); return range(Range.of(Bound.inclusive(count), upper)); }
/** * Define the valid length range ({@literal minLength}) for a valid field. * * @param length * @return new instance of {@link StringJsonSchemaObject}. */ public StringJsonSchemaObject minLength(int length) { Bound<Integer> upper = this.length != null ? this.length.getUpperBound() : Bound.unbounded(); return length(Range.of(Bound.inclusive(length), upper)); }
/** * Applies a lower bound to the {@link Range}. Constructs a new command instance with all previously configured * properties. * * @param start * @return a new {@link RangeCommand} with the lower bound applied. */ public RangeCommand fromIndex(long start) { return new RangeCommand(getKey(), Range.of(Bound.inclusive(start), range.getUpperBound())); }
Boolean inclusive = upper ? source.getUpperBound().isInclusive() : source.getLowerBound().isInclusive(); Object value = upper ? source.getUpperBound().getValue().orElse(null) : source.getLowerBound().getValue().orElse(null);
@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(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; }
@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); }
@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); } }
@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 Flux<NumericResponse<BitPosCommand, Long>> bitPos(Publisher<BitPosCommand> commands) { return connection.execute(cmd -> { return Flux.from(commands).flatMap(command -> { Mono<Long> result; Range<Long> range = command.getRange(); if (range.getLowerBound().isBounded()) { result = cmd.bitpos(command.getKey(), command.getBit(), getLowerValue(range)); if (range.getUpperBound().isBounded()) { result = cmd.bitpos(command.getKey(), command.getBit(), getLowerValue(range), getUpperValue(range)); } } else { result = cmd.bitpos(command.getKey(), command.getBit()); } return result.map(respValue -> new NumericResponse<>(command, respValue)); }); }); }