Search in sources :

Example 1 with TrafficLight

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

the class TestTrafficLightDataBase method testGetAllTrafficLightsInPosition.

/*
     * @author Sharon Hadar
     * @Date 21/01/2018*/
@Test
public void testGetAllTrafficLightsInPosition() {
    MainDataBase.openConnection();
    Point position = new PointImpl(1, 1);
    Set<TrafficLight> allTrafficLights = TrafficLightsDataBase.getAllTrafficLights(position, "mapName");
    Iterator<TrafficLight> iterator = allTrafficLights.iterator();
    // System.out.println("\n\n\nthe result set is:");
    while (iterator.hasNext()) {
        assertNotNull(iterator.next());
    // System.out.println(iterator.next().toString());
    }
    MainDataBase.closeConnection();
}
Also used : TrafficLight(il.ac.technion.cs.yp.btw.classes.TrafficLight) Point(il.ac.technion.cs.yp.btw.classes.Point) PointImpl(il.ac.technion.cs.yp.btw.classes.PointImpl) Test(org.junit.Test)

Example 2 with TrafficLight

use of il.ac.technion.cs.yp.btw.classes.TrafficLight 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<TrafficLight> 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) {
        System.out.println("query has failed");
    }
    return trafficLights;
}
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) Point(il.ac.technion.cs.yp.btw.classes.Point) PointImpl(il.ac.technion.cs.yp.btw.classes.PointImpl) HashSet(java.util.HashSet)

Example 3 with TrafficLight

use of il.ac.technion.cs.yp.btw.classes.TrafficLight 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) {
        System.out.println("query 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 4 with TrafficLight

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

the class QueryTrafficLight method arrangeRecievedData.

/*
     * @author Sharon Hadar
     * @Date 21/01/2018
     * construct a traffic light by the result of the data base*/
@Override
public TrafficLight arrangeRecievedData(ResultSet resultSet) {
    TrafficLight trafficLight = null;
    try {
        resultSet.next();
        String nameID = resultSet.getString("nameID");
        double cordx = resultSet.getDouble("cordx");
        double cordy = resultSet.getDouble("cordy");
        String sourceRoadId = nameID.split("from:|to:")[1];
        String destinationRoadIf = nameID.split("to:")[1];
        long overload = resultSet.getLong("overload");
        Point position = new PointImpl(cordx, cordy);
        trafficLight = new DataTrafficLight(nameID, position, sourceRoadId, destinationRoadIf, overload, mapName);
    } catch (SQLException e) {
        System.out.println("query has failed");
    }
    return trafficLight;
}
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) Point(il.ac.technion.cs.yp.btw.classes.Point) PointImpl(il.ac.technion.cs.yp.btw.classes.PointImpl)

Example 5 with TrafficLight

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

the class QueryTrafficLightExample method testGetAllTrafficLights.

/*
     * @author Sharon Hadar
     * @Date 21/01/2018*/
@Test
public void testGetAllTrafficLights() {
    TestResult result = new TestResult();
    MainDataBase.openConnection();
    Query query = new QueryTrafficLightExample("first");
    // MainDataBase database = new MainDataBase();
    // Set<TrafficLight> trafficLights = (Set<TrafficLight>) database.queryDataBase(query);
    Set<TrafficLight> trafficLights = (Set<TrafficLight>) MainDataBase.queryDataBase(query);
    Iterator<TrafficLight> iterator = trafficLights.iterator();
    // System.out.println("\n\n\nthe result set is:");
    while (iterator.hasNext()) {
        assertNotNull(iterator.next());
    // System.out.println(iterator.next().toString());
    }
    MainDataBase.closeConnection();
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) ResultSet(java.sql.ResultSet) Query(il.ac.technion.cs.yp.btw.db.queries.Query) DataTrafficLight(il.ac.technion.cs.yp.btw.db.DataObjects.DataTrafficLight) TrafficLight(il.ac.technion.cs.yp.btw.classes.TrafficLight) TestResult(junit.framework.TestResult) Test(org.junit.Test)

Aggregations

TrafficLight (il.ac.technion.cs.yp.btw.classes.TrafficLight)6 Point (il.ac.technion.cs.yp.btw.classes.Point)4 PointImpl (il.ac.technion.cs.yp.btw.classes.PointImpl)4 DataTrafficLight (il.ac.technion.cs.yp.btw.db.DataObjects.DataTrafficLight)4 SQLException (java.sql.SQLException)3 HashSet (java.util.HashSet)3 Test (org.junit.Test)3 Crossroad (il.ac.technion.cs.yp.btw.classes.Crossroad)1 DataCrossRoad (il.ac.technion.cs.yp.btw.db.DataObjects.DataCrossRoad)1 Query (il.ac.technion.cs.yp.btw.db.queries.Query)1 ResultSet (java.sql.ResultSet)1 Set (java.util.Set)1 TestResult (junit.framework.TestResult)1