org.springframework.data.domain.Range Java Examples

The following examples show how to use org.springframework.data.domain.Range. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DerivedQueryCreatorTest.java    From spring-data with Apache License 2.0 6 votes vote down vote up
@Test
public void findWithinTest() {
	final List<Customer> toBeRetrieved = new LinkedList<>();
	final Customer customer1 = new Customer("", "", 0);
	customer1.setLocation(new int[] { 11, 0 });
	toBeRetrieved.add(customer1);
	final Customer customer2 = new Customer("", "", 0);
	customer2.setLocation(new int[] { 10, 10 });
	toBeRetrieved.add(customer2);
	final Customer customer3 = new Customer("", "", 0);
	customer3.setLocation(new int[] { 0, 50 });
	toBeRetrieved.add(customer3);
	repository.saveAll(toBeRetrieved);
	final Customer customer4 = new Customer("", "", 0);
	customer4.setLocation(new int[] { 0, 0 });
	repository.save(customer4);
	final Customer customer5 = new Customer("---", "", 0);
	customer5.setLocation(new int[] { 10, 10 });
	repository.save(customer5);
	final Bound<Double> lowerBound = Bound.inclusive(convertAngleToDistance(10));
	final Bound<Double> upperBound = Bound.inclusive(convertAngleToDistance(50));
	final List<Customer> retrieved = repository.findByLocationWithinAndName(new Point(0, 0),
		Range.of(lowerBound, upperBound), "");
	assertTrue(equals(toBeRetrieved, retrieved, cmp, eq, false));
}
 
Example #2
Source File: DerivedQueryCreatorTest.java    From spring-data with Apache License 2.0 6 votes vote down vote up
@Test
public void findWithinAndWithinTest() {
	final List<Customer> toBeRetrieved = new LinkedList<>();
	final Customer customer1 = new Customer("+++", "", 0);
	customer1.setLocation(new int[] { 80, 0 });
	toBeRetrieved.add(customer1);
	final Customer customer2 = new Customer("vvv", "", 0);
	customer2.setLocation(new int[] { 10, 0 });
	toBeRetrieved.add(customer2);
	repository.saveAll(toBeRetrieved);
	final Customer customer3 = new Customer("--d", "", 0);
	customer3.setLocation(new int[] { 19, 0 });
	repository.save(customer3);
	final Customer customer4 = new Customer("--r", "", 0);
	customer4.setLocation(new int[] { 6, 0 });
	repository.save(customer4);
	final Customer customer5 = new Customer("-!r", "", 0);
	customer5.setLocation(new int[] { 0, 0 });
	repository.save(customer5);
	final int distance = (int) convertAngleToDistance(11);
	final Bound<Integer> lowerBound = Bound.inclusive((int) convertAngleToDistance(5));
	final Bound<Integer> upperBound = Bound.inclusive((int) convertAngleToDistance(15));
	final Collection<Customer> retrieved = repository.findByLocationWithinAndLocationWithinOrName(new Point(0, 20),
		distance, new Ring<>(new Point(0, 0), Range.of(lowerBound, upperBound)), "+++");
	assertTrue(equals(toBeRetrieved, retrieved, cmp, eq, false));
}
 
Example #3
Source File: RedissonReactiveStringCommands.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Override

public Flux<NumericResponse<BitCountCommand, Long>> bitCount(Publisher<BitCountCommand> commands) {
    return execute(commands, command -> {

        Assert.notNull(command.getKey(), "Key must not be null!");

        Range<Long> range = command.getRange();
        if (range == null) {
            range = Range.unbounded();
        }
        
        byte[] keyBuf = toByteArray(command.getKey());
        Mono<Long> m;
        if (range == Range.<Long>unbounded()) {
            m = write(keyBuf, StringCodec.INSTANCE, RedisCommands.BITCOUNT, keyBuf); 
        } else {
            m = write(keyBuf, StringCodec.INSTANCE, RedisCommands.BITCOUNT, 
                    keyBuf, range.getLowerBound().getValue().orElse(0L), 
                    range.getUpperBound().getValue().get());
        }
        return m.map(v -> new NumericResponse<>(command, v));
    });
}
 
