use of org.onebusaway.geospatial.model.CoordinateBounds in project onebusaway-application-modules by camsys.
the class DynamicFederatedServiceCollectionImplTest method addServiceServlet.
private SimpleFederatedServiceImpl addServiceServlet(Server server, String agencyId, CoordinateBounds bounds) {
Map<String, List<CoordinateBounds>> agenciesA = new HashMap<String, List<CoordinateBounds>>();
agenciesA.put(agencyId, Arrays.asList(bounds));
SimpleFederatedServiceImpl serviceA = new SimpleFederatedServiceImpl(agenciesA, agencyId);
HessianServlet servletA = new HessianServlet();
servletA.setHome(serviceA);
servletA.setHomeAPI(SimpleFederatedService.class);
Context contextA = new Context(server, "/service-" + agencyId, Context.SESSIONS);
contextA.addServlet(new ServletHolder(servletA), "/*");
return serviceA;
}
use of org.onebusaway.geospatial.model.CoordinateBounds in project onebusaway-application-modules by camsys.
the class FederatedServiceLibrary method checkAgencyAndCoverageAgainstExisting.
/**
* Given an existing set of {@link FederatedService} instances along with
* their set of agency ids and geographic bounds, examine an additional agency
* id and coverage area from another service instance and verify that there is
* no overlap.
*
* @param byProvider existing {@link FederatedService} instances along with
* their agency ids and coverage areas
* @param agencyId a new agency id to check
* @param coverage the coverage area for that agency
* @param serviceInterface the target service interface
* @param failHard throw an exception if overlap is found
* @return true if there is no overlap (good), other false (bad)
*/
public static boolean checkAgencyAndCoverageAgainstExisting(Map<FederatedService, Map<String, List<CoordinateBounds>>> byProvider, String agencyId, List<CoordinateBounds> coverage, Class<?> serviceInterface, boolean failHard) {
for (Map<String, List<CoordinateBounds>> other : byProvider.values()) {
// elsewhere
if (other.containsKey(agencyId)) {
if (failHard)
throw new IllegalArgumentException("agency \"" + agencyId + "\" is handled by multiple providers for service " + serviceInterface.getName());
else
return false;
}
// another provider
for (Map.Entry<String, List<CoordinateBounds>> otherEntry : other.entrySet()) {
String otherAgencyId = otherEntry.getKey();
List<CoordinateBounds> otherCoverage = otherEntry.getValue();
for (CoordinateBounds otherRectangle : otherCoverage) {
for (CoordinateBounds rectangle : coverage) {
if (rectangle.intersects(otherRectangle)) {
if (failHard)
throw new IllegalArgumentException("agency \"" + agencyId + "\" has overlap with agency \"" + otherAgencyId + "\" in separate service providers of type " + serviceInterface.getName());
else
return false;
}
}
}
}
}
return true;
}
use of org.onebusaway.geospatial.model.CoordinateBounds in project onebusaway-application-modules by camsys.
the class FederatedByCoordinateBoundsMethodInvocationHandlerImplTest method test02.
@Test
public void test02() throws Exception {
CoordinateBounds bounds = new CoordinateBounds(0, 1, 2, 3);
CoordinateBoundsTestBean bean = new CoordinateBoundsTestBean();
bean.setBounds(bounds);
SimpleFederatedService mockService = Mockito.mock(SimpleFederatedService.class);
FederatedServiceCollection mockCollection = Mockito.mock(FederatedServiceCollectionImpl.class);
Mockito.when(mockCollection.getServiceForBounds(bounds)).thenReturn(mockService);
Method method = SimpleFederatedService.class.getDeclaredMethod("getValueForCoordinateBoundsTestBean", CoordinateBoundsTestBean.class);
Object[] args = { bean };
FederatedServiceMethodInvocationHandler handler = new FederatedByCoordinateBoundsMethodInvocationHandlerImpl(method, 0, "bounds");
handler.invoke(mockCollection, method, args);
Mockito.verify(mockService).getValueForCoordinateBoundsTestBean(bean);
}
use of org.onebusaway.geospatial.model.CoordinateBounds in project onebusaway-application-modules by camsys.
the class HierarchicalSTRtreeFactory method create.
public HierarchicalSTRtree<T> create() {
STRtree parentTree = new STRtree();
for (Map.Entry<CoordinateBounds, STRtree> entry : _treesByBounds.entrySet()) {
CoordinateBounds b = entry.getKey();
Envelope env = new Envelope(b.getMinLon(), b.getMaxLon(), b.getMinLat(), b.getMaxLat());
STRtree tree = entry.getValue();
tree.build();
parentTree.insert(env, tree);
}
parentTree.build();
return new HierarchicalSTRtree<T>(parentTree);
}
use of org.onebusaway.geospatial.model.CoordinateBounds in project onebusaway-application-modules by camsys.
the class HierarchicalSTRtreeFactory method setLatAndLonStep.
public void setLatAndLonStep(double lat, double lon, double gridSize) {
CoordinateBounds b = SphericalGeometryLibrary.bounds(lat, lon, gridSize / 2);
_latStep = b.getMaxLat() - b.getMinLat();
_lonStep = b.getMaxLon() - b.getMinLon();
}
Aggregations