コード例 #1
0
 /**
  * Deletes the old appointment and adds a new appointment to the list
  *
  * @param oldApp old appointment
  * @param newApp new appointment
  */
 public void saveEditedApp(Appointment oldApp, Appointment newApp) {
   modified = true;
   // save specific instance
   if (oldApp.getRecurring() && !newApp.getRecurring()) {
     System.out.println("Saving specific instance");
     oldApp.addExceptDate(newApp.getDate());
     appointments.add(newApp);
   } else {
     appointments.set(appointments.indexOf(oldApp), newApp);
   }
 }
コード例 #2
0
 /**
  * View Appointment of the specified date
  *
  * @return appointment list of that day
  * @param date
  */
 public ArrayList<Appointment> viewApp(String date) {
   ArrayList<Appointment> filteredApps = new ArrayList<Appointment>();
   String[] tokens1 = date.split("/");
   // for every appointment in the list
   for (Appointment a : appointments) {
     boolean addIt = true;
     String[] tokens2 = a.getDate().split("/");
     if (a.getRecurring()) {
       switch (a.typeRecurring()) {
         case 0:
           {
             setCaleDate(date);
             boolean[] daysOfWeek = a.getBoolDaysOfWeek();
             if (daysOfWeek[cale.get(Calendar.DAY_OF_WEEK) - 1]) {
               if (!a.getExceptDates().contains(date)) {
                 filteredApps.add(a);
                 addIt = false;
               }
             }
           }
           break;
         case 1:
           {
             int n = a.getN();
             Date d1 =
                 new Date(
                     Integer.parseInt(tokens1[0]),
                     Integer.parseInt(tokens1[1]),
                     Integer.parseInt(tokens1[2]));
             long d1Long = d1.getTime();
             Date d2 =
                 new Date(
                     Integer.parseInt(tokens2[0]),
                     Integer.parseInt(tokens2[1]),
                     Integer.parseInt(tokens2[2]));
             long d2Long = d2.getTime();
             if (((d2Long - d1Long) / 86400000L) % n == 0) {
               if (!a.getExceptDates().contains(date)) {
                 filteredApps.add(a);
                 addIt = false;
               }
             }
           }
           break;
         case 2:
           {
             if (Integer.parseInt(tokens1[2]) == a.getN()) {
               if (!a.getExceptDates().contains(date)) {
                 filteredApps.add(a);
                 addIt = false;
               }
             }
           }
           break;
         case 3:
           {
             boolean[] daysOfWeek = a.getBoolDaysOfWeek();
             int n = a.getN();
             int[] days =
                 computeNumDays(Integer.parseInt(tokens1[1]), Integer.parseInt(tokens1[2]));
             int count = 0;
             for (int i = 1; i <= days.length; i++) {
               String dt = tokens1[0] + "/" + tokens1[1] + "/" + i;
               setCaleDate(dt);
               if (daysOfWeek[cale.get(Calendar.DAY_OF_WEEK) - 1]) {
                 count++;
                 if (count == n && dt.equals(date)) {
                   if (!a.getExceptDates().contains(date)) {
                     filteredApps.add(a);
                     addIt = false;
                   }
                 }
               }
             }
           }
           break;
       }
     } else {
       // for every token in parameter
       for (int i = 0; i < tokens1.length; i++) {
         if (!(tokens1[i].equals(tokens2[i]))) {
           addIt = false;
         }
       }
       if (addIt) {
         filteredApps.add(a);
       }
     }
   }
   return filteredApps;
 }
コード例 #3
0
 /**
  * Removes specific instance of the recurring appointment
  *
  * @param oldApp recurring appointment
  * @param date date that the appointment will not reocurr
  */
 public void removeSpecific(Appointment oldApp, String date) {
   if (oldApp.getRecurring()) {
     oldApp.addExceptDate(date);
   }
 }