Advertisement
Guest User

Untitled

a guest
May 24th, 2015
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.74 KB | None | 0 0
  1.     public void lerEventos(JSONArray listaEventos) {
  2.         this.eventos = listaEventos;
  3.  
  4.         for (Object obj : listaEventos) {
  5.             String accao = (String) ((JSONObject)obj).get("accao");
  6.             if (accao.equals("LIGA")) {
  7.                 String id = (String) ((JSONObject)obj).get("idAparelho");
  8.                 for (Linha l : linhaEletrica) {
  9.                     if (l.getAparelho(id) != null) {
  10.                         long time = (long) ((JSONObject)obj).get("tempo");
  11.                         if (Relogio.getInstanciaUnica().getTique() == (int) time)
  12.                             l.getAparelho(id).liga();
  13.                     }
  14.                 }
  15.             }
  16.             if (accao.equals("DESLIGA")) {
  17.                 String id = (String) ((JSONObject)obj).get("idAparelho");
  18.                 for (Linha l : linhaEletrica) {
  19.                     if (l.getAparelho(id) != null) {
  20.                         long time = (long) ((JSONObject)obj).get("tempo");
  21.                         if (Relogio.getInstanciaUnica().getTique() == (int) time)
  22.                             l.getAparelho(id).desliga();
  23.                     }
  24.                 }
  25.  
  26.             }
  27.             if (accao.equals("AUMENTA")) {
  28.                 String id = (String) ((JSONObject)obj).get("idAparelho");
  29.                 for (Linha l: linhaEletrica) {
  30.                     if (l.getAparelho(id) != null) {
  31.                         long time = (long)((JSONObject)obj).get("tempo");
  32.                         if (Relogio.getInstanciaUnica().getTique() == time)
  33.                             ((AparelhoPotenciaVariavel) l.getAparelho(id)).aumenta((int) (double) ((JSONObject)obj).get("valor"));
  34.                     }
  35.                 }
  36.  
  37.             }
  38.  
  39.             if (accao.equals("PROGRAMA")) {
  40.                 String id = (String) ((JSONObject)obj).get("idAparelho");
  41.                 String programa = (String)((JSONObject)obj).get("programa");
  42.                 for (Linha l : linhaEletrica) {
  43.                     if (l.getAparelho(id) != null) {
  44.                         long time = (long) ((JSONObject)obj).get("tempo");
  45.                         if (Relogio.getInstanciaUnica().getTique() == (int) time) {
  46.                             ((MaqLavar) l.getAparelho(id)).setPrograma(programa);
  47.                         }
  48.                     }
  49.                 }
  50.  
  51.             }
  52.         }
  53.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement