Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented AddMilestoneCommandParser #48

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -7,6 +7,7 @@

import seedu.address.logic.CommandHistory;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.logic.parser.AddMilestoneCommandParser;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.Model;
import seedu.address.model.task.Milestone;
Expand Down Expand Up @@ -50,7 +51,7 @@ public CommandResult execute(Model model, CommandHistory history) throws Command

@Override
public Command parse(String arguments) throws ParseException {
return null;
return new AddMilestoneCommandParser().parse(arguments);
}

@Override
Expand Down
@@ -0,0 +1,46 @@
package seedu.address.logic.parser;

import seedu.address.logic.commands.AddMilestoneCommand;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.task.Milestone;

import java.util.stream.Stream;

import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TITLE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_MILESTONE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_RANK;

//@@author JeremyInElysium
/**
* Parses input arguments and creates a new AddMilestoneCommand object
*/
public class AddMilestoneCommandParser implements Parser<AddMilestoneCommand> {

/**
* Returns true if none of the prefixes contain empty {@code Optional} values in the given
* {@code ArgumentMultiMap}.
*/
private static boolean arePrefixesPresent(ArgumentMultimap argumentMultimap, Prefix... prefixes) {
return Stream.of(prefixes).allMatch(prefix -> argumentMultimap.getValue(prefix).isPresent());
}

@Override
public AddMilestoneCommand parse(String userInput) throws ParseException {
ArgumentMultimap argMultimap =
ArgumentTokenizer.tokenize(userInput, PREFIX_TITLE, PREFIX_MILESTONE, PREFIX_RANK);

if(!arePrefixesPresent(argMultimap, PREFIX_TITLE, PREFIX_MILESTONE, PREFIX_RANK)
|| !argMultimap.getPreamble().isEmpty()) {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddMilestoneCommand.MESSAGE_USAGE));
}

String title = ParserUtil.parseTitle(argMultimap.getValue(PREFIX_TITLE).get());
String milestoneDescription = ParserUtil.parseMilestoneDescription(argMultimap.getValue(PREFIX_MILESTONE).get());
String rank = ParserUtil.parseRank(argMultimap.getValue(PREFIX_RANK).get());

Milestone milestone = new Milestone(title, milestoneDescription, rank);

return new AddMilestoneCommand(milestone);
}
}
19 changes: 19 additions & 0 deletions src/main/java/seedu/address/logic/parser/ParserUtil.java
Expand Up @@ -120,4 +120,23 @@ public static String parseYear(String year) throws ParseException {
return trimmedYear;
}

//@@author JeremyInElysium
/**
* Leading and trailing whitespaces will be trimmed from {@code String milestoneDescription}
*/
public static String parseMilestoneDescription(String milestoneDescription) throws ParseException {
requireNonNull(milestoneDescription);
String trimmedMilestoneDescription = milestoneDescription.trim();
return trimmedMilestoneDescription;
}

/**
* Leading and trailing whitespaces will be trimmed from {@code String rank}
*/
public static String parseRank(String rank) throws ParseException {
requireNonNull(rank);
String trimmedRank = rank.trim();
return trimmedRank;
}

}
6 changes: 3 additions & 3 deletions src/main/java/seedu/address/model/task/Milestone.java
Expand Up @@ -7,16 +7,16 @@
public class Milestone extends Task {
//private final String title;
//private final String milestone_description;
private final Integer rank;
private final String rank;

public Milestone(String title, String milestoneDescription, Integer rank) {
public Milestone(String title, String milestoneDescription, String rank) {
super(title, milestoneDescription, new PriorityLevel("high"));
//this.title = title;
//this.milestoneDescription = milestoneDescription;
this.rank = rank;
}

public Integer getRank() {
public String getRank() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More intuitive to have rank as a int? U may consider parsingRank as a string then converting it into an integer.

return rank;
}

Expand Down