Example #4
Source File: RedissonReactiveStreamCommands.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Override
public Flux<ReactiveRedisConnection.CommandResponse<PendingRecordsCommand, PendingMessagesSummary>> xPendingSummary(Publisher<PendingRecordsCommand> publisher) {
    return execute(publisher, command -> {

        Assert.notNull(command.getKey(), "Key must not be null!");
        Assert.notNull(command.getGroupName(), "Group name must not be null!");

        byte[] k = toByteArray(command.getKey());

        Mono<PendingResult> m = write(k, StringCodec.INSTANCE, RedisCommands.XPENDING, k, command.getGroupName());
        return m.map(v -> {
            Range<String> range = Range.open(v.getLowestId().toString(), v.getHighestId().toString());
            PendingMessagesSummary s = new PendingMessagesSummary(command.getGroupName(), v.getTotal(), range, v.getConsumerNames());
            return new ReactiveRedisConnection.CommandResponse<>(command, s);
        });
    });
}
 
Example #5
Source File: RedissonStreamCommands.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Override
public PendingMessagesSummary decode(List<Object> parts, State state) {
    if (parts.isEmpty()) {
        return null;
    }

    List<List<String>> customerParts = (List<List<String>>) parts.get(3);
    if (customerParts.isEmpty()) {
        return new PendingMessagesSummary(groupName, 0, Range.unbounded(), Collections.emptyMap());
    }

    Map<String, Long> map = customerParts.stream().collect(Collectors.toMap(e -> e.get(0), e -> Long.valueOf(e.get(1)),
            (u, v) -> { throw new IllegalStateException("Duplicate key: " + u); },
            LinkedHashMap::new));
    Range<String> range = Range.open(parts.get(1).toString(), parts.get(2).toString());
    return new PendingMessagesSummary(groupName, (Long) parts.get(0), range, map);
}
 
Example #6
Source File: RedissonStreamCommands.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Override
public PendingMessages xPending(byte[] key, String groupName, XPendingOptions options) {
    Assert.notNull(key, "Key must not be null!");
    Assert.notNull(groupName, "Group name must not be null!");

    List<Object> params = new ArrayList<>();
    params.add(groupName);

    params.add(((Range.Bound<String>)options.getRange().getLowerBound()).getValue().orElse("-"));
    params.add(((Range.Bound<String>)options.getRange().getUpperBound()).getValue().orElse("+"));

    if (options.getCount() != null) {
        params.add(options.getCount());
    }
    if (options.getConsumerName() != null) {
        params.add(options.getConsumerName());
    }

    return connection.write(key, StringCodec.INSTANCE, new RedisCommand<>("XPENDING",
                        new PendingMessagesReplayDecoder(groupName, options.getRange())), params.toArray());
}
 
Example #7
Source File: RedissonReactiveStringCommands.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Override

public Flux<NumericResponse<BitCountCommand, Long>> bitCount(Publisher<BitCountCommand> commands) {
    return execute(commands, command -> {

        Assert.notNull(command.getKey(), "Key must not be null!");

        Range<Long> range = command.getRange();
        if (range == null) {
            range = Range.unbounded();
        }
        
        byte[] keyBuf = toByteArray(command.getKey());
        Mono<Long> m;
        if (range == Range.<Long>unbounded()) {
            m = write(keyBuf, StringCodec.INSTANCE, RedisCommands.BITCOUNT, keyBuf); 
        } else {
            m = write(keyBuf, StringCodec.INSTANCE, RedisCommands.BITCOUNT, 
                    keyBuf, range.getLowerBound().getValue().orElse(0L), 
                    range.getUpperBound().getValue().get());
        }
        return m.map(v -> new NumericResponse<>(command, v));
    });
}
 
Example #8
Source File: RedissonReactiveStringCommands.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Override

