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 (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; }
private static Converter<org.springframework.data.domain.Range<?>, Boundary<?>> rangeToBoundArgumentConverter( Boolean upper) { return (source) -> { Boolean inclusive = upper ? source.getUpperBound().isInclusive() : source.getLowerBound().isInclusive(); Object value = upper ? LettuceConverters.getUpperBound(source).orElse(null) : LettuceConverters.getLowerBound(source).orElse(null); if (value == null) { return Boundary.unbounded(); } if (value instanceof Number) { return inclusive ? Boundary.including((Number) value) : Boundary.excluding((Number) value); } if (value instanceof String) { StringCodec stringCodec = new StringCodec(LettuceCharsets.UTF8); if (!StringUtils.hasText((String) value) || ObjectUtils.nullSafeEquals(value, "+") || ObjectUtils.nullSafeEquals(value, "-")) { return Boundary.unbounded(); } return inclusive ? Boundary.including(stringCodec.encodeValue((String) value)) : Boundary.excluding(stringCodec.encodeValue((String) value)); } return inclusive ? Boundary.including((ByteBuffer) value) : Boundary.excluding((ByteBuffer) value); }; } }
private static Converter<org.springframework.data.domain.Range<?>, Boundary<?>> rangeToBoundArgumentConverter( Boolean upper) { return (source) -> { Boolean inclusive = upper ? source.getUpperBound().isInclusive() : source.getLowerBound().isInclusive(); Object value = upper ? LettuceConverters.getUpperBound(source).orElse(null) : LettuceConverters.getLowerBound(source).orElse(null); if (value == null) { return Boundary.unbounded(); } if (value instanceof Number) { return inclusive ? Boundary.including((Number) value) : Boundary.excluding((Number) value); } if (value instanceof String) { StringCodec stringCodec = new StringCodec(LettuceCharsets.UTF8); if (!StringUtils.hasText((String) value) || ObjectUtils.nullSafeEquals(value, "+") || ObjectUtils.nullSafeEquals(value, "-")) { return Boundary.unbounded(); } return inclusive ? Boundary.including(stringCodec.encodeValue((String) value)) : Boundary.excluding(stringCodec.encodeValue((String) value)); } return inclusive ? Boundary.including((ByteBuffer) value) : Boundary.excluding((ByteBuffer) value); }; } }
/** * Returns whether the {@link Range} contains the given value. * * @param value must not be {@literal null}. * @return */ public boolean contains(T value) { Assert.notNull(value, "Reference value must not be null!"); boolean greaterThanLowerBound = lowerBound.getValue() // .map(it -> lowerBound.isInclusive() ? it.compareTo(value) <= 0 : it.compareTo(value) < 0) // .orElse(true); boolean lessThanUpperBound = upperBound.getValue() // .map(it -> upperBound.isInclusive() ? it.compareTo(value) >= 0 : it.compareTo(value) > 0) // .orElse(true); return greaterThanLowerBound && lessThanUpperBound; }
String toPrefixString() { return getValue() // .map(Object::toString) // .map(it -> isInclusive() ? "[".concat(it) : "(".concat(it)) // .orElse("unbounded"); }
/** * @return * @deprecated since 2.0, use {@link #getLowerBound()} and {@link Bound#isInclusive()}. */ @Deprecated public boolean isLowerInclusive() { return lowerBound.isInclusive(); }
/** * @return * @deprecated since 2.0, use {@link #getUpperBound()} and {@link Bound#isInclusive()}. */ @Deprecated public boolean isUpperInclusive() { return upperBound.isInclusive(); }
String toSuffixString() { return getValue() // .map(Object::toString) // .map(it -> isInclusive() ? it.concat("]") : it.concat(")")) // .orElse("unbounded"); }