Package my.beans

Examples of my.beans.TaxiDriver


   */
  public void init(ServletConfig config) throws ServletException {
    // TODO Auto-generated method stub
    taxiDrivers = new HashMap();

    TaxiDriver driver = new TaxiDriver("1", "John Doe", "1111", "4153381200", "0.00", "0.00");
    taxiDrivers.put("1", driver);

    driver = new TaxiDriver("2", "Jack Washington", "2222", "4153381201", "0.00", "0.00");
    taxiDrivers.put("2", driver);

    driver = new TaxiDriver("3", "Ken Peterson", "3333", "4153381202", "0.00", "0.00");
    taxiDrivers.put("3", driver);

    driver = new TaxiDriver("4", "John Doe", "4444", "4153381203", "0.00", "0.00");
    taxiDrivers.put("4", driver);

    driver = new TaxiDriver("5", "Kelly Clarkson", "5555", "4153381204", "0.00", "0.00");
    taxiDrivers.put("5", driver);

    driver = new TaxiDriver("6", "May Deng", "6666", "4153381205", "0.00", "0.00");
    taxiDrivers.put("6", driver);

  }
View Full Code Here


  protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
  {
    // TODO Auto-generated method stub
    String action = StringUtils.getTrimWhiteSpaces(request.getParameter("action"));
    String id = "";
    TaxiDriver driver = new TaxiDriver();

    String lat = StringUtils.getTrimWhiteSpaces(request.getParameter("lat"));
    String lon = StringUtils.getTrimWhiteSpaces(request.getParameter("lon"));

    if (action.equals("set"))
    {
      id = StringUtils.getTrimWhiteSpaces(request.getParameter("id"));

      driver = (TaxiDriver) taxiDrivers.get(id);

      if (driver != null)
      { 
        if (!lat.equals("") && !lon.equals(""))
        {
          driver.setCurrentLatitude(lat);
          driver.setCurrentLongitude(lon);

          taxiDrivers.put(id, driver);
        }
      }
    }
    else if (action.equals("json"))
    {
      String name = "";
      String phone = "";
      String locations = "";

      try
      {

        JSONObject responseObj = new JSONObject();     
        List<JSONObject> driverObjects = new LinkedList<JSONObject>();

        Iterator iterator = taxiDrivers.keySet().iterator();
        while (iterator.hasNext()) {
          id = (String) iterator.next();

          driver = (TaxiDriver) taxiDrivers.get(id);

          JSONObject driverObj = new JSONObject();

          driverObj.put("id", driver.getId());
          driverObj.put("name", driver.getName());
          driverObj.put("phone", driver.getPhoneNumber());

          List<JSONObject> locationObjects = new LinkedList<JSONObject>();
         
          JSONObject locationObj = new JSONObject();   
          locationObj.put("lat", driver.getCurrentLatitude());
          locationObjects.add(locationObj);
         
          locationObj = new JSONObject();
          locationObj.put("lon", driver.getCurrentLongitude());
          locationObjects.add(locationObj);

          driverObj.put("locations", locationObjects);
          driverObjects.add(driverObj);
        }

        responseObj.put("drivers", driverObjects);

        PrintWriter writer = response.getWriter();
        writer.write(responseObj.toString());
        writer.flush();
      }
      catch (Exception e)
      { 
        e.printStackTrace();
        throw new ServletException(e);
      }
    }
    else if (action.equals("html"))
    {
      String name = "";
      String phone = "";
      String locations = "";
     
      response.setContentType("text/html");
     
      PrintWriter out = response.getWriter();
     
      out.println("<html>");
      out.println("<head>");
      out.println("<title>Display All Driver GPS Location</title>");
      out.println("</head>");
      out.println("<body>");
      out.println("<table border='1' cellpadding='5' cellspacing='5'>");
      out.println("<tr>");
      out.println("<th>Driver ID</th>");
      out.println("<th>Name</th>");
      out.println("<th>Phone</th>");
      out.println("<th>Locations (lat/long)</th>");
      out.println("</tr>");
     
      Iterator iterator = taxiDrivers.keySet().iterator();
        while (iterator.hasNext()) {
          out.println("<tr>");
          id = (String) iterator.next();
         
          driver = (TaxiDriver) taxiDrivers.get(id);
          name = driver.getName();
          phone = driver.getPhoneNumber();
          locations = driver.getCurrentLatitude() + ";" + driver.getCurrentLongitude();
         
          out.println("<td align='center'>" + id + "</td>");
          out.println("<td align='center'>" + name + "</td>");
          out.println("<td align='center'>" + phone + "</td>");
          out.println("<td align='right'>" + locations + "</td>");
View Full Code Here

   */
  public void init(ServletConfig config) throws ServletException {
    // TODO Auto-generated method stub
taxiDrivers = new HashMap();
   
    TaxiDriver driver = new TaxiDriver("1", "John Doe", "1111", "4153381200", "37.720595", "-122.476080");
    taxiDrivers.put("1", driver);
 
    driver = new TaxiDriver("2", "Jack Washington", "2222", "4153381201", "37.742131", "-122.491682");
    taxiDrivers.put("2", driver);
   
    driver = new TaxiDriver("3", "Ken Peterson", "3333", "4153381202", "37.727977", "-122.476268");
    taxiDrivers.put("3", driver);
   
    driver = new TaxiDriver("4", "John Doe", "4444", "4153381203", "37.720678", "-122.480930");
    taxiDrivers.put("4", driver);
 
    driver = new TaxiDriver("5", "Kelly Clarkson", "5555", "4153381204", "37.746630", "-122.474682");
    taxiDrivers.put("5", driver);
   
    driver = new TaxiDriver("6", "May Deng", "6666", "4153381205", "37.732431", "-122.477482");
    taxiDrivers.put("6", driver);

  }
View Full Code Here

  protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    // TODO Auto-generated method stub
   
    String action = StringUtils.getTrimWhiteSpaces(request.getParameter("action"));
    String id = "";
    TaxiDriver driver = new TaxiDriver();
    Gson gson = new Gson();
    
    String lat = StringUtils.getTrimWhiteSpaces(request.getParameter("lat"));
    String lon = StringUtils.getTrimWhiteSpaces(request.getParameter("lon"));
   
    if (action.equals("set"))
    {
      id = StringUtils.getTrimWhiteSpaces(request.getParameter("id"));
     
      driver = (TaxiDriver) taxiDrivers.get(id);
     
      if (driver != null)
      { 
        if (!lat.equals("") && !lon.equals(""))
        {
          driver.setCurrentLatitude(lat);
          driver.setCurrentLongitude(lon);
       
          taxiDrivers.put(id, driver);
        }
      }
    }
    else if (action.equals("json"))
    {
      String name = "";
      String phone = "";
      String locations = "";
     
      List<TaxiDriver> drivers = new ArrayList<TaxiDriver>();
     
      PrintWriter out = response.getWriter();
     
      Iterator iterator = taxiDrivers.keySet().iterator();
        while (iterator.hasNext()) {
          id = (String) iterator.next();
         
          driver = (TaxiDriver) taxiDrivers.get(id);
          drivers.add(driver);
       
        }
       
        gson = new Gson();
        String jsonDrivers = gson.toJson(drivers);
        out.println(jsonDrivers);
        out.flush();
     
    }
    else if (action.equals("html"))
    {
      String name = "";
      String phone = "";
      String locations = "";
     
      response.setContentType("text/html");
     
      PrintWriter out = response.getWriter();
     
      out.println("<html>");
      out.println("<head>");
      out.println("<title>Display All Driver GPS Location</title>");
      out.println("</head>");
      out.println("<body>");
      out.println("<table border='1' cellpadding='5' cellspacing='5'>");
      out.println("<tr>");
      out.println("<th>Driver ID</th>");
      out.println("<th>Name</th>");
      out.println("<th>Phone</th>");
      out.println("<th>Locations (lat/long)</th>");
      out.println("</tr>");
     
      Iterator iterator = taxiDrivers.keySet().iterator();
        while (iterator.hasNext()) {
          out.println("<tr>");
          id = (String) iterator.next();
         
          driver = (TaxiDriver) taxiDrivers.get(id);
          name = driver.getName();
          phone = driver.getPhoneNumber();
          locations = driver.getCurrentLatitude() + ";" + driver.getCurrentLongitude();
         
          out.println("<td align='center'>" + id + "</td>");
          out.println("<td align='center'>" + name + "</td>");
          out.println("<td align='center'>" + phone + "</td>");
          out.println("<td align='right'>" + locations + "</td>");
View Full Code Here

TOP

Related Classes of my.beans.TaxiDriver

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.