You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

UserFavouriteStopsDbo.java 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. package com.rthoni.stssaguenay.dbo;
  2. import com.luticate.utils.dbo.LuDbo;
  3. import org.json.JSONArray;
  4. import org.json.JSONException;
  5. import org.json.JSONObject;
  6. import java.util.HashMap;
  7. import java.util.List;
  8. import java.util.Vector;
  9. /**
  10. * Created by robin on 10/1/16.
  11. */
  12. public class UserFavouriteStopsDbo extends LuDbo {
  13. protected StopsDbo _stop;
  14. protected List<RoutesDbo> _routes;
  15. protected String _name;
  16. @Override
  17. public void fromJson(JSONObject json) throws JSONException {
  18. _stop = new StopsDbo();
  19. _stop.fromJson(json.getJSONObject("stop"));
  20. _routes = new Vector<>();
  21. JSONArray routes = json.getJSONArray("routes");
  22. for (int i = 0; i < routes.length(); ++i) {
  23. RoutesDbo route = new RoutesDbo();
  24. route.fromJson(routes.getJSONObject(i));
  25. _routes.add(route);
  26. }
  27. _name = json.getString("name");
  28. }
  29. @Override
  30. public HashMap<String, Object> toArray() {
  31. HashMap<String, Object> map = new HashMap<>();
  32. map.put("stop", _stop.toArray());
  33. List<Object> routes = new Vector<>();
  34. for (RoutesDbo route : _routes) {
  35. routes.add(route.toArray());
  36. }
  37. map.put("routes", routes);
  38. map.put("name", _name);
  39. return map;
  40. }
  41. public StopsDbo getStop() {
  42. return _stop;
  43. }
  44. public void setStop(StopsDbo stop) {
  45. _stop = stop;
  46. }
  47. public List<RoutesDbo> getRoutes() {
  48. return _routes;
  49. }
  50. public void setRoutes(List<RoutesDbo> routes) {
  51. _routes = routes;
  52. }
  53. public String getName() {
  54. return _name;
  55. }
  56. public void setName(String name) {
  57. _name = name;
  58. }
  59. public String getCustomName()
  60. {
  61. if (_name != null && !_name.isEmpty()) {
  62. return _name;
  63. }
  64. return _stop.getName();
  65. }
  66. }