org.springframework.data.domain.Range.Bound Java Examples

The following examples show how to use org.springframework.data.domain.Range.Bound. 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: 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 #4
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 #5
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 #6
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 #7
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 #8
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 #9
Source File: DerivedQueryCreatorTest.java    From spring-data with Apache License 2.0 4 votes vote down vote up
@Test
public void findByMultipleLocationsAndMultipleRegularFieldsTest() {
	final List<Customer> toBeRetrieved = new LinkedList<>();
	final Customer customer1 = new Customer("John", "", 0);
	customer1.setLocation(new int[] { 89, 0 });
	toBeRetrieved.add(customer1);
	final Customer customer2 = new Customer("Bob", "", 0);
	customer2.setLocation(new int[] { 0, 5 });
	toBeRetrieved.add(customer2);
	final Customer customer3 = new Customer("Peter", "Pen", 0);
	customer3.setLocation(new int[] { 0, 89 });
	toBeRetrieved.add(customer3);
	final Customer customer4 = new Customer("Jack", "Sparrow", 0);
	customer4.setLocation(new int[] { 70, 20 });
	toBeRetrieved.add(customer4);
	repository.saveAll(toBeRetrieved);
	final Customer customer5 = new Customer("Peter", "The Great", 0);
	customer5.setLocation(new int[] { 0, 89 });
	repository.save(customer5);
	final Customer customer6 = new Customer("Ballpoint", "Pen", 0);
	customer6.setLocation(new int[] { 0, 89 });
	repository.save(customer6);
	final Customer customer7 = new Customer("Jack", "Reacher", 0);
	customer7.setLocation(new int[] { 70, 20 });
	repository.save(customer7);
	final Customer customer8 = new Customer("Jack", "Sparrow", 0);
	customer8.setLocation(new int[] { 15, 65 });
	repository.save(customer8);
	final Customer customer9 = new Customer("Jack", "Sparrow", 0);
	customer9.setLocation(new int[] { 25, 75 });
	repository.save(customer9);
	final double distance = convertAngleToDistance(10);
	final Bound<Double> lowerBound = Bound.inclusive(convertAngleToDistance(10));
	final Bound<Double> upperBound = Bound.inclusive(convertAngleToDistance(20));
	final Range<Double> distanceRange = Range.of(lowerBound, upperBound);
	final List<Customer> retrieved = repository
			.findByNameOrLocationWithinOrNameAndSurnameOrNameAndLocationNearAndSurnameAndLocationWithin("John",
				new Point(0, 0), distance, "Peter", "Pen", "Jack", new Point(47, 63), "Sparrow", new Point(10, 60),
				distanceRange);
	assertTrue(equals(toBeRetrieved, retrieved, cmp, eq, false));
}
 
Example #10
Source File: Order.java    From salespoint with Apache License 2.0 3 votes vote down vote up
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);
	}