Search in sources :

Example 1 with DataRoad

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

the class QueryTrafficLightExample method arrangeRecievedData.

/*
     * @author Sharon Hadar
     * @Date 21/01/2018*/
@Override
public Set<Road> 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");
            String overload = resultSet.getString("overload");
            System.out.println("nameID = " + nameID + " cord1x = " + cord1x + " cord2x = " + cord2x + " cord1y = " + cord1y + " cord2y = " + cord2y + " length = " + length + " secStart = " + secStart + " secEnd = " + secEnd + " overload = " + 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, mapName);
            System.out.println(road.toString());
            roads.add(road);
        }
    } catch (SQLException e) {
        System.out.println("query has failed");
    }
    return roads;
}
Also used : SQLException(java.sql.SQLException) DataRoad(il.ac.technion.cs.yp.btw.db.DataObjects.DataRoad) Road(il.ac.technion.cs.yp.btw.classes.Road) 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 DataRoad

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

the class BTWDataBaseImpl method insertCrossRoadsToRoads.

/*
     * @author Sharon Hadar
     * @Date 21/01/2018*/
private void insertCrossRoadsToRoads() {
    // set.forEach(t -> map.put(t, t));
    Map<Point, Crossroad> crossRoadsOfLocation = new HashMap<>();
    this.crossRoads.forEach(crossRoad -> crossRoadsOfLocation.put(new PointImpl(crossRoad.getCoordinateX(), crossRoad.getCoordinateY()), crossRoad));
    // Iterator<Road> roadIterator = this.roads.iterator();
    for (Road road : this.roads) {
        Point sourcePosition = ((DataRoad) road).getSourceCrossroadPosition();
        ((DataRoad) road).setSourceCrossRoad(crossRoadsOfLocation.get(sourcePosition));
        Point destinationPosition = ((DataRoad) road).getDestinationCrossroadPosition();
        ((DataRoad) road).setDestinationCrossRoad(crossRoadsOfLocation.get(destinationPosition));
    }
}
Also used : DataCrossRoad(il.ac.technion.cs.yp.btw.db.DataObjects.DataCrossRoad) DataRoad(il.ac.technion.cs.yp.btw.db.DataObjects.DataRoad) DataRoad(il.ac.technion.cs.yp.btw.db.DataObjects.DataRoad)

Example 3 with DataRoad

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

the class QueryRoad method arrangeRecievedData.

/*
     * @author Sharon Hadar
     * @Date 21/01/2018
     * construct a road by the results from the data base*/
@Override
public Road arrangeRecievedData(ResultSet resultSet) {
    Road road = null;
    try {
        resultSet.next();
        String nameID = resultSet.getString("nameID");
        double cord1x = resultSet.getDouble("cord1x");
        double cord2x = resultSet.getDouble("cord2x");
        double cord1y = resultSet.getDouble("cord1y");
        double cord2y = resultSet.getDouble("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 = new DataRoad(nameID, length, myStreet, sourceCrossroadId, destinationCrossroadId, secStart, secEnd, overload, mapName);
    } catch (SQLException e) {
        System.out.println("query has failed");
    }
    return road;
}
Also used : 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)

Example 4 with DataRoad

use of il.ac.technion.cs.yp.btw.db.DataObjects.DataRoad 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 5 with DataRoad

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

the class TestDataRoad method testConstructing.

@Test
public void testConstructing() {
    // first constructor
    Road a = new DataRoad("Road6", 3, "STR1", new PointImpl(0, 0), new PointImpl(6.6, 6.6), "try");
    // second constructor
    Road b = new DataRoad("Road4", 43346, "STR2", new PointImpl(11.32, 77.234), new PointImpl(6.6, 6.6), 0, 342, 235, "try");
    Assert.assertTrue(b.isStreetNumberInRange(100));
    Assert.assertFalse(b.isStreetNumberInRange(1000));
    Assert.assertTrue(a.getRoadName().equals("Road6"));
    Assert.assertTrue(b.getRoadName().equals("Road4"));
    Assert.assertTrue(a.getRoadLength() == 3);
    String s = a.toString();
    String s2 = b.toString();
    Assert.assertTrue(s.contains("Road6"));
    Assert.assertTrue(s2.contains("STR2"));
}
Also used : 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) PointImpl(il.ac.technion.cs.yp.btw.classes.PointImpl) Test(org.junit.Test)

Aggregations

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