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.
- Loading branch information
Showing
23 changed files
with
430 additions
and
58 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
{ | ||
"jsonResources" : [ { | ||
"name" : "Push ups", | ||
"date" : "26/09/2019", | ||
"calories" : "30", | ||
"quantity" : "60", | ||
"unit" : "counts", | ||
"muscles" : [ "Triceps" ], | ||
"customProperties" : { } | ||
}, { | ||
"name" : "Sit ups", | ||
"date" : "26/09/2019", | ||
"calories" : "30", | ||
"quantity" : "60", | ||
"unit" : "counts", | ||
"muscles" : [ "Abs" ], | ||
"customProperties" : { } | ||
}, { | ||
"name" : "Run", | ||
"date" : "22/09/2019", | ||
"calories" : "300", | ||
"quantity" : "2.4", | ||
"unit" : "km", | ||
"muscles" : [ "Legs", "cardio" ], | ||
"customProperties" : { } | ||
}, { | ||
"name" : "Bench Press", | ||
"date" : "22/09/2019", | ||
"calories" : "50", | ||
"quantity" : "30", | ||
"unit" : "counts", | ||
"muscles" : [ "Chest", "Triceps" ], | ||
"customProperties" : { } | ||
}, { | ||
"name" : "Squat", | ||
"date" : "22/09/2019", | ||
"calories" : "50", | ||
"quantity" : "30", | ||
"unit" : "counts", | ||
"muscles" : [ "Legs", "Back" ], | ||
"customProperties" : { } | ||
}, { | ||
"name" : "Deadlift", | ||
"date" : "22/09/2019", | ||
"calories" : "50", | ||
"quantity" : "30", | ||
"unit" : "counts", | ||
"muscles" : [ "Legs", "Back" ], | ||
"customProperties" : { } | ||
} ] | ||
} |
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
20 changes: 14 additions & 6 deletions
20
src/main/java/seedu/exercise/logic/commands/SuggestBasicCommand.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
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
72 changes: 72 additions & 0 deletions
72
src/main/java/seedu/exercise/logic/commands/SuggestPossibleCommand.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,72 @@ | ||
package seedu.exercise.logic.commands; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static seedu.exercise.logic.parser.CliSyntax.PREFIX_MUSCLE; | ||
import static seedu.exercise.logic.parser.CliSyntax.PREFIX_SUGGEST_TYPE; | ||
|
||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.function.Predicate; | ||
|
||
import seedu.exercise.logic.commands.exceptions.CommandException; | ||
import seedu.exercise.model.Model; | ||
import seedu.exercise.model.property.Muscle; | ||
import seedu.exercise.model.resource.Exercise; | ||
|
||
/** | ||
* Lists possible exercises to the user. | ||
*/ | ||
public class SuggestPossibleCommand extends SuggestCommand { | ||
|
||
public static final String MESSAGE_USAGE_SUGGEST_POSSIBLE = "Parameters: " | ||
+ PREFIX_SUGGEST_TYPE + "SUGGEST_TYPE " | ||
+ "[" + PREFIX_MUSCLE + "MUSCLE] " | ||
+ "[" + "CUSTOM_PROPERTY_PREFIX" + "/" + "VALUE]" + "\n" | ||
+ "\t\tExample: " + COMMAND_WORD + " " | ||
+ PREFIX_SUGGEST_TYPE + "possible " | ||
+ PREFIX_MUSCLE + "Legs"; | ||
|
||
public static final String MESSAGE_SUCCESS = "Listed suggested exercises."; | ||
public static final String SUGGEST_TYPE = "possible"; | ||
|
||
|
||
private Set<Muscle> targetMuscles; | ||
private Map<String, String> targetCustomPropertiesMap; | ||
|
||
public SuggestPossibleCommand(Set<Muscle> targetMuscles, Map<String, String> targetCustomPropertiesMap) { | ||
this.targetMuscles = targetMuscles; | ||
this.targetCustomPropertiesMap = targetCustomPropertiesMap; | ||
} | ||
|
||
@Override | ||
public CommandResult execute(Model model) throws CommandException { | ||
requireNonNull(model); | ||
model.updateSuggestedExerciseList(getPredicate()); | ||
return new CommandResult(MESSAGE_SUCCESS); | ||
} | ||
|
||
private Predicate<Exercise> getPredicate() { | ||
return exercise -> { | ||
Set<Muscle> exercisesMuscles = exercise.getMuscles(); | ||
for (Muscle muscle : targetMuscles) { | ||
if (!(exercisesMuscles.contains(muscle))) { | ||
return false; | ||
} | ||
} | ||
|
||
Map<String, String> exerciseCustomProperties = exercise.getCustomProperties(); | ||
for (String key : targetCustomPropertiesMap.keySet()) { | ||
if (!(targetCustomPropertiesMap.get(key).equals(exerciseCustomProperties.get(key)))) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
}; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
return other == this // short circuit if same object | ||
|| (other instanceof SuggestPossibleCommand); // instanceof handles nulls | ||
} | ||
} |
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
Oops, something went wrong.