use of il.ac.technion.cs.yp.btw.db.DataObjects.DataTrafficLight in project BTW by TechnionYearlyProject.
the class QueryTrafficLightExample method arrangeRecievedData.
/*
* @author Sharon Hadar
* @Date 21/01/2018*/
@Override
public Set<TrafficLight> arrangeRecievedData(ResultSet resultSet) {
Set<TrafficLight> trafficLights = new HashSet();
try {
while (resultSet.next()) {
String nameID = resultSet.getString("nameID");
int cordx = resultSet.getInt("cordx");
int cordy = resultSet.getInt("cordy");
String sourceRoadId = nameID.split("-")[1];
// resultSet.getString("from");
String destinationRoadIf = nameID.split("-")[2];
// resultSet.getString("to");
long overload = resultSet.getLong("overload");
Point position = new PointImpl(cordx, cordy);
TrafficLight trafficLight = new DataTrafficLight(nameID, position, sourceRoadId, destinationRoadIf, overload, mapName);
System.out.println(trafficLight.toString());
trafficLights.add(trafficLight);
}
} catch (SQLException e) {
System.out.println("query has failed");
}
return trafficLights;
}
use of il.ac.technion.cs.yp.btw.db.DataObjects.DataTrafficLight in project BTW by TechnionYearlyProject.
the class TestDataTrafficLight method testGetParameters.
/**
* @Autor: Shay
* @Date: 15/6/18
* DataTrafficLight unit test
*/
@Test
public void testGetParameters() {
BTWDataBase btw = new BTWDataBaseImpl("test1");
btw.loadMap();
Set<TrafficLight> tls = btw.getAllTrafficLights();
for (TrafficLight tl : tls) {
if (tl.getName().equals("from:cc to:dd")) {
Assert.assertTrue(tl.getCoordinateX() == 0.0);
Assert.assertTrue(tl.getCoordinateY() == 0.0);
Assert.assertTrue(tl.getMinimumWeight().seconds() == 4647);
}
if (tl.getName().equals("from:aa to:bb")) {
Assert.assertTrue(tl.getCoordinateX() == 0.0);
Assert.assertTrue(tl.getCoordinateY() == 0.0);
Assert.assertTrue(tl.getMinimumWeight().seconds() == 435345445);
}
if (tl.getName().equals("from:bb to:ee")) {
Assert.assertTrue(tl.getCoordinateX() == 2.0);
Assert.assertTrue(tl.getCoordinateY() == 0.0);
Assert.assertTrue(tl.getMinimumWeight().seconds() == 4647);
}
}
}
use of il.ac.technion.cs.yp.btw.db.DataObjects.DataTrafficLight 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) {
logger.error("query trafficlight has failed");
}
return trafficLight;
}
use of il.ac.technion.cs.yp.btw.db.DataObjects.DataTrafficLight in project BTW by TechnionYearlyProject.
the class TestDataTrafficLight method testConstruct.
/**
* @Autor: Shay
* @Date: 15/6/18
* DataTrafficLight unit test
*/
@Test
public void testConstruct() {
DataTrafficLight tl = new DataTrafficLight("tl12009", new PointImpl(2, 5.12313), "aa", "cc", 239732623, "test1");
BTWDataBase b = new BTWDataBaseImpl("test1");
b.loadMap();
String rd = tl.getDestinationRoadName();
String rs = tl.getSourceRoadName();
Assert.assertNotNull(rd);
Assert.assertNotNull(rs);
String s = tl.toString();
try {
BTWTime time = BTWTime.of(44);
Assert.assertTrue(tl.getWeightByTime(time).seconds() == 0);
} catch (BTWIllegalTimeException e) {
}
Assert.assertTrue(s.contains("tl12009"));
}
use of il.ac.technion.cs.yp.btw.db.DataObjects.DataTrafficLight 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;
}
Aggregations