Java Code Examples for org.springframework.data.domain.Range.Bound#inclusive()

The following examples show how to use org.springframework.data.domain.Range.Bound#inclusive() . 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: 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 4
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));
}