Search in sources :

Example 1 with DataStreet

use of il.ac.technion.cs.yp.btw.db.DataObjects.DataStreet in project BTW by TechnionYearlyProject.

the class QueryStreet method arrangeRecievedData.

/*
     * @author Sharon Hadar
     * @Date 21/01/2018
     * construct a street from the result of the data base*/
@Override
public Street arrangeRecievedData(ResultSet resultSet) {
    Set<Road> roads = new HashSet();
    try {
        while (resultSet.next()) {
            String nameID = resultSet.getString("nameID");
            int cord1x = resultSet.getInt("cord1x");
            int cord2x = resultSet.getInt("cord2x");
            int cord1y = resultSet.getInt("cord1y");
            int cord2y = resultSet.getInt("cord2y");
            int length = resultSet.getInt("length");
            int secStart = resultSet.getInt("secStart");
            int secEnd = resultSet.getInt("secEnd");
            long overload = resultSet.getLong("overload");
            String myStreet = nameID.split("st")[0];
            Point sourceCrossroadId = new PointImpl(cord1x, cord1y);
            Point destinationCrossroadId = new PointImpl(cord2x, cord2y);
            Road road = new DataRoad(nameID, length, myStreet, sourceCrossroadId, destinationCrossroadId, secStart, secEnd, overload, mapName);
            roads.add(road);
        }
    } catch (SQLException e) {
        System.out.println("query has failed");
    }
    return new DataStreet(streetName, roads, mapName);
}
Also used : DataStreet(il.ac.technion.cs.yp.btw.db.DataObjects.DataStreet) SQLException(java.sql.SQLException) Road(il.ac.technion.cs.yp.btw.classes.Road) DataRoad(il.ac.technion.cs.yp.btw.db.DataObjects.DataRoad) DataRoad(il.ac.technion.cs.yp.btw.db.DataObjects.DataRoad) Point(il.ac.technion.cs.yp.btw.classes.Point) Point(il.ac.technion.cs.yp.btw.classes.Point) PointImpl(il.ac.technion.cs.yp.btw.classes.PointImpl) HashSet(java.util.HashSet)

Example 2 with DataStreet

use of il.ac.technion.cs.yp.btw.db.DataObjects.DataStreet in project BTW by TechnionYearlyProject.

the class TestDataStreet method testGet.

@Test
public void testGet() {
    Road r1 = new TestingRoad("r1", null, null);
    Road r2 = new TestingRoad("r2", null, null);
    Road r3 = new TestingRoad("r3", null, null);
    Set<Road> roads = new HashSet<Road>();
    roads.add(r1);
    roads.add(r2);
    Street street = new DataStreet("Alenbi", roads, "try");
    Street street2 = new DataStreet("Rotchild", "try");
    street.addRoad(r3);
    Assert.assertTrue(street2.getAllRoadsInStreet().size() == 0);
    Assert.assertTrue(street.getAllRoadsInStreet().size() == 3);
    Assert.assertTrue(street.getStreetName().equals("Alenbi"));
    String s = street.toString();
    String s2 = street2.toString();
    Assert.assertTrue(s.contains("Alenbi"));
    Assert.assertTrue(s2.contains("Rotchild"));
}
Also used : DataStreet(il.ac.technion.cs.yp.btw.db.DataObjects.DataStreet) DataStreet(il.ac.technion.cs.yp.btw.db.DataObjects.DataStreet) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

DataStreet (il.ac.technion.cs.yp.btw.db.DataObjects.DataStreet)2 HashSet (java.util.HashSet)2 Point (il.ac.technion.cs.yp.btw.classes.Point)1 PointImpl (il.ac.technion.cs.yp.btw.classes.PointImpl)1 Road (il.ac.technion.cs.yp.btw.classes.Road)1 DataRoad (il.ac.technion.cs.yp.btw.db.DataObjects.DataRoad)1 SQLException (java.sql.SQLException)1 Test (org.junit.Test)1