示例#1
0
 /**
  * Copy method for WatchTimeExceptionData.
  *
  * @param data the data to be copied from
  * @return the new WatchTimeExceptionData
  */
 private WatchTimeExceptionData addWatchTimeExceptionData(WatchTimeExceptionData data) {
   if (data != null) {
     int[] daysAsInt = data.getDaysOfWeek();
     List<TimeSpan> exceptionTimes = new LinkedList<TimeSpan>();
     for (TimeSpan s : data.getTimesOfDay()) {
       Time newFromTime = new Time(s.getFrom().getHour(), s.getFrom().getMinute());
       Time newToTime = new Time(s.getTo().getHour(), s.getTo().getMinute());
       exceptionTimes.add(new TimeSpan(newFromTime, newToTime));
     }
     return new WatchTimeExceptionData(daysAsInt, exceptionTimes);
   } else {
     return null;
   }
 }
示例#2
0
 /**
  * Adds the WatchTimeExceptionData from the form.
  *
  * @param formData the form.
  * @return the WatchTimeExceptionData
  */
 private WatchTimeExceptionData addWatchTimeExceptionData(JSONObject formData) {
   List<Integer> days = new LinkedList<Integer>();
   List<TimeSpan> exceptionTimes = new LinkedList<TimeSpan>();
   int[] daysAsInt = new int[] {};
   if (formData.has("watchdogExceptions")) {
     JSONObject jsonObject = formData.getJSONObject(("watchdogExceptions"));
     if (jsonObject.getBoolean(String.valueOf(Calendar.MONDAY))) {
       days.add(Calendar.MONDAY);
     }
     if (jsonObject.getBoolean(String.valueOf(Calendar.TUESDAY))) {
       days.add(Calendar.TUESDAY);
     }
     if (jsonObject.getBoolean(String.valueOf(Calendar.WEDNESDAY))) {
       days.add(Calendar.WEDNESDAY);
     }
     if (jsonObject.getBoolean(String.valueOf(Calendar.THURSDAY))) {
       days.add(Calendar.THURSDAY);
     }
     if (jsonObject.getBoolean(String.valueOf(Calendar.FRIDAY))) {
       days.add(Calendar.FRIDAY);
     }
     if (jsonObject.getBoolean(String.valueOf(Calendar.SATURDAY))) {
       days.add(Calendar.SATURDAY);
     }
     if (jsonObject.getBoolean(String.valueOf(Calendar.SUNDAY))) {
       days.add(Calendar.SUNDAY);
     }
     daysAsInt = Ints.toArray(days);
     if (jsonObject.has("watchdogExceptionTimes")) {
       Object obj = jsonObject.get("watchdogExceptionTimes");
       if (obj instanceof JSONArray) {
         for (Object json : (JSONArray) obj) {
           exceptionTimes.add(TimeSpan.createTimeSpanFromJSONObject((JSONObject) json));
         }
       } else if (obj instanceof JSONObject) {
         exceptionTimes.add(TimeSpan.createTimeSpanFromJSONObject((JSONObject) obj));
       }
     }
   }
   return new WatchTimeExceptionData(daysAsInt, exceptionTimes);
 }