Commit a85b7b19 authored by Luna Riegel's avatar Luna Riegel
Browse files

Style: Rename functions and add JavaDoc

parent 670b2a9f
...@@ -225,60 +225,86 @@ public class EmbeddedDatabaseHandler { ...@@ -225,60 +225,86 @@ public class EmbeddedDatabaseHandler {
} }
/**
public List<GmlId> getBufferIntersectingObjects(CityObject co, double bufferSize) { * Retrieves a List of GmlIds of CityObjects that are candidates for a buffer collision with a given CityObject(subject),
return getBufferIntersectingObjects(co.getGmlId(), bufferSize); * meaning the candidate's bbox intersects the subject's buffered bbox.
public List<GmlId> getBufferCollisionCandidates(CityObject co, double bufferSize) { * @param subject the subject CityObject
return getBufferCollisionCandidates(co.getGmlId(), bufferSize); * @param bufferSize the buffer distance
* @return a List of GmlIds of buffer collision candidates
*/
public List<GmlId> getBufferCollisionCandidates(CityObject subject, double bufferSize) {
return getBufferCollisionCandidates(subject.getGmlId(), bufferSize);
} }
public List<GmlId> getBufferCollisionCandidates(GmlId gmlID, double bufferSize) { /**
* Retrieves a List of GmlIds of CityObjects that are candidates for a buffer collision with a given CityObject(subject),
* meaning the candidate's bbox intersects the subject's buffered bbox.
* @param subjectId the subject CityObject's GmlId
* @param bufferSize the buffer distance
* @return a List of GmlIds of buffer collision candidates
*/
public List<GmlId> getBufferCollisionCandidates(GmlId subjectId, double bufferSize) {
List<GmlId> intersectingObjects = new ArrayList<>(); List<GmlId> intersectingObjects = new ArrayList<>();
try (Connection con = dataSource.getConnection()) { try (Connection con = dataSource.getConnection()) {
try (PreparedStatement ps = con.prepareStatement("SELECT gmlid FROM features AS tab1" + try (PreparedStatement ps = con.prepareStatement("SELECT gmlid FROM features AS tab1" +
" WHERE ST_INTERSECTS(ST_BUFFER(tab1.bbox,?), (SELECT bbox FROM features WHERE gmlid = ?)) " + " WHERE ST_INTERSECTS(ST_BUFFER(tab1.bbox,?), (SELECT bbox FROM features WHERE gmlid = ?)) " +
"AND tab1.gmlid <> ?")) { "AND tab1.gmlid <> ?")) {
ps.setDouble(1, bufferSize); ps.setDouble(1, bufferSize);
ps.setString(2, gmlID.toString()); ps.setString(2, subjectId.toString());
ps.setString(3, gmlID.toString()); ps.setString(3, subjectId.toString());
ResultSet rs = ps.executeQuery(); ResultSet rs = ps.executeQuery();
while (rs.next()) { while (rs.next()) {
intersectingObjects.add(new GmlId(rs.getString("gmlid"))); intersectingObjects.add(new GmlId(rs.getString("gmlid")));
} }
} }
} catch (SQLException e) { } catch (SQLException e) {
logger.error(Localization.getText("DatabaseHandler.getBufferIntersectFailure"),gmlID); logger.error(Localization.getText("DatabaseHandler.getBufferIntersectFailure"),subjectId);
logger.debug(e.getMessage()); logger.debug(e.getMessage());
} }
return intersectingObjects; return intersectingObjects;
} }
public List<GmlId> getBBoxCollisionCandidates(CityObject co) { /**
return getBBoxCollisionCandidates(co.getGmlId()); * Retrieves a List of GmlIds of CityObjects that are candidates for a geometry collision with a given CityObject(subject),
* meaning the bounding boxes of candidate and subject intersect.
* @param subject the subject CityObject
* @return a List of GmlIds of buffer collision candidates
*/
public List<GmlId> getGeometryCollisionCandidates(CityObject subject) {
return getGeometryCollisionCandidates(subject.getGmlId());
} }
public List<GmlId> getBBoxCollisionCandidates(GmlId id) { /**
* Retrieves a List of GmlIds of CityObjects that are candidates for a geometry collision with a given CityObject(subject),
* meaning the bounding boxes of candidate and subject intersect.
* @param subjectId the subject CityObject
* @return a List of GmlIds of buffer collision candidates
*/
public List<GmlId> getGeometryCollisionCandidates(GmlId subjectId) {
List<GmlId> intersectingObjects = new ArrayList<>(); List<GmlId> intersectingObjects = new ArrayList<>();
try (Connection con = dataSource.getConnection()) { try (Connection con = dataSource.getConnection()) {
try (PreparedStatement ps = con.prepareStatement("SELECT gmlid FROM features AS tab1" + try (PreparedStatement ps = con.prepareStatement("SELECT gmlid FROM features AS tab1" +
" WHERE ST_INTERSECTS(tab1.bbox, (SELECT bbox FROM features WHERE gmlid = ?)) AND tab1.gmlid <> ?")) " WHERE ST_INTERSECTS(tab1.bbox, (SELECT bbox FROM features WHERE gmlid = ?)) AND tab1.gmlid <> ?"))
{ {
ps.setString(1, id.toString()); ps.setString(1, subjectId.toString());
ps.setString(2, id.toString()); ps.setString(2, subjectId.toString());
ResultSet rs = ps.executeQuery(); ResultSet rs = ps.executeQuery();
while (rs.next()) { while (rs.next()) {
intersectingObjects.add(new GmlId(rs.getString("gmlid"))); intersectingObjects.add(new GmlId(rs.getString("gmlid")));
} }
} }
} catch (SQLException e) { } catch (SQLException e) {
logger.error(Localization.getText("DatabaseHandler.getBBoxIntersectFailure"),id); logger.error(Localization.getText("DatabaseHandler.getBBoxIntersectFailure"),subjectId);
logger.debug(e.getMessage()); logger.debug(e.getMessage());
} }
return intersectingObjects; return intersectingObjects;
} }
/**
* Returns the number of top-level CityObjects entries that are currently in the embedded database.
* @return the count of top-level CityObjects in the database
*/
public int getFeatureCount() { public int getFeatureCount() {
int count = -1; int count = -1;
......
...@@ -27,7 +27,7 @@ import static org.junit.Assert.assertEquals; ...@@ -27,7 +27,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
public class DataBaseHandlerTest { public class EmbeddedDataBaseHandlerTest {
private EmbeddedDatabaseHandler handler; private EmbeddedDatabaseHandler handler;
...@@ -112,7 +112,7 @@ public class DataBaseHandlerTest { ...@@ -112,7 +112,7 @@ public class DataBaseHandlerTest {
handler.marshallCityObject(b4); handler.marshallCityObject(b4);
assertEquals(4, handler.getFeatureCount()); assertEquals(4, handler.getFeatureCount());
List<GmlId> objects = handler.getBBoxCollisionCandidates(b); List<GmlId> objects = handler.getGeometryCollisionCandidates(b);
assertEquals(1, objects.size()); assertEquals(1, objects.size());
assertEquals(4, handler.getFeatureCount()); assertEquals(4, handler.getFeatureCount());
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment