Skip to content

Commit

Permalink
Merge pull request nus-cs2103-AY1819S2#70 from jwl1997/master
Browse files Browse the repository at this point in the history
modify event list basic commands
  • Loading branch information
jwl1997 authored Mar 20, 2019
2 parents 7dd8ac9 + c782ba8 commit 70242d6
Show file tree
Hide file tree
Showing 6 changed files with 292 additions and 1 deletion.
63 changes: 63 additions & 0 deletions src/main/java/seedu/address/logic/parser/AddECommandParser.java
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());
}

}
16 changes: 16 additions & 0 deletions src/main/java/seedu/address/logic/parser/AddressBookParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,20 @@
import java.util.regex.Pattern;

import seedu.address.logic.commands.AddCommand;
import seedu.address.logic.commands.AddECommand;
import seedu.address.logic.commands.ClearCommand;
import seedu.address.logic.commands.Command;
import seedu.address.logic.commands.DeleteCommand;
import seedu.address.logic.commands.DeleteECommand;
import seedu.address.logic.commands.EditCommand;
import seedu.address.logic.commands.EditECommand;
import seedu.address.logic.commands.ExitCommand;
import seedu.address.logic.commands.FindCommand;
import seedu.address.logic.commands.HelpCommand;
import seedu.address.logic.commands.HistoryCommand;
import seedu.address.logic.commands.ImportCommand;
import seedu.address.logic.commands.ListCommand;
import seedu.address.logic.commands.ListECommand;
import seedu.address.logic.commands.MeetCommand;
import seedu.address.logic.commands.RedoCommand;
import seedu.address.logic.commands.SelectCommand;
Expand Down Expand Up @@ -53,15 +57,24 @@ public Command parseCommand(String userInput) throws ParseException {
case AddCommand.COMMAND_WORD:
return new AddCommandParser().parse(arguments);

case AddECommand.COMMAND_WORD:
return new AddECommandParser().parse(arguments);

case EditCommand.COMMAND_WORD:
return new EditCommandParser().parse(arguments);

case EditECommand.COMMAND_WORD:
return new EditECommandParser().parse(arguments);

case SelectCommand.COMMAND_WORD:
return new SelectCommandParser().parse(arguments);

case DeleteCommand.COMMAND_WORD:
return new DeleteCommandParser().parse(arguments);

case DeleteECommand.COMMAND_WORD:
return new DeleteECommandParser().parse(arguments);

case ClearCommand.COMMAND_WORD:
return new ClearCommand();

Expand All @@ -74,6 +87,9 @@ public Command parseCommand(String userInput) throws ParseException {
case ListCommand.COMMAND_WORD:
return new ListCommand();

case ListECommand.COMMAND_WORD:
return new ListECommand();

case HistoryCommand.COMMAND_WORD:
return new HistoryCommand();

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/logic/parser/CliSyntax.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class CliSyntax {
public static final Prefix PREFIX_TAG = new Prefix("t/");
public static final Prefix PREFIX_AVATOR = new Prefix("av/");
public static final Prefix PREFIX_DESCRIPTION = new Prefix("d/");
public static final Prefix PREFIX_VENUE = new Prefix("n/");
public static final Prefix PREFIX_VENUE = new Prefix("v/");
public static final Prefix PREFIX_START_TIME = new Prefix("s/");
public static final Prefix PREFIX_END_TIME = new Prefix("e/");
public static final Prefix PREFIX_LABEL = new Prefix("l/");
Expand Down
29 changes: 29 additions & 0 deletions src/main/java/seedu/address/logic/parser/DeleteECommandParser.java
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 src/main/java/seedu/address/logic/parser/EditECommandParser.java
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 src/main/java/seedu/address/logic/parser/ParserUtilForEvent.java
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);
}

}

0 comments on commit 70242d6

Please sign in to comment.