Search in sources :

Example 1 with PointImpl

use of il.ac.technion.cs.yp.btw.classes.PointImpl 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;
}
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) 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 PointImpl

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

the class QueryAllCentralLocations method arrangeRecievedData.

/*
    * @author Sharon Hadar
     * @Date 21/01/2018
     * get the results fro the data base and construct the match centeral locations
     * */
@Override
public Set<CentralLocation> arrangeRecievedData(ResultSet resultSet) {
    Set<CentralLocation> centralLocations = new HashSet();
    try {
        while (resultSet.next()) {
            String nameID = resultSet.getString("nameID");
            String street = resultSet.getString("street");
            int cord1x = resultSet.getInt("cord1x");
            int cord2x = resultSet.getInt("cord2x");
            int cord3x = resultSet.getInt("cord3x");
            int cord4x = resultSet.getInt("cord4x");
            int cord1y = resultSet.getInt("cord1y");
            int cord2y = resultSet.getInt("cord2y");
            int cord3y = resultSet.getInt("cord3y");
            int cord4y = resultSet.getInt("cord4y");
            Set<Point> points = new HashSet<Point>();
            points.add(new PointImpl(cord1x, cord1y));
            points.add(new PointImpl(cord2x, cord2y));
            points.add(new PointImpl(cord3x, cord3y));
            points.add(new PointImpl(cord4x, cord4y));
            CentralLocation centralLocation = new DataCentralLocation(points, nameID, street, mapName);
            centralLocations.add(centralLocation);
        }
    } catch (SQLException e) {
        logger.error("query has failed");
    }
    return centralLocations;
}
Also used : DataCentralLocation(il.ac.technion.cs.yp.btw.db.DataObjects.DataCentralLocation) SQLException(java.sql.SQLException) CentralLocation(il.ac.technion.cs.yp.btw.classes.CentralLocation) DataCentralLocation(il.ac.technion.cs.yp.btw.db.DataObjects.DataCentralLocation) 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 3 with PointImpl

use of il.ac.technion.cs.yp.btw.classes.PointImpl 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 4 with PointImpl

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

the class TestDataCentralLocation method testCentralLocation.

/*
     * @author Sharon Hadar
     * @Date 21/01/2018*/
@Test
public void testCentralLocation() {
    Point a = new PointImpl(3, 4);
    Point b = new PointImpl(1, 2);
    Set<Point> points = new HashSet<Point>();
    points.add(a);
    points.add(b);
    CentralLocation cl = new DataCentralLocation(points, "Bank", "Namir", "try");
    String s = cl.toString();
    String sn = cl.getName();
    Assert.assertTrue(s.contains(sn));
}
Also used : DataCentralLocation(il.ac.technion.cs.yp.btw.db.DataObjects.DataCentralLocation) CentralLocation(il.ac.technion.cs.yp.btw.classes.CentralLocation) DataCentralLocation(il.ac.technion.cs.yp.btw.db.DataObjects.DataCentralLocation) Point(il.ac.technion.cs.yp.btw.classes.Point) PointImpl(il.ac.technion.cs.yp.btw.classes.PointImpl) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 5 with PointImpl

use of il.ac.technion.cs.yp.btw.classes.PointImpl 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.getName().equals("Road6"));
    Assert.assertTrue(b.getName().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"));
    Assert.assertNull(((DataRoad) a).getWeights());
    Assert.assertNotNull(((DataRoad) a).getDistances());
    // Assert.assertTrue(a.getSpeed()>-1 && a.getSpeed() <1);
    // Assert.assertTrue(a.getOverload()>-1 && a.getOverload() <1);
    Assert.assertTrue(s2.contains("STR2"));
    System.out.println(a.getWeightByTime(BTWTime.of(0)).seconds());
}
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

PointImpl (il.ac.technion.cs.yp.btw.classes.PointImpl)13 Point (il.ac.technion.cs.yp.btw.classes.Point)12 SQLException (java.sql.SQLException)10 HashSet (java.util.HashSet)9 Road (il.ac.technion.cs.yp.btw.classes.Road)4 TrafficLight (il.ac.technion.cs.yp.btw.classes.TrafficLight)4 DataRoad (il.ac.technion.cs.yp.btw.db.DataObjects.DataRoad)4 DataTrafficLight (il.ac.technion.cs.yp.btw.db.DataObjects.DataTrafficLight)4 CentralLocation (il.ac.technion.cs.yp.btw.classes.CentralLocation)3 DataCentralLocation (il.ac.technion.cs.yp.btw.db.DataObjects.DataCentralLocation)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 DataStreet (il.ac.technion.cs.yp.btw.db.DataObjects.DataStreet)1