public Flux<NumericResponse<BitCountCommand, Long>> bitCount(Publisher<BitCountCommand> commands) {
    return execute(commands, command -> {

        Assert.notNull(command.getKey(), "Key must not be null!");

        Range<Long> range = command.getRange();
        if (range == null) {
            range = Range.unbounded();
        }
        
        byte[] keyBuf = toByteArray(command.getKey());
        Mono<Long> m;
        if (range == Range.<Long>unbounded()) {
            m = write(keyBuf, StringCodec.INSTANCE, RedisCommands.BITCOUNT, keyBuf); 
        } else {
            m = write(keyBuf, StringCodec.INSTANCE, RedisCommands.BITCOUNT, 
                    keyBuf, range.getLowerBound().getValue().orElse(0L), 
                    range.getUpperBound().getValue().get());
        }
        return m.map(v -> new NumericResponse<>(command, v));
    });
}
 
Example #9
Source File: RedissonReactiveStringCommands.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Override

public Flux<NumericResponse<BitCountCommand, Long>> bitCount(Publisher<BitCountCommand> commands) {
    return execute(commands, command -> {

        Assert.notNull(command.getKey(), "Key must not be null!");

        Range<Long> range = command.getRange();
        if (range == null) {
            range = Range.unbounded();
        }
        
        byte[] keyBuf = toByteArray(command.getKey());
        Mono<Long> m;
        if (range == Range.<Long>unbounded()) {
            m = write(keyBuf, StringCodec.INSTANCE, RedisCommands.BITCOUNT, keyBuf); 
        } else {
            m = write(keyBuf, StringCodec.INSTANCE, RedisCommands.BITCOUNT, 
                    keyBuf, range.getLowerBound().getValue().orElse(0L), 
                    range.getUpperBound().getValue().get());
        }
        return m.map(v -> new NumericResponse<>(command, v));
    });
}
 
Example #10
Source File: Neo4jQuerySupport.java    From sdn-rx with Apache License 2.0 5 votes vote down vote up
/**
 * Converts parameter as needed by the query generated, which is not covered by standard conversion services.
 *
 * @param parameter The parameter to fit into the generated query.
 * @return A parameter that fits the place holders of a generated query
 */
final Object convertParameter(Object parameter) {

	if (parameter == null) {
		// According to https://neo4j.com/docs/cypher-manual/current/syntax/working-with-null/#cypher-null-intro
		// it does not make any sense to continue if a `null` value gets into a comparison
		// but we just warn the users and do not throw an exception on `null`.
		log.warn("Do not use `null` as a property value for comparison."
			+ " It will always be false and return an empty result.");

		return Values.NULL;
	}

	// Maybe move all of those into Neo4jConverter at some point.
	if (parameter instanceof Range) {
		return convertRange((Range) parameter);
	} else if (parameter instanceof Distance) {
		return calculateDistanceInMeter((Distance) parameter);
	} else if (parameter instanceof Circle) {
		return convertCircle((Circle) parameter);
	} else if (parameter instanceof Instant) {
		return ((Instant) parameter).atOffset(ZoneOffset.UTC);
	} else if (parameter instanceof Box) {
		return convertBox((Box) parameter);
	} else if (parameter instanceof BoundingBox) {
		return convertBoundingBox((BoundingBox) parameter);
	}

	// Good hook to check the NodeManager whether the thing is an entity and we replace the value with a known id.
	return mappingContext.getConverter()
		.writeValueFromProperty(parameter, ClassTypeInformation.from(parameter.getClass()));
}
 
Example #11
Source File: CypherQueryCreator.java    From sdn-rx with Apache License 2.0 5 votes vote down vote up
private Condition betweenCondition(Neo4jPersistentProperty persistentProperty, Iterator<Object> actualParameters,
	boolean ignoreCase) {

	Parameter lowerBoundOrRange = nextRequiredParameter(actualParameters);

	Expression property = toCypherProperty(persistentProperty, ignoreCase);
	if (lowerBoundOrRange.value instanceof Range) {
		return createRangeConditionForProperty(property, lowerBoundOrRange);
	} else {
		Parameter upperBound = nextRequiredParameter(actualParameters);
		return property.gte(toCypherParameter(lowerBoundOrRange, ignoreCase))
			.and(property.lte(toCypherParameter(upperBound, ignoreCase)));
	}
}
 
