Refine search
/** * Count the number of set bits (population counting) of value stored at {@literal key} between {@literal start} and * {@literal end}. * * @param key must not be {@literal null}. * @param start * @param end * @return * @see <a href="http://redis.io/commands/bitcount">Redis Documentation: BITCOUNT</a> */ default Mono<Long> bitCount(ByteBuffer key, long start, long end) { Assert.notNull(key, "Key must not be null!"); return bitCount(Mono.just(BitCountCommand.bitCount(key).within(new Range<>(start, end)))).next() .map(NumericResponse::getOutput); }
@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)); }
/** * 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)); }
/** * 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; } }
/** * Set {@literal maximum} to given {@code max} value and {@literal exclusiveMaximum} to {@literal false}. * * @param max must not be {@literal null}. * @return new instance of {@link NumericJsonSchemaObject}. */ @SuppressWarnings("unchecked") NumericJsonSchemaObject lte(Number max) { Assert.notNull(max, "Max must not be null!"); Bound lower = this.range != null ? this.range.getLowerBound() : Bound.unbounded(); return within(Range.of(lower, createBound(max, true))); }
Optional<Distance> distance = range.getUpperBound().getValue(); Optional<Distance> minDistance = range.getLowerBound().getValue(); return distance.map(it -> { minDistance.ifPresent(min -> criteria.minDistance(min.getNormalizedValue())); }).orElseGet(() -> isSpherical ? criteria.nearSphere(pointToUse) : criteria.near(pointToUse));
@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 (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; }
Boolean inclusive = upper ? source.getUpperBound().isInclusive() : source.getLowerBound().isInclusive(); Object value = upper ? source.getUpperBound().getValue().orElse(null) : source.getLowerBound().getValue().orElse(null);
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 getUpperValue(Range<T> range) { return range.getUpperBound().getValue() .orElseThrow(() -> new IllegalArgumentException("Range does not contain upper bound value!")); }
RedisClusterAsyncCommands<byte[], byte[]> connection = getAsyncConnection(); if (range.getLowerBound().isBounded()) { if (range.getUpperBound().isBounded()) { futureResult = connection.bitpos(key, bit, getLowerValue(range), getUpperValue(range)); } else { if (range.getLowerBound().isBounded()) { if (range.getUpperBound().isBounded()) { return getConnection().bitpos(key, bit, getLowerValue(range), getUpperValue(range));
/** * Creates a new {@link RangeCommand} given a {@code key}. * * @param key must not be {@literal null}. * @return a new {@link RangeCommand} for {@code key}. */ public static RangeCommand key(ByteBuffer key) { return new RangeCommand(key, Range.unbounded()); }
@Override public Flux<NumericResponse<BitCountCommand, Long>> bitCount(Publisher<BitCountCommand> commands) { return connection.execute(cmd -> Flux.from(commands).concatMap(command -> { Assert.notNull(command.getKey(), "Key must not be null!"); Range<Long> range = command.getRange(); return (!Range.unbounded().equals(range) ? cmd.bitcount(command.getKey(), LettuceConverters.getLowerBoundIndex(range), // LettuceConverters.getUpperBoundIndex(range)) // : cmd.bitcount(command.getKey())).map(responseValue -> new NumericResponse<>(command, responseValue)); })); }
/** * 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(); }
/** * 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(); }
public Range<Distance> getDistanceRange() { MongoParameters mongoParameters = method.getParameters(); int rangeIndex = mongoParameters.getRangeIndex(); if (rangeIndex != -1) { return getValue(rangeIndex); } int maxDistanceIndex = mongoParameters.getMaxDistanceIndex(); Bound<Distance> maxDistance = maxDistanceIndex == -1 ? Bound.unbounded() : Bound.inclusive((Distance) getValue(maxDistanceIndex)); return Range.of(Bound.unbounded(), maxDistance); }
private OrderLine getRequiredOrderLineByIndex(int index) { Range<Integer> allowedIndexRange = Range.from(Bound.inclusive(0))// .to(Bound.exclusive(orderLines.size())); Assert.isTrue(allowedIndexRange.contains(index), String.format("Invalid order line index %s. Required: %s!", index, allowedIndexRange)); return this.orderLines.get(index); }
/** * Creates a new {@link QuotationMap} for the query. * * @param query can be {@literal null}. */ public QuotationMap(@Nullable String query) { if (query == null) { return; } Character inQuotation = null; int start = 0; for (int i = 0; i < query.length(); i++) { char currentChar = query.charAt(i); if (QUOTING_CHARACTERS.contains(currentChar)) { if (inQuotation == null) { inQuotation = currentChar; start = i; } else if (currentChar == inQuotation) { inQuotation = null; quotedRanges.add(Range.from(Bound.inclusive(start)).to(Bound.inclusive(i))); } } } if (inQuotation != null) { throw new IllegalArgumentException( String.format("The string <%s> starts a quoted range at %d, but never ends it.", query, start)); } }
/** * Checks if a given index is within a quoted range. * * @param index to check if it is part of a quoted range. * @return whether the query contains a quoted range at {@literal index}. */ public boolean isQuoted(int index) { return quotedRanges.stream().anyMatch(r -> r.contains(index)); } }