forked from nus-cs2103-AY1819S2/addressbook-level4
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request nus-cs2103-AY1819S2#70 from jwl1997/master
modify event list basic commands
- Loading branch information
Showing
6 changed files
with
292 additions
and
1 deletion.
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
src/main/java/seedu/address/logic/parser/AddECommandParser.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,63 @@ | ||
package seedu.address.logic.parser; | ||
|
||
import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_DESCRIPTION; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_END_TIME; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_LABEL; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_START_TIME; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_VENUE; | ||
|
||
import java.util.stream.Stream; | ||
|
||
import seedu.address.logic.commands.AddECommand; | ||
import seedu.address.logic.parser.exceptions.ParseException; | ||
import seedu.address.model.event.DateTime; | ||
import seedu.address.model.event.Description; | ||
import seedu.address.model.event.Event; | ||
import seedu.address.model.event.Label; | ||
import seedu.address.model.event.Name; | ||
import seedu.address.model.event.Venue; | ||
|
||
/** | ||
* Parses input arguments and creates a new AddCommand object | ||
*/ | ||
public class AddECommandParser implements Parser<AddECommand> { | ||
|
||
/** | ||
* Parses the given {@code String} of arguments in the context of the AddECommand | ||
* and returns an AddECommand object for execution. | ||
* @throws ParseException if the user input does not conform the expected format | ||
*/ | ||
public AddECommand parse(String args) throws ParseException { | ||
ArgumentMultimap argMultimap = | ||
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_DESCRIPTION, PREFIX_VENUE, PREFIX_START_TIME, | ||
PREFIX_END_TIME, PREFIX_LABEL); | ||
|
||
if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_DESCRIPTION, PREFIX_VENUE, PREFIX_START_TIME, | ||
PREFIX_END_TIME, PREFIX_LABEL) | ||
|| !argMultimap.getPreamble().isEmpty()) { | ||
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddECommand.MESSAGE_USAGE)); | ||
} | ||
|
||
Name name = ParserUtilForEvent.parseName(argMultimap.getValue(PREFIX_NAME).get()); | ||
Description description = ParserUtilForEvent.parseDescription(argMultimap.getValue(PREFIX_DESCRIPTION).get()); | ||
Venue venue = ParserUtilForEvent.parseVenue(argMultimap.getValue(PREFIX_VENUE).get()); | ||
DateTime startTime = ParserUtilForEvent.parseDateTime(argMultimap.getValue(PREFIX_START_TIME).get()); | ||
DateTime endTime = ParserUtilForEvent.parseDateTime(argMultimap.getValue(PREFIX_END_TIME).get()); | ||
Label label = ParserUtilForEvent.parseLabel(argMultimap.getValue(PREFIX_LABEL).get()); | ||
|
||
Event event = new Event(name, description, venue, startTime, endTime, label); | ||
|
||
return new AddECommand(event); | ||
} | ||
|
||
/** | ||
* Returns true if none of the prefixes contains 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()); | ||
} | ||
|
||
} |
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
29 changes: 29 additions & 0 deletions
29
src/main/java/seedu/address/logic/parser/DeleteECommandParser.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,29 @@ | ||
package seedu.address.logic.parser; | ||
|
||
import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; | ||
|
||
import seedu.address.commons.core.index.Index; | ||
import seedu.address.logic.commands.DeleteECommand; | ||
import seedu.address.logic.parser.exceptions.ParseException; | ||
|
||
/** | ||
* Parses input arguments and creates a new DeleteECommand object | ||
*/ | ||
public class DeleteECommandParser implements Parser<DeleteECommand> { | ||
|
||
/** | ||
* Parses the given {@code String} of arguments in the context of the DeleteECommand | ||
* and returns an DeleteECommand object for execution. | ||
* @throws ParseException if the user input does not conform the expected format | ||
*/ | ||
public DeleteECommand parse(String args) throws ParseException { | ||
try { | ||
Index index = ParserUtilForEvent.parseIndex(args); | ||
return new DeleteECommand(index); | ||
} catch (ParseException pe) { | ||
throw new ParseException( | ||
String.format(MESSAGE_INVALID_COMMAND_FORMAT, DeleteECommand.MESSAGE_USAGE), pe); | ||
} | ||
} | ||
|
||
} |
74 changes: 74 additions & 0 deletions
74
src/main/java/seedu/address/logic/parser/EditECommandParser.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,74 @@ | ||
package seedu.address.logic.parser; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_DESCRIPTION; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_END_TIME; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_LABEL; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_START_TIME; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_VENUE; | ||
|
||
import seedu.address.commons.core.index.Index; | ||
import seedu.address.logic.commands.EditECommand; | ||
import seedu.address.logic.parser.exceptions.ParseException; | ||
|
||
|
||
|
||
|
||
/** | ||
* Parses input arguments and creates a new EditECommand object | ||
*/ | ||
public class EditECommandParser implements Parser<EditECommand> { | ||
|
||
/** | ||
* Parses the given {@code String} of arguments in the context of the EditECommand | ||
* and returns an EditECommand object for execution. | ||
* @throws ParseException if the user input does not conform the expected format | ||
*/ | ||
public EditECommand parse(String args) throws ParseException { | ||
requireNonNull(args); | ||
ArgumentMultimap argMultimap = | ||
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_DESCRIPTION, PREFIX_VENUE, PREFIX_START_TIME, | ||
PREFIX_END_TIME, PREFIX_LABEL); | ||
|
||
Index index; | ||
|
||
try { | ||
index = ParserUtilForEvent.parseIndex(argMultimap.getPreamble()); | ||
} catch (ParseException pe) { | ||
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, EditECommand.MESSAGE_USAGE), pe); | ||
} | ||
|
||
EditECommand.EditEventDescriptor editEventDescriptor = new EditECommand.EditEventDescriptor(); | ||
if (argMultimap.getValue(PREFIX_NAME).isPresent()) { | ||
editEventDescriptor.setName(ParserUtilForEvent.parseName(argMultimap.getValue(PREFIX_NAME).get())); | ||
} | ||
if (argMultimap.getValue(PREFIX_DESCRIPTION).isPresent()) { | ||
editEventDescriptor.setDescription(ParserUtilForEvent.parseDescription(argMultimap | ||
.getValue(PREFIX_DESCRIPTION).get())); | ||
} | ||
if (argMultimap.getValue(PREFIX_VENUE).isPresent()) { | ||
editEventDescriptor.setVenue(ParserUtilForEvent.parseVenue(argMultimap.getValue(PREFIX_VENUE).get())); | ||
} | ||
if (argMultimap.getValue(PREFIX_START_TIME).isPresent()) { | ||
editEventDescriptor.setStartDateTime(ParserUtilForEvent.parseDateTime(argMultimap | ||
.getValue(PREFIX_START_TIME).get())); | ||
} | ||
if (argMultimap.getValue(PREFIX_END_TIME).isPresent()) { | ||
editEventDescriptor.setEndDateTime(ParserUtilForEvent.parseDateTime(argMultimap | ||
.getValue(PREFIX_END_TIME).get())); | ||
} | ||
if (argMultimap.getValue(PREFIX_LABEL).isPresent()) { | ||
editEventDescriptor.setLabel(ParserUtilForEvent.parseLabel(argMultimap.getValue(PREFIX_LABEL).get())); | ||
} | ||
|
||
if (!editEventDescriptor.isAnyFieldEdited()) { | ||
throw new ParseException(EditECommand.MESSAGE_NOT_EDITED); | ||
} | ||
|
||
return new EditECommand(index, editEventDescriptor); | ||
} | ||
|
||
} | ||
|
109 changes: 109 additions & 0 deletions
109
src/main/java/seedu/address/logic/parser/ParserUtilForEvent.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,109 @@ | ||
package seedu.address.logic.parser; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
import seedu.address.commons.core.index.Index; | ||
import seedu.address.commons.util.StringUtil; | ||
import seedu.address.logic.parser.exceptions.ParseException; | ||
import seedu.address.model.event.DateTime; | ||
import seedu.address.model.event.Description; | ||
import seedu.address.model.event.Label; | ||
import seedu.address.model.event.Name; | ||
import seedu.address.model.event.Venue; | ||
|
||
/** | ||
* Contains utility methods used for parsing strings for event class in the various *Parser classes. | ||
*/ | ||
public class ParserUtilForEvent { | ||
|
||
public static final String MESSAGE_INVALID_INDEX = "Index is not a non-zero unsigned integer."; | ||
|
||
/** | ||
* Parses {@code oneBasedIndex} into an {@code Index} and returns it. Leading and trailing whitespaces will be | ||
* trimmed. | ||
* @throws ParseException if the specified index is invalid (not non-zero unsigned integer). | ||
*/ | ||
public static Index parseIndex(String oneBasedIndex) throws ParseException { | ||
String trimmedIndex = oneBasedIndex.trim(); | ||
if (!StringUtil.isNonZeroUnsignedInteger(trimmedIndex)) { | ||
throw new ParseException(MESSAGE_INVALID_INDEX); | ||
} | ||
return Index.fromOneBased(Integer.parseInt(trimmedIndex)); | ||
} | ||
|
||
/** | ||
* Parses a {@code String name} into a {@code Name}. | ||
* Leading and trailing whitespaces will be trimmed. | ||
* | ||
* @throws ParseException if the given {@code name} is invalid. | ||
*/ | ||
public static Name parseName(String name) throws ParseException { | ||
requireNonNull(name); | ||
String trimmedName = name.trim(); | ||
if (!Name.isValidName(trimmedName)) { | ||
throw new ParseException(Name.MESSAGE_CONSTRAINTS); | ||
} | ||
return new Name(trimmedName); | ||
} | ||
|
||
/** | ||
* Parses a {@code String description} into a {@code Description}. | ||
* Leading and trailing whitespaces will be trimmed. | ||
* | ||
* @throws ParseException if the given {@code description} is invalid. | ||
*/ | ||
public static Description parseDescription(String description) throws ParseException { | ||
requireNonNull(description); | ||
String trimmedDescription = description.trim(); | ||
if (!Description.isValidDescription(trimmedDescription)) { | ||
throw new ParseException(Description.MESSAGE_CONSTRAINTS); | ||
} | ||
return new Description(trimmedDescription); | ||
} | ||
|
||
/** | ||
* Parses a {@code String venue} into an {@code Venue}. | ||
* Leading and trailing whitespaces will be trimmed. | ||
* | ||
* @throws ParseException if the given {@code venue} is invalid. | ||
*/ | ||
public static Venue parseVenue(String venue) throws ParseException { | ||
requireNonNull(venue); | ||
String trimmedVenue = venue.trim(); | ||
if (!Venue.isValidVenue(trimmedVenue)) { | ||
throw new ParseException(Venue.MESSAGE_CONSTRAINTS); | ||
} | ||
return new Venue(trimmedVenue); | ||
} | ||
|
||
/** | ||
* Parses a {@code String dateTime} into an {@code DateTime}. | ||
* Leading and trailing whitespaces will be trimmed. | ||
* | ||
* @throws ParseException if the given {@code dateTime} is invalid. | ||
*/ | ||
public static DateTime parseDateTime(String dateTime) throws ParseException { | ||
requireNonNull(dateTime); | ||
String trimmedDateTime = dateTime.trim(); | ||
if (!DateTime.isValidDateTime(trimmedDateTime)) { | ||
throw new ParseException(DateTime.MESSAGE_CONSTRAINTS); | ||
} | ||
return new DateTime(trimmedDateTime); | ||
} | ||
|
||
/** | ||
* Parses a {@code String label} into an {@code Label}. | ||
* Leading and trailing whitespaces will be trimmed. | ||
* | ||
* @throws ParseException if the given {@code label} is invalid. | ||
*/ | ||
public static Label parseLabel(String label) throws ParseException { | ||
requireNonNull(label); | ||
String trimmedLabel = label.trim(); | ||
if (!Label.isValidLabelName(trimmedLabel)) { | ||
throw new ParseException(Label.MESSAGE_CONSTRAINTS); | ||
} | ||
return new Label(trimmedLabel); | ||
} | ||
|
||
} |