Example #12
Source File: CypherQueryCreator.java    From sdn-rx with Apache License 2.0 5 votes vote down vote up
private Condition createNearCondition(Neo4jPersistentProperty persistentProperty,
	Iterator<Object> actualParameters) {

	Parameter p1 = nextRequiredParameter(actualParameters);
	Optional<Parameter> p2 = nextOptionalParameter(actualParameters);

	Expression referencePoint;

	Optional<Parameter> other;
	if (p1.value instanceof Point) {
		referencePoint = toCypherParameter(p1, false);
		other = p2;
	} else if (p2.isPresent() && p2.get().value instanceof Point) {
		referencePoint = toCypherParameter(p2.get(), false);
		other = Optional.of(p1);
	} else {
		throw new IllegalArgumentException(
			String.format("The NEAR operation requires a reference point of type %s", Point.class));
	}

	Expression distanceFunction = Functions.distance(toCypherProperty(persistentProperty, false), referencePoint);

	if (other.filter(p -> p.hasValueOfType(Distance.class)).isPresent()) {
		return distanceFunction.lte(toCypherParameter(other.get(), false));
	} else if (other.filter(p -> p.hasValueOfType(Range.class)).isPresent()) {
		return createRangeConditionForProperty(distanceFunction, other.get());
	} else {
		// We only have a point toCypherParameter, that's ok, but we have to put back the last toCypherParameter when it wasn't null
		other.ifPresent(this.lastParameter::offer);

		// Also, we cannot filter, but need to sort in the end.
		this.sortItems.add(distanceFunction.ascending());
		return Conditions.noCondition();
	}
}
 
Example #13
Source File: RepositoryIT.java    From sdn-rx with Apache License 2.0 5 votes vote down vote up
@Test
void findByBetweenRange(@Autowired PersonRepository repository) {

	List<PersonWithAllConstructor> persons;
	persons = repository.findAllByPersonNumberIsBetween(Range.from(inclusive(1L)).to(inclusive(2L)));
	assertThat(persons)
		.containsExactlyInAnyOrder(person1, person2);

	persons = repository.findAllByPersonNumberIsBetween(Range.from(inclusive(1L)).to(exclusive(2L)));
	assertThat(persons)
		.hasSize(1)
		.contains(person1);

	persons = repository.findAllByPersonNumberIsBetween(Range.from(inclusive(1L)).to(unbounded()));
	assertThat(persons)
		.containsExactlyInAnyOrder(person1, person2);

	persons = repository.findAllByPersonNumberIsBetween(Range.from(exclusive(1L)).to(unbounded()));
	assertThat(persons)
		.hasSize(1)
		.contains(person2);

	persons = repository.findAllByPersonNumberIsBetween(Range.from(Bound.<Long>unbounded()).to(inclusive(2L)));
	assertThat(persons)
		.containsExactlyInAnyOrder(person1, person2);

	persons = repository.findAllByPersonNumberIsBetween(Range.from(Bound.<Long>unbounded()).to(exclusive(2L)));
	assertThat(persons)
		.hasSize(1)
		.contains(person1);

	persons = repository.findAllByPersonNumberIsBetween(Range.unbounded());
	assertThat(persons)
		.containsExactlyInAnyOrder(person1, person2);
}
 
Example #14
Source File: BindParameterBinding.java    From spring-data with Apache License 2.0 5 votes vote down vote up
public int bindRing(
	final Object value,
	final boolean shouldIgnoreCase,
	final UniqueCheck uniqueCheck,
	final int startIndex) {
	int index = startIndex;
	final Ring<?> ring = (Ring<?>) ignoreArgumentCase(value, shouldIgnoreCase);
	final Point point = ring.getPoint();
	index = bindPoint(point, uniqueCheck, index);
	final Range<?> range = ring.getRange();
	index = bindRange(range, index);
	return index;
}
 
