@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)); }
/** * 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)); }
Boolean inclusive = upper ? source.getUpperBound().isInclusive() : source.getLowerBound().isInclusive(); Object value = upper ? source.getUpperBound().getValue().orElse(null) : source.getLowerBound().getValue().orElse(null);
String toPrefixString() { return getValue() // .map(Object::toString) // .map(it -> isInclusive() ? "[".concat(it) : "(".concat(it)) // .orElse("unbounded"); }
@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); } }
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));
@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; }
/** * 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 getUpperValue(Range<T> range) { return range.getUpperBound().getValue() .orElseThrow(() -> new IllegalArgumentException("Range does not contain upper bound value!")); }
/** * 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))); }
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));
/** * 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)); } }
private static Bound<?> createBound(Number number, boolean inclusive) { if (number instanceof Long) { return inclusive ? Bound.inclusive((Long) number) : Bound.exclusive((Long) number); } if (number instanceof Double) { return inclusive ? Bound.inclusive((Double) number) : Bound.exclusive((Double) number); } if (number instanceof Float) { return inclusive ? Bound.inclusive((Float) number) : Bound.exclusive((Float) number); } if (number instanceof Integer) { return inclusive ? Bound.inclusive((Integer) number) : Bound.exclusive((Integer) number); } if (number instanceof BigDecimal) { return inclusive ? Bound.inclusive((BigDecimal) number) : Bound.exclusive((BigDecimal) number); } throw new IllegalArgumentException("Unsupported numeric value."); }
private static Bound<?> createBound(Number number, boolean inclusive) { if (number instanceof Long) { return inclusive ? Bound.inclusive((Long) number) : Bound.exclusive((Long) number); } if (number instanceof Double) { return inclusive ? Bound.inclusive((Double) number) : Bound.exclusive((Double) number); } if (number instanceof Float) { return inclusive ? Bound.inclusive((Float) number) : Bound.exclusive((Float) number); } if (number instanceof Integer) { return inclusive ? Bound.inclusive((Integer) number) : Bound.exclusive((Integer) number); } if (number instanceof BigDecimal) { return inclusive ? Bound.inclusive((BigDecimal) number) : Bound.exclusive((BigDecimal) number); } throw new IllegalArgumentException("Unsupported numeric value."); }
/** * @return * @deprecated since 2.0, use {@link #getLowerBound()} and {@link Bound#isInclusive()}. */ @Deprecated public boolean isLowerInclusive() { return lowerBound.isInclusive(); }