private static Converter<org.springframework.data.redis.connection.RedisZSetCommands.Range, Range.Boundary<?>> rangeToBoundaryArgumentConverter( boolean upper, boolean convertNumberToBytes) { return (source) -> { Boundary sourceBoundary = upper ? source.getMax() : source.getMin(); if (sourceBoundary == null || sourceBoundary.getValue() == null) { return Range.Boundary.unbounded(); } boolean inclusive = sourceBoundary.isIncluding(); Object value = sourceBoundary.getValue(); if (value instanceof Number) { if (convertNumberToBytes) { value = value.toString(); } else { return inclusive ? Range.Boundary.including((Number) value) : Range.Boundary.excluding((Number) value); } } if (value instanceof String) { if (!StringUtils.hasText((String) value) || ObjectUtils.nullSafeEquals(value, "+") || ObjectUtils.nullSafeEquals(value, "-")) { return Range.Boundary.unbounded(); } return inclusive ? Range.Boundary.including(value.toString().getBytes(LettuceCharsets.UTF8)) : Range.Boundary.excluding(value.toString().getBytes(LettuceCharsets.UTF8)); } return inclusive ? Range.Boundary.including((byte[]) value) : Range.Boundary.excluding((byte[]) value); }; }
/** * Less Then Equals * * @param max must not be {@literal null}. * @return this. */ public Range lte(Object max) { Assert.notNull(max, "Max already set for range."); this.max = new Boundary(max, true); return this; }
private static Converter<org.springframework.data.redis.connection.RedisZSetCommands.Range, Range.Boundary<?>> rangeToBoundaryArgumentConverter( boolean upper) { return (source) -> { Boundary sourceBoundary = upper ? source.getMax() : source.getMin(); if (sourceBoundary == null || sourceBoundary.getValue() == null) { return Range.Boundary.unbounded(); } boolean inclusive = sourceBoundary.isIncluding(); Object value = sourceBoundary.getValue(); if (value instanceof Number) { return inclusive ? Range.Boundary.including((Number) value) : Range.Boundary.excluding((Number) value); } if (value instanceof String) { if (!StringUtils.hasText((String) value) || ObjectUtils.nullSafeEquals(value, "+") || ObjectUtils.nullSafeEquals(value, "-")) { return Range.Boundary.unbounded(); } return inclusive ? Range.Boundary.including(value.toString().getBytes(LettuceCharsets.UTF8)) : Range.Boundary.excluding(value.toString().getBytes(LettuceCharsets.UTF8)); } return inclusive ? Range.Boundary.including((byte[]) value) : Range.Boundary.excluding((byte[]) value); }; }
private static byte[] boundaryToBytes(Boundary boundary, byte[] inclPrefix, byte[] exclPrefix) { byte[] prefix = boundary.isIncluding() ? inclPrefix : exclPrefix; byte[] value = null; if (boundary.getValue() instanceof byte[]) { value = (byte[]) boundary.getValue(); } else if (boundary.getValue() instanceof Double) { value = toBytes((Double) boundary.getValue()); } else if (boundary.getValue() instanceof Long) { value = toBytes((Long) boundary.getValue()); } else if (boundary.getValue() instanceof Integer) { value = toBytes((Integer) boundary.getValue()); } else if (boundary.getValue() instanceof String) { value = toBytes((String) boundary.getValue()); } else { throw new IllegalArgumentException(String.format("Cannot convert %s to binary format", boundary.getValue())); } ByteBuffer buffer = ByteBuffer.allocate(prefix.length + value.length); buffer.put(prefix); buffer.put(value); return buffer.array(); }
private static String boundaryToBytes(Boundary boundary, byte[] inclPrefix, byte[] exclPrefix) { byte[] prefix = boundary.isIncluding() ? inclPrefix : exclPrefix; byte[] value = null; if (boundary.getValue() instanceof byte[]) { value = (byte[]) boundary.getValue(); } else if (boundary.getValue() instanceof Double) { value = toBytes((Double) boundary.getValue()); } else if (boundary.getValue() instanceof Long) { value = toBytes((Long) boundary.getValue()); } else if (boundary.getValue() instanceof Integer) { value = toBytes((Integer) boundary.getValue()); } else if (boundary.getValue() instanceof String) { value = toBytes((String) boundary.getValue()); } else { throw new IllegalArgumentException(String.format("Cannot convert %s to binary format", boundary.getValue())); } ByteBuffer buffer = ByteBuffer.allocate(prefix.length + value.length); buffer.put(prefix); buffer.put(value); return toString(ByteUtils.getBytes(buffer)); }
private static Converter<org.springframework.data.redis.connection.RedisZSetCommands.Range, Range.Boundary<?>> rangeToBoundaryArgumentConverter( boolean upper) { return (source) -> { Boundary sourceBoundary = upper ? source.getMax() : source.getMin(); if (sourceBoundary == null || sourceBoundary.getValue() == null) { return Range.Boundary.unbounded(); } boolean inclusive = sourceBoundary.isIncluding(); Object value = sourceBoundary.getValue(); if (value instanceof Number) { return inclusive ? Range.Boundary.including((Number) value) : Range.Boundary.excluding((Number) value); } if (value instanceof String) { if (!StringUtils.hasText((String) value) || ObjectUtils.nullSafeEquals(value, "+") || ObjectUtils.nullSafeEquals(value, "-")) { return Range.Boundary.unbounded(); } return inclusive ? Range.Boundary.including(value.toString().getBytes(LettuceCharsets.UTF8)) : Range.Boundary.excluding(value.toString().getBytes(LettuceCharsets.UTF8)); } return inclusive ? Range.Boundary.including((byte[]) value) : Range.Boundary.excluding((byte[]) value); }; }
private static byte[] boundaryToBytes(Boundary boundary, byte[] inclPrefix, byte[] exclPrefix) { byte[] prefix = boundary.isIncluding() ? inclPrefix : exclPrefix; byte[] value = null; if (boundary.getValue() instanceof byte[]) { value = (byte[]) boundary.getValue(); } else if (boundary.getValue() instanceof Double) { value = toBytes((Double) boundary.getValue()); } else if (boundary.getValue() instanceof Long) { value = toBytes((Long) boundary.getValue()); } else if (boundary.getValue() instanceof Integer) { value = toBytes((Integer) boundary.getValue()); } else if (boundary.getValue() instanceof String) { value = toBytes((String) boundary.getValue()); } else { throw new IllegalArgumentException(String.format("Cannot convert %s to binary format", boundary.getValue())); } ByteBuffer buffer = ByteBuffer.allocate(prefix.length + value.length); buffer.put(prefix); buffer.put(value); return buffer.array(); }
private static String boundaryToBytes(Boundary boundary, byte[] inclPrefix, byte[] exclPrefix) { byte[] prefix = boundary.isIncluding() ? inclPrefix : exclPrefix; byte[] value = null; if (boundary.getValue() instanceof byte[]) { value = (byte[]) boundary.getValue(); } else if (boundary.getValue() instanceof Double) { value = toBytes((Double) boundary.getValue()); } else if (boundary.getValue() instanceof Long) { value = toBytes((Long) boundary.getValue()); } else if (boundary.getValue() instanceof Integer) { value = toBytes((Integer) boundary.getValue()); } else if (boundary.getValue() instanceof String) { value = toBytes((String) boundary.getValue()); } else { throw new IllegalArgumentException(String.format("Cannot convert %s to binary format", boundary.getValue())); } ByteBuffer buffer = ByteBuffer.allocate(prefix.length + value.length); buffer.put(prefix); buffer.put(value); return toString(ByteUtils.getBytes(buffer)); }
/** * Converts a given {@link Boundary} to its binary representation suitable for {@literal ZRANGEBY*} commands, despite * {@literal ZRANGEBYLEX}. * * @param boundary * @param defaultValue * @return * @since 1.6 */ public static byte[] boundaryToBytesForZRange(@Nullable Boundary boundary, byte[] defaultValue) { if (boundary == null || boundary.getValue() == null) { return defaultValue; } return boundaryToBytes(boundary, new byte[] {}, toBytes("(")); }
/** * Converts a given {@link Boundary} to its binary representation suitable for {@literal ZRANGEBY*} commands, despite * {@literal ZRANGEBYLEX}. * * @param boundary * @param defaultValue * @return * @since 1.6 */ public static String boundaryToBytesForZRange(Boundary boundary, byte[] defaultValue) { if (boundary == null || boundary.getValue() == null) { return toString(defaultValue); } return boundaryToBytes(boundary, new byte[] {}, toBytes("(")); }
/** * Converts a given {@link Boundary} to its binary representation suitable for {@literal ZRANGEBY*} commands, despite * {@literal ZRANGEBYLEX}. * * @param boundary * @param defaultValue * @return * @since 1.6 */ public static byte[] boundaryToBytesForZRange(@Nullable Boundary boundary, byte[] defaultValue) { if (boundary == null || boundary.getValue() == null) { return defaultValue; } return boundaryToBytes(boundary, new byte[] {}, toBytes("(")); }
static Boundary infinite() { return new Boundary(null, true); }
/** * Converts a given {@link Boundary} to its binary representation suitable for ZRANGEBYLEX command. * * @param boundary * @return * @since 1.6 */ public static byte[] boundaryToBytesForZRangeByLex(@Nullable Boundary boundary, byte[] defaultValue) { if (boundary == null || boundary.getValue() == null) { return defaultValue; } return boundaryToBytes(boundary, toBytes("["), toBytes("(")); }
/** * Converts a given {@link Boundary} to its binary representation suitable for {@literal ZRANGEBY*} commands, despite * {@literal ZRANGEBYLEX}. * * @param boundary * @param defaultValue * @return * @since 1.6 */ public static String boundaryToBytesForZRange(Boundary boundary, byte[] defaultValue) { if (boundary == null || boundary.getValue() == null) { return toString(defaultValue); } return boundaryToBytes(boundary, new byte[] {}, toBytes("(")); }
static Boundary infinite() { return new Boundary(null, true); }
public static String boundaryToStringForZRange(Boundary boundary, String defaultValue) { if (boundary == null || boundary.getValue() == null) { return defaultValue; } return boundaryToString(boundary, "", "("); }
/** * Converts a given {@link Boundary} to its binary representation suitable for ZRANGEBYLEX command. * * @param boundary * @return * @since 1.6 */ public static byte[] boundaryToBytesForZRangeByLex(@Nullable Boundary boundary, byte[] defaultValue) { if (boundary == null || boundary.getValue() == null) { return defaultValue; } return boundaryToBytes(boundary, toBytes("["), toBytes("(")); }
/** * Converts a given {@link Boundary} to its binary representation suitable for ZRANGEBYLEX command. * * @param boundary * @return * @since 1.6 */ public static String boundaryToBytesForZRangeByLex(Boundary boundary, byte[] defaultValue) { if (boundary == null || boundary.getValue() == null) { return toString(defaultValue); } return boundaryToBytes(boundary, toBytes("["), toBytes("(")); }
/** * Greater Than Equals * * @param min must not be {@literal null}. * @return this. */ public Range gte(Object min) { Assert.notNull(min, "Min already set for range."); this.min = new Boundary(min, true); return this; }