Example #15
Source File: BindParameterBinding.java    From spring-data with Apache License 2.0 5 votes vote down vote up
private int bindRange(final Range<?> range, int index) {
	Object lowerBound = range.getLowerBound().getValue().get();
	Object upperBound = range.getUpperBound().getValue().get();
	if (lowerBound.getClass() == Distance.class && upperBound.getClass() == lowerBound.getClass()) {
		lowerBound = convertDistanceToMeters((Distance) lowerBound);
		upperBound = convertDistanceToMeters((Distance) upperBound);
	}
	bind(index++, lowerBound);
	bind(index++, upperBound);
	return index;
}
 
Example #16
Source File: CustomerRepository.java    From spring-data with Apache License 2.0 5 votes vote down vote up
List<Customer> findByNameOrLocationWithinOrNameAndSurnameOrNameAndLocationNearAndSurnameAndLocationWithin(
String name1,
Point location1,
double distance,
String name2,
String surname1,
String name3,
Point location2,
String surname2,
Point location3,
Range<Double> distanceRange);
 
Example #17
Source File: CustomerRepository.java    From spring-data with Apache License 2.0 5 votes vote down vote up
GeoResults<Customer> findByNameOrSurnameAndLocationWithinOrLocationWithin(
String name,
String surname,
Point location1,
Distance distance,
Point location2,
Range<Distance> distanceRange);
 
Example #18
Source File: DerivedQueryCreatorTest.java    From spring-data with Apache License 2.0 5 votes vote down vote up
@Test
public void geoResultsTest() {
	final List<Customer> toBeRetrieved = new LinkedList<>();
	final Customer customer1 = new Customer("", "", 0);
	customer1.setLocation(new int[] { 43, 21 });
	toBeRetrieved.add(customer1);
	final Customer customer2 = new Customer("", "", 0);
	customer2.setLocation(new int[] { 21, 43 });
	toBeRetrieved.add(customer2);
	repository.saveAll(toBeRetrieved);
	final Customer customer3 = new Customer("", "", 0);
	customer3.setLocation(new int[] { 70, 50 });
	repository.save(customer3);
	final Customer customer4 = new Customer("", "", 0);
	customer4.setLocation(new int[] { 3, 2 });
	repository.save(customer4);
	final Bound<Double> lowerBound = Bound.inclusive(convertAngleToDistance(30));
	final Bound<Double> upperBound = Bound.inclusive(convertAngleToDistance(50));
	final GeoResults<Customer> retrieved = repository.findByLocationWithin(new Point(1, 0),
		Range.of(lowerBound, upperBound));
	final List<GeoResult<Customer>> expectedGeoResults = new LinkedList<>();
	expectedGeoResults.add(new GeoResult<>(customer1,
			new Distance(getDistanceBetweenPoints(new Point(1, 0), new Point(21, 43)) / 1000, Metrics.KILOMETERS)));
	expectedGeoResults.add(new GeoResult<>(customer2,
			new Distance(getDistanceBetweenPoints(new Point(1, 0), new Point(43, 21)) / 1000, Metrics.KILOMETERS)));
	assertTrue(equals(expectedGeoResults, retrieved, geoCmp, geoEq, false));
}
 
