forked from nus-cs2103-AY1920S1/addressbook-level3
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Move muscle to exercise package * Add Regime * Add UniqueRegimeList * Add regime to AddCommand * Add regime to UI * Add regime to storage * Edit tests * Seperate AddCommand to AddECommand and AddRCommand * Implement delete regime * Add sample data and edit command message * Refactor code * Refactor code * Change regimeName to be compulsory field * Implement add exercise to same regime name * Implement delete of exercises in regime * Change messages in logic * Refactor code to pass checkstyle * Refactor code Close #66
- Loading branch information
1 parent
aee0060
commit b44a7ed
Showing
69 changed files
with
1,812 additions
and
291 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 8 additions & 60 deletions
68
src/main/java/seedu/exercise/logic/commands/AddCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,17 @@ | ||
package seedu.exercise.logic.commands; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static seedu.exercise.logic.parser.CliSyntax.PREFIX_CALORIES; | ||
import static seedu.exercise.logic.parser.CliSyntax.PREFIX_DATE; | ||
import static seedu.exercise.logic.parser.CliSyntax.PREFIX_MUSCLE; | ||
import static seedu.exercise.logic.parser.CliSyntax.PREFIX_NAME; | ||
import static seedu.exercise.logic.parser.CliSyntax.PREFIX_QUANTITY; | ||
import static seedu.exercise.logic.parser.CliSyntax.PREFIX_UNIT; | ||
|
||
import seedu.exercise.logic.commands.exceptions.CommandException; | ||
import seedu.exercise.model.Model; | ||
import seedu.exercise.model.exercise.Exercise; | ||
import static seedu.exercise.logic.commands.AddExerciseCommand.MESSAGE_USAGE_EXERCISE; | ||
import static seedu.exercise.logic.commands.AddRegimeCommand.MESSAGE_USAGE_REGIME; | ||
|
||
/** | ||
* Adds an exercise to the exercise book. | ||
* Represents an AddCommand with hidden internal logic and the ability to be executed. | ||
*/ | ||
public class AddCommand extends Command { | ||
public abstract class AddCommand extends Command { | ||
|
||
public static final String COMMAND_WORD = "add"; | ||
|
||
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds a exercise to the exercise list. " | ||
+ "Parameters: " | ||
+ PREFIX_NAME + "EXERCISE NAME " | ||
+ PREFIX_DATE + "DATE " | ||
+ PREFIX_CALORIES + "CALORIES " | ||
+ PREFIX_QUANTITY + "QUANTITY " | ||
+ PREFIX_UNIT + "UNITS" | ||
+ "[" + PREFIX_MUSCLE + "MUSCLE]...\n" | ||
+ "Example: " + COMMAND_WORD + " " | ||
+ PREFIX_NAME + "Run " | ||
+ PREFIX_DATE + "22/09/2019 " | ||
+ PREFIX_CALORIES + "1500 " | ||
+ PREFIX_QUANTITY + "2.4 " | ||
+ PREFIX_UNIT + "km " | ||
+ PREFIX_MUSCLE + "Leg"; | ||
|
||
public static final String MESSAGE_SUCCESS = "New exercise added: %1$s"; | ||
public static final String MESSAGE_DUPLICATE_EXERCISE = "This exercise already exists in the exercise book"; | ||
|
||
private final Exercise toAdd; | ||
|
||
/** | ||
* Creates an AddCommand to add the specified {@code Person} | ||
*/ | ||
public AddCommand(Exercise exercise) { | ||
requireNonNull(exercise); | ||
toAdd = exercise; | ||
} | ||
|
||
@Override | ||
public CommandResult execute(Model model) throws CommandException { | ||
requireNonNull(model); | ||
|
||
if (model.hasExercise(toAdd)) { | ||
throw new CommandException(MESSAGE_DUPLICATE_EXERCISE); | ||
} | ||
|
||
model.addExercise(toAdd); | ||
return new CommandResult(String.format(MESSAGE_SUCCESS, toAdd)); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
return other == this // short circuit if same object | ||
|| (other instanceof AddCommand // instanceof handles nulls | ||
&& toAdd.equals(((AddCommand) other).toAdd)); | ||
} | ||
public static final String MESSAGE_USAGE = COMMAND_WORD | ||
+ ": Adds exercise to exercise list or adds regime to regime list.\n" | ||
+ "EXERCISE: " + MESSAGE_USAGE_EXERCISE + "\n" | ||
+ "REGIME: " + MESSAGE_USAGE_REGIME; | ||
} |
68 changes: 68 additions & 0 deletions
68
src/main/java/seedu/exercise/logic/commands/AddExerciseCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package seedu.exercise.logic.commands; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static seedu.exercise.logic.parser.CliSyntax.PREFIX_CALORIES; | ||
import static seedu.exercise.logic.parser.CliSyntax.PREFIX_CATEGORY; | ||
import static seedu.exercise.logic.parser.CliSyntax.PREFIX_DATE; | ||
import static seedu.exercise.logic.parser.CliSyntax.PREFIX_MUSCLE; | ||
import static seedu.exercise.logic.parser.CliSyntax.PREFIX_NAME; | ||
import static seedu.exercise.logic.parser.CliSyntax.PREFIX_QUANTITY; | ||
import static seedu.exercise.logic.parser.CliSyntax.PREFIX_UNIT; | ||
|
||
import seedu.exercise.logic.commands.exceptions.CommandException; | ||
import seedu.exercise.model.Model; | ||
import seedu.exercise.model.exercise.Exercise; | ||
|
||
/** | ||
* Adds an exercise to the exercise book. | ||
*/ | ||
public class AddExerciseCommand extends AddCommand { | ||
|
||
public static final String MESSAGE_USAGE_EXERCISE = "Parameters: " | ||
+ PREFIX_CATEGORY + "CATEGORY " | ||
+ PREFIX_NAME + "EXERCISE NAME " | ||
+ PREFIX_DATE + "DATE " | ||
+ PREFIX_CALORIES + "CALORIES " | ||
+ PREFIX_QUANTITY + "QUANTITY " | ||
+ PREFIX_UNIT + "UNITS " | ||
+ "[" + PREFIX_MUSCLE + "MUSCLE]...\n" | ||
+ "\t\tExample: " + COMMAND_WORD + " " | ||
+ PREFIX_CATEGORY + "exercise" | ||
+ PREFIX_NAME + "Run " | ||
+ PREFIX_DATE + "22/09/2019 " | ||
+ PREFIX_CALORIES + "1500 " | ||
+ PREFIX_QUANTITY + "2.4 " | ||
+ PREFIX_UNIT + "km " | ||
+ PREFIX_MUSCLE + "Leg"; | ||
|
||
public static final String MESSAGE_SUCCESS = "New exercise added: %1$s"; | ||
public static final String MESSAGE_DUPLICATE_EXERCISE = "This exercise already exists in the exercise book"; | ||
|
||
private Exercise toAdd; | ||
|
||
/** | ||
* Creates an AddExerciseCommand to add the specified {@code Exercise} | ||
*/ | ||
public AddExerciseCommand(Exercise exercise) { | ||
requireNonNull(exercise); | ||
toAdd = exercise; | ||
} | ||
|
||
@Override | ||
public CommandResult execute(Model model) throws CommandException { | ||
requireNonNull(model); | ||
if (model.hasExercise(toAdd)) { | ||
throw new CommandException(MESSAGE_DUPLICATE_EXERCISE); | ||
} | ||
|
||
model.addExercise(toAdd); | ||
return new CommandResult(String.format(MESSAGE_SUCCESS, toAdd)); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
return other == this // short circuit if same object | ||
|| (other instanceof AddExerciseCommand // instanceof handles nulls | ||
&& toAdd.equals(((AddExerciseCommand) other).toAdd)); | ||
} | ||
} |
Oops, something went wrong.