Пример #1
0
  public synchronized void updateSingleShedule(
      String command, String commandID, String commantModeText) {

    int cmdID = Integer.parseInt(commandID);
    if (!conainsCommandInDevice(command)) {
      return;
    }

    System.out.println(
        "found command in device for signle update   #ncommand:"
            + command
            + "#ncommandID="
            + commandID
            + " commantModeText:"
            + commantModeText);

    System.out.println("commandID= " + commandID);
    // int position = -1;
    Shedule shedule = null;
    for (int i = 0; i < sheduleList.size(); i++) {
      if (sheduleList.get(i).getId() == cmdID) {
        shedule = sheduleList.get(i);
        System.out.println("found update id");
        if (commantModeText.startsWith(IS_WEEKLY)) {
          System.out.println(
              commantModeText.substring(IS_WEEKLY.length(), commantModeText.length()));
          // boolean
          // isActive=Boolean.parseBoolean(commantModeText.substring(IS_WEEKLY.length(),commantModeText.length()));
          shedule.setIsWeekly(
              commantModeText.substring(IS_WEEKLY.length(), commantModeText.length()));
          updateShedule();
        } else if (commantModeText.startsWith(IS_ACTIVE)) {
          // boolean isActive=Boolean.parseBoolean(commantModeText.substring(IS_ACTIVE.length()));
          System.out.println(
              commantModeText.substring(IS_ACTIVE.length(), commantModeText.length()));
          shedule.setIsActive(
              commantModeText.substring(IS_ACTIVE.length(), commantModeText.length()));
          updateShedule();
        }
        //   position = i;

      }
    }

    //   if (position != -1) {
    //    sheduleList.remove(position);
    //   sheduleList.add(position,shedule);
    //  }

    if (shedule == null) {
      System.out.println("shedule did not found");
      return;
    }
    sh.sendToAll("updatedOk:DeviceID:" + SH.DeviceID + COMMAND_SPLIT_STRING + shedule.toString());
  }
Пример #2
0
  public synchronized String updateShedule(Shedule shedule) {

    int position = -1;
    for (int i = 0; i < sheduleList.size(); i++) {
      if (sheduleList.get(i).getId() == shedule.getId()) {
        position = i;
      }
    }

    if (position != -1) {
      sheduleList.remove(position);
      sheduleList.add(position, shedule);
    }

    updateShedule();
    return "UpdatedOk:DeviceID:" + SH.DeviceID + COMMAND_SPLIT_STRING + shedule.toString();
  }
Пример #3
0
        @Override
        public boolean add(Shedule shedule) {

          System.out.println(size() + "    add to list     " + shedule.getCommands());
          for (int i = 0; i < size(); i++) {

            if (get(i).getId() == shedule.getId()) {
              return false;
            }

            System.out.println(get(i).getCommands() + "    vs    " + shedule.getCommands());
            if (get(i).getCommands().equals(shedule.getCommands())) {
              System.out.println("false");
              return false;
            }
          }
          return super.add(shedule);
        }
Пример #4
0
  public synchronized void updateShedule(String command, String commandID) {

    String sendingToAllCommand = "";
    //  Shedule shedule = new Shedule();

    // System.out.println("command = "+command);
    if (!conainsCommandInDevice(getCommandText(command))) {
      return;
    }
    System.out.println(
        "found command in device for update   command:" + command + "#ncommandID=" + commandID);
    //   int position = -1;
    Shedule shedule = null;
    int cmdID = Integer.parseInt(commandID);
    for (int i = 0; i < sheduleList.size(); i++) {
      if (sheduleList.get(i).getId() == cmdID) {
        shedule = sheduleList.get(i);
        shedule.setId(cmdID); // /////// iDD
        shedule.setActiveDays(getDays(command));
        shedule.setTime(getTime(command));
        shedule.setIsWeekly(getIsWeekly(command));
        shedule.setIsActive(getIsActive(command));
        shedule.setCommandText(getCommandText(command));
        updateShedule();
        //   position = i;
      }
    }

    // if (position != -1) {
    //    sheduleList.remove(position);
    //     sheduleList.add(position,shedule);
    //  }

    if (shedule == null) {
      return;
    }
    sh.sendToAll("updatedOk:DeviceID:" + SH.DeviceID + COMMAND_SPLIT_STRING + shedule.toString());

    //   return"updatedOk:DeviceID:"+SH.DeviceID+COMMAND_SPLIT_STRING+shedule.toString();
  }
Пример #5
0
  public synchronized String add(String command) {

    System.out.println("add:::" + command);
    Shedule shedule = new Shedule();
    shedule.setId(getnewID());
    shedule.setActiveDays(getDays(command));
    shedule.setTime(getTime(command));
    shedule.setIsWeekly(getIsWeekly(command));
    shedule.setIsActive(getIsActive(command));
    shedule.setCommandText(getCommandText(command));
    if (!conainsCommandInDevice(shedule.getCommandText())) {
      return null;
    }
    boolean isGointToADd = true;
    for (int i = 0; i < sheduleList.size(); i++) {

      if (sheduleList.get(i).getId() == shedule.getId()) {
        isGointToADd = false;
      }

      if (sheduleList.get(i).getCommands().equals(shedule.getCommands())) {
        System.out.println("false");
        isGointToADd = false;
      }
    }
    if (isGointToADd) {
      if (sheduleList.add(shedule)) {
        addShedule(shedule);
        return "DeviceID:" + SH.DeviceID + COMMAND_SPLIT_STRING + shedule.toString();
      }
    }
    return "addedNotOk";
  }