Example #19
Source File: DerivedQueryCreatorTest.java    From spring-data with Apache License 2.0 5 votes vote down vote up
@Test
public void buildPredicateWithDistanceTest() {
	final List<Customer> toBeRetrieved = new LinkedList<>();
	final Customer customer1 = new Customer("+", "", 0);
	customer1.setLocation(new int[] { 89, 89 });
	toBeRetrieved.add(customer1);
	final Customer customer2 = new Customer("", "+", 0);
	customer2.setLocation(new int[] { 5, 0 });
	toBeRetrieved.add(customer2);
	final Customer customer3 = new Customer("", "", 0);
	customer3.setLocation(new int[] { 0, 25 });
	toBeRetrieved.add(customer3);
	repository.saveAll(toBeRetrieved);
	final Customer customer4 = new Customer("", "", 0);
	customer4.setLocation(new int[] { 15, 0 });
	repository.save(customer4);
	final Customer customer5 = new Customer("", "", 0);
	customer5.setLocation(new int[] { 0, 35 });
	repository.save(customer5);
	final double distanceInMeters = convertAngleToDistance(10);
	final Distance distance = new Distance(distanceInMeters / 1000, Metrics.KILOMETERS);
	final Range<Distance> distanceRange = Range.of(
		Bound.inclusive(new Distance(convertAngleToDistance(20) / 1000, Metrics.KILOMETERS)),
		Bound.inclusive(new Distance(convertAngleToDistance(30) / 1000, Metrics.KILOMETERS)));
	final Point location = new Point(0, 0);
	final GeoResults<Customer> retrieved = repository.findByNameOrSurnameAndLocationWithinOrLocationWithin("+", "+",
		location, distance, location, distanceRange);
	final List<GeoResult<Customer>> expectedGeoResults = new LinkedList<>();
	expectedGeoResults.add(new GeoResult<>(customer1,
			new Distance(getDistanceBetweenPoints(location, new Point(89, 89)) / 1000, Metrics.KILOMETERS)));
	expectedGeoResults.add(new GeoResult<>(customer2,
			new Distance(getDistanceBetweenPoints(location, new Point(0, 5)) / 1000, Metrics.KILOMETERS)));
	expectedGeoResults.add(new GeoResult<>(customer3,
			new Distance(getDistanceBetweenPoints(location, new Point(25, 0)) / 1000, Metrics.KILOMETERS)));
	assertTrue(equals(expectedGeoResults, retrieved, geoCmp, geoEq, false));
}
 
Example #20
Source File: SpelQueryContext.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new {@link QuotationMap} for the query.
 *
 * @param qry can be {@literal null}.
 */
public QuotationMap(@Nullable String qry) {
    if (qry == null)
        return;

    Character inQuotation = null;
    int start = 0;

    for (int i = 0; i < qry.length(); i++) {

        char curChar = qry.charAt(i);

        if (QUOTING_CHARACTERS.contains(curChar)) {

            if (inQuotation == null) {

                inQuotation = curChar;
                start = i;

            }
            else if (curChar == 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.", qry, start));
    }
}
 
Example #21
Source File: StringQuery.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new instance 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));
    }
}
 
Example #22
Source File: StringQuery.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new instance 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));
    }
}
 
Example #23
Source File: RedissonReactiveStreamCommands.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Override
public Flux<ReactiveRedisConnection.CommandResponse<PendingRecordsCommand, PendingMessages>> xPending(Publisher<PendingRecordsCommand> publisher) {
    return execute(publisher, command -> {

        Assert.notNull(command.getKey(), "Key must not be null!");
        Assert.notNull(command.getGroupName(), "Group name must not be null!");

        byte[] k = toByteArray(command.getKey());

        List<Object> params = new ArrayList<>();
        params.add(k);

        params.add(((Range.Bound<String>)command.getRange().getLowerBound()).getValue().orElse("-"));
        params.add(((Range.Bound<String>)command.getRange().getUpperBound()).getValue().orElse("+"));

        if (command.getCount() != null) {
            params.add(command.getCount());
        }
        if (command.getConsumerName() != null) {
            params.add(command.getConsumerName());
        }

        Mono<List<PendingEntry>> m = write(k, StringCodec.INSTANCE, RedisCommands.XPENDING_ENTRIES, params.toArray());
        return m.map(list -> {
            List<PendingMessage> msgs = list.stream().map(v -> new PendingMessage(RecordId.of(v.getId().toString()),
                    Consumer.from(command.getGroupName(), v.getConsumerName()),
                    Duration.of(v.getIdleTime(), ChronoUnit.MILLIS),
                    v.getLastTimeDelivered())).collect(Collectors.toList());
            PendingMessages s = new PendingMessages(command.getGroupName(), command.getRange(), msgs);
            return new ReactiveRedisConnection.CommandResponse<>(command, s);
        });
    });
}
 
