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();
}
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;
}
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;
}
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;
}
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();
}
Aggregations