Search in sources :

Example 1 with CentralLocation

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

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

the class QueryTrafficLightExample method testGetAllCenteralLocations.

/*
     * @author Sharon Hadar
     * @Date 21/01/2018*/
@Test
public void testGetAllCenteralLocations() {
    TestResult result = new TestResult();
    MainDataBase.openConnection();
    Query query = new QueryCenteralLocationExample("first");
    // MainDataBase database = new MainDataBase();
    // Set<CentralLocation> centeralLocations = (Set<CentralLocation>) database.queryDataBase(query);
    Set<CentralLocation> centeralLocations = (Set<CentralLocation>) MainDataBase.queryDataBase(query);
    Iterator<CentralLocation> iterator = centeralLocations.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) CentralLocation(il.ac.technion.cs.yp.btw.classes.CentralLocation) TestResult(junit.framework.TestResult) Test(org.junit.Test)

Example 3 with CentralLocation

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

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

the class QueryCentralLocation method arrangeRecievedData.

/*
     * @author Sharon Hadar
     * @Date 21/01/2018
     * construct a centeral location from the data base results*/
@Override
public CentralLocation arrangeRecievedData(ResultSet resultSet) {
    CentralLocation centralLocation = null;
    try {
        // check if it is necessary.
        resultSet.next();
        String nameID = resultSet.getString("nameID");
        String street = resultSet.getString("street");
        double cord1x = resultSet.getDouble("cord1x");
        double cord2x = resultSet.getDouble("cord2x");
        double cord3x = resultSet.getDouble("cord3x");
        double cord4x = resultSet.getDouble("cord4x");
        double cord1y = resultSet.getDouble("cord1y");
        double cord2y = resultSet.getDouble("cord2y");
        double cord3y = resultSet.getDouble("cord3y");
        double cord4y = resultSet.getDouble("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 = new DataCentralLocation(points, nameID, street, mapName);
    } catch (SQLException e) {
        logger.error("query central location has failed");
    }
    return centralLocation;
}
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) PointImpl(il.ac.technion.cs.yp.btw.classes.PointImpl) HashSet(java.util.HashSet)

Example 5 with CentralLocation

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

the class TestCenteralLocationDataBase method testGetCentralLocation.

/*
     * @author Sharon Hadar
     * @Date 21/01/2018*/
@Test
public void testGetCentralLocation() {
    // SELECT * FROM dbo.firstPlace WHERE nameID = 'GasStation'
    MainDataBase.openConnection();
    CentralLocation centralLocation = CentralLocationsDataBase.getCentralLocation("GasStation Paz", "first");
    assertNotNull(centralLocation);
    // System.out.println(centralLocation.toString());
    CentralLocation centralLocation2 = CentralLocationsDataBase.getCentralLocation("bankHapoalim", "first");
    assertNotNull(centralLocation2);
    // System.out.println(centralLocation2.toString());
    MainDataBase.closeConnection();
}
Also used : CentralLocation(il.ac.technion.cs.yp.btw.classes.CentralLocation) Test(org.junit.Test)

Aggregations

CentralLocation (il.ac.technion.cs.yp.btw.classes.CentralLocation)5 HashSet (java.util.HashSet)4 Point (il.ac.technion.cs.yp.btw.classes.Point)3 PointImpl (il.ac.technion.cs.yp.btw.classes.PointImpl)3 DataCentralLocation (il.ac.technion.cs.yp.btw.db.DataObjects.DataCentralLocation)3 Test (org.junit.Test)3 SQLException (java.sql.SQLException)2 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