Example #24
Source File: RedissonStreamCommands.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Override
public List<ByteRecord> xRange(byte[] key, Range<String> range, RedisZSetCommands.Limit limit) {
    return range(new RedisCommand<>("XRANGE",
        new ListMultiDecoder2(
                new ByteRecordReplayDecoder(key),
                new ObjectDecoder(new StreamIdDecoder()),
                new StreamObjectMapReplayDecoder()), RedisCommand.ValueType.MAP),
            key, range, limit);
}
 
Example #25
Source File: RedissonStreamCommands.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Override
public List<ByteRecord> xRevRange(byte[] key, Range<String> range, RedisZSetCommands.Limit limit) {
    return range(new RedisCommand<>("XREVRANGE",
        new ListMultiDecoder2(
                new ByteRecordReplayDecoder(key),
                new ObjectDecoder(new StreamIdDecoder()),
                new StreamObjectMapReplayDecoder()), RedisCommand.ValueType.MAP),
            key, range, limit);
}
 
Example #26
Source File: RedissonReactiveZSetCommands.java    From redisson with Apache License 2.0 5 votes vote down vote up
String toLowerBound(Range range) {
    StringBuilder s = new StringBuilder();
    if (!range.getLowerBound().isInclusive()) {
        s.append("(");
    }
    if (!range.getLowerBound().getValue().isPresent() || range.getLowerBound().getValue().get().toString().isEmpty()) {
        s.append("-inf");
    } else {
        s.append(range.getLowerBound().getValue().get());
    }
    return s.toString();
}
 
Example #27
Source File: RedissonReactiveZSetCommands.java    From redisson with Apache License 2.0 5 votes vote down vote up
String toUpperBound(Range range) {
    StringBuilder s = new StringBuilder();
    if (!range.getUpperBound().isInclusive()) {
        s.append("(");
    }
    if (!range.getUpperBound().getValue().isPresent() || range.getUpperBound().getValue().get().toString().isEmpty()) {
        s.append("+inf");
    } else {
        s.append(range.getUpperBound().getValue().get());
    }
    return s.toString();
}
 
Example #28
Source File: RedissonReactiveZSetCommands.java    From redisson with Apache License 2.0 5 votes vote down vote up
String toLexLowerBound(Range range, Object defaultValue) {
    StringBuilder s = new StringBuilder();
    if (range.getLowerBound().isInclusive()) {
        s.append("[");
    } else {
        s.append("(");
    }
    if (!range.getLowerBound().getValue().isPresent() || range.getLowerBound().getValue().get().toString().isEmpty()) {
        s.append(defaultValue);
    } else {
        s.append(range.getLowerBound().getValue().get());
    }
    return s.toString();
}
 
Example #29
Source File: RedissonReactiveZSetCommands.java    From redisson with Apache License 2.0 5 votes vote down vote up
String toLexUpperBound(Range range, Object defaultValue) {
    StringBuilder s = new StringBuilder();
    if (range.getUpperBound().isInclusive()) {
        s.append("[");
    } else {
        s.append("(");
    }
    if (!range.getUpperBound().getValue().isPresent() || range.getUpperBound().getValue().get().toString().isEmpty()) {
        s.append(defaultValue);
    } else {
        s.append(range.getUpperBound().getValue().get());
    }
    return s.toString();
}
 
Example #30
Source File: RedissonReactiveZSetCommands.java    From redisson with Apache License 2.0 5 votes vote down vote up
String toLowerBound(Range range) {
    StringBuilder s = new StringBuilder();
    if (!range.getLowerBound().isInclusive()) {
        s.append("(");
    }
    if (!range.getLowerBound().getValue().isPresent() || range.getLowerBound().getValue().get().toString().isEmpty()) {
        s.append("-inf");
    } else {
        s.append(range.getLowerBound().getValue().get());
    }
    return s.toString();
}