55
66import java .util .Iterator ;
77import java .util .List ;
8+ import java .util .Set ;
89
910import javafx .collections .FXCollections ;
1011import javafx .collections .ObservableList ;
12+ import seedu .address .model .person .exceptions .DuplicateExerciseException ;
1113import seedu .address .model .person .exceptions .DuplicateRoutineException ;
1214import seedu .address .model .person .exceptions .RoutineNotFoundException ;
1315
@@ -52,7 +54,8 @@ public void add(Routine toAdd) {
5254
5355 /**
5456 * Adds an existing Exercise within fitNUS into an existing Routine within fitNUS.
55- * @param r Existing Routine.
57+ *
58+ * @param r Existing Routine.
5659 * @param exercise Existing Exercise.
5760 */
5861 public void addExercise (Routine r , Exercise exercise ) {
@@ -62,6 +65,10 @@ public void addExercise(Routine r, Exercise exercise) {
6265 } else {
6366 for (Routine routine : internalList ) {
6467 if (routine .isSameActivity (r )) {
68+ Set <Exercise > routineExercises = routine .getExercises ();
69+ if (routineExercises .contains (exercise )) {
70+ throw new DuplicateExerciseException ();
71+ }
6572 routine .addExercise (exercise );
6673 break ;
6774 }
@@ -71,6 +78,7 @@ public void addExercise(Routine r, Exercise exercise) {
7178
7279 /**
7380 * Returns the toString method of the Routine that the user wants to view.
81+ *
7482 * @param index Index of the Routine that the user wants to view.
7583 * @return The toString method of the Routine that the user wants to see.
7684 */
@@ -80,6 +88,7 @@ public String viewRoutine(int index) {
8088
8189 /**
8290 * Lists out all the Routine objects in UniqueRoutineList.
91+ *
8392 * @return String containing all the Routine object toString method.
8493 */
8594 public String listRoutines () {
@@ -126,6 +135,7 @@ public void remove(Routine toRemove) {
126135
127136 /**
128137 * Returns the size of the UniqueRoutineList.
138+ *
129139 * @return Integer of the size of the UniqueRoutineList.
130140 */
131141 public int checkSize () {
@@ -190,6 +200,7 @@ private boolean routinesAreUnique(List<Routine> routines) {
190200
191201 /**
192202 * Retrieves the Routine object from UniqueRoutineList that the user specified.
203+ *
193204 * @param r Routine object that the user wants.
194205 * @return Routine object that exists within fitNUS that the user is looking for.
195206 */
@@ -201,4 +212,34 @@ public Routine retrieveRoutine(Routine r) {
201212 }
202213 return r ;
203214 }
215+
216+ /**
217+ * Deletes the specified Exercise from the specified Routine.
218+ *
219+ * @param retrievedRoutine User-specified Routine.
220+ * @param retrievedExercise User-specified Exercise.
221+ */
222+ public void deleteExerciseFromRoutine (Routine retrievedRoutine , Exercise retrievedExercise ) {
223+ if (!internalList .contains (retrievedRoutine )) {
224+ throw new RoutineNotFoundException ();
225+ } else {
226+ for (Routine routine : internalList ) {
227+ if (routine .isSameActivity (retrievedRoutine )) {
228+ routine .deleteExercise (retrievedExercise );
229+ break ;
230+ }
231+ }
232+ }
233+ }
234+
235+ /**
236+ * Deletes specified Exercise from all Routines.
237+ * @param retrievedExercise User-specified Exercise to remove from all Routines.
238+ */
239+ public void deleteExercise (Exercise retrievedExercise ) {
240+ for (Routine routine : internalList ) {
241+ Set <Exercise > routineExercises = routine .getExercises ();
242+ routineExercises .remove (retrievedExercise );
243+ }
244+ }
204245}
0 commit comments