Search in sources :

Example 11 with Point

use of il.ac.technion.cs.yp.btw.classes.Point in project BTW by TechnionYearlyProject.

the class QueryAllTrafficLightPositions method arrangeRecievedData.

/*
     * @author Sharon Hadar
     * @Date 21/01/2018
     * construct a traffic light by results from the data base*/
@Override
public Set<Point> arrangeRecievedData(ResultSet resultSet) {
    Set<Point> positions = new HashSet();
    try {
        while (resultSet.next()) {
            double cordx = resultSet.getDouble("cordx");
            double cordy = resultSet.getDouble("cordy");
            Point position = new PointImpl(cordx, cordy);
            positions.add(position);
        }
    } catch (SQLException e) {
        logger.error("query all trafficlights positions has failed");
    }
    return positions;
}
Also used : SQLException(java.sql.SQLException) Point(il.ac.technion.cs.yp.btw.classes.Point) PointImpl(il.ac.technion.cs.yp.btw.classes.PointImpl) HashSet(java.util.HashSet)

Example 12 with Point

use of il.ac.technion.cs.yp.btw.classes.Point in project BTW by TechnionYearlyProject.

the class QueryCrossRoad method arrangeRecievedData.

/*
    * @author Sharon Hadar
    * @Date 21/01/2018
    * construct a cross road from the data base results
    * */
@Override
public Crossroad arrangeRecievedData(ResultSet resultSet) {
    Set<TrafficLight> trafficLights = new HashSet();
    try {
        while (resultSet.next()) {
            String nameID = resultSet.getString("nameID");
            double cordx = resultSet.getDouble("cordx");
            double cordy = resultSet.getDouble("cordy");
            String sourceRoadId = nameID.split("from:|to:")[1];
            // resultSet.getString("from");
            String destinationRoadIf = nameID.split("to:")[1];
            // resultSet.getString("to");
            long overload = resultSet.getLong("overload");
            Point position = new PointImpl(cordx, cordy);
            TrafficLight trafficLight = new DataTrafficLight(nameID, position, sourceRoadId, destinationRoadIf, overload, mapName);
            trafficLights.add(trafficLight);
        }
    } catch (SQLException e) {
        logger.error("queryCrossRoad has failed");
    }
    Crossroad crossRoad = new DataCrossRoad(this.position, trafficLights, mapName);
    return crossRoad;
}
Also used : DataTrafficLight(il.ac.technion.cs.yp.btw.db.DataObjects.DataTrafficLight) SQLException(java.sql.SQLException) DataTrafficLight(il.ac.technion.cs.yp.btw.db.DataObjects.DataTrafficLight) TrafficLight(il.ac.technion.cs.yp.btw.classes.TrafficLight) Crossroad(il.ac.technion.cs.yp.btw.classes.Crossroad) Point(il.ac.technion.cs.yp.btw.classes.Point) DataCrossRoad(il.ac.technion.cs.yp.btw.db.DataObjects.DataCrossRoad) PointImpl(il.ac.technion.cs.yp.btw.classes.PointImpl) HashSet(java.util.HashSet)

Example 13 with Point

use of il.ac.technion.cs.yp.btw.classes.Point 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) {
        logger.error("query Road 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 14 with Point

use of il.ac.technion.cs.yp.btw.classes.Point in project BTW by TechnionYearlyProject.

the class QueryAllRoads method arrangeRecievedData.

/*
     * @author Sharon Hadar
     * @Date 21/01/2018
     * construct a road by the information recieved from the data base
     * */
@Override
public Set<Road> arrangeRecievedData(ResultSet resultSet) {
    Set<Road> roads = new HashSet();
    try {
        while (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 road = new DataRoad(nameID, length, myStreet, sourceCrossroadId, destinationCrossroadId, secStart, secEnd, overload, mapName);
            roads.add(road);
        }
    } catch (SQLException e) {
        logger.error("query all roads has failed");
    }
    return roads;
}
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) HashSet(java.util.HashSet)

Example 15 with Point

use of il.ac.technion.cs.yp.btw.classes.Point in project BTW by TechnionYearlyProject.

the class QueryAllTrafficLights method arrangeRecievedData.

/*
    * @author Sharon Hadar
    * @Date 21/01/2018
    * build the recieved data from the data base results
    * */
@Override
public Set<DataTrafficLight> arrangeRecievedData(ResultSet resultSet) {
    Set<DataTrafficLight> trafficLights = new HashSet();
    try {
        while (resultSet.next()) {
            String nameID = resultSet.getString("nameID");
            double cordx = resultSet.getDouble("cordx");
            double cordy = resultSet.getDouble("cordy");
            String sourceRoadId = nameID.split("from:| to:")[1];
            // resultSet.getString("from");
            String destinationRoadIf = nameID.split(" to:")[1];
            // resultSet.getString("to");
            long overload = resultSet.getLong("overload");
            Point position = new PointImpl(cordx, cordy);
            DataTrafficLight trafficLight = new DataTrafficLight(nameID, position, sourceRoadId, destinationRoadIf, overload, mapName);
            trafficLights.add(trafficLight);
        }
    } catch (SQLException e) {
        logger.error("query all trafficlights failed");
    }
    return trafficLights;
}
Also used : DataTrafficLight(il.ac.technion.cs.yp.btw.db.DataObjects.DataTrafficLight) SQLException(java.sql.SQLException) Point(il.ac.technion.cs.yp.btw.classes.Point) PointImpl(il.ac.technion.cs.yp.btw.classes.PointImpl) HashSet(java.util.HashSet)

Aggregations

Point (il.ac.technion.cs.yp.btw.classes.Point)17 PointImpl (il.ac.technion.cs.yp.btw.classes.PointImpl)12 SQLException (java.sql.SQLException)10 HashSet (java.util.HashSet)10 TrafficLight (il.ac.technion.cs.yp.btw.classes.TrafficLight)5 DataRoad (il.ac.technion.cs.yp.btw.db.DataObjects.DataRoad)5 DataTrafficLight (il.ac.technion.cs.yp.btw.db.DataObjects.DataTrafficLight)5 Road (il.ac.technion.cs.yp.btw.classes.Road)4 CentralLocation (il.ac.technion.cs.yp.btw.classes.CentralLocation)3 DataCentralLocation (il.ac.technion.cs.yp.btw.db.DataObjects.DataCentralLocation)3 JsonArray (com.google.gson.JsonArray)2 JsonElement (com.google.gson.JsonElement)2 Crossroad (il.ac.technion.cs.yp.btw.classes.Crossroad)2 DataCrossRoad (il.ac.technion.cs.yp.btw.db.DataObjects.DataCrossRoad)2 Pair (javafx.util.Pair)2 Test (org.junit.Test)2 JsonObject (com.google.gson.JsonObject)1 JsonParser (com.google.gson.JsonParser)1 CityRoad (il.ac.technion.cs.yp.btw.citysimulation.CityRoad)1 CityTrafficLight (il.ac.technion.cs.yp.btw.citysimulation.CityTrafficLight)1