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

Fix bugs in logic classes #247

Merged
merged 4 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion src/main/java/seedu/address/logic/commands/AddEventCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
+ "h/2020-03-02 1400 1600 "
+ "r/y \n"
+ "Note: "
+ "If you are adding a dated event, then index should be the index of "
+ "Index should be the index of "
+ "the friend you are adding the dated event to or 'user' "
+ "if you would like to add the event to yourself \n";

Expand Down Expand Up @@ -111,4 +111,26 @@
}
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;

Check warning on line 117 in src/main/java/seedu/address/logic/commands/AddEventCommand.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/commands/AddEventCommand.java#L117

Added line #L117 was not covered by tests
}

if (!(o instanceof AddEventCommand)) {
return false;

Check warning on line 121 in src/main/java/seedu/address/logic/commands/AddEventCommand.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/commands/AddEventCommand.java#L121

Added line #L121 was not covered by tests
}

AddEventCommand other = (AddEventCommand) o;
if (index == null && other.index != null) {
return false;

Check warning on line 126 in src/main/java/seedu/address/logic/commands/AddEventCommand.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/commands/AddEventCommand.java#L126

Added line #L126 was not covered by tests
} else if (index != null && other.index == null) {
return false;

Check warning on line 128 in src/main/java/seedu/address/logic/commands/AddEventCommand.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/commands/AddEventCommand.java#L128

Added line #L128 was not covered by tests
} else {
return eventName.equals(other.eventName)
&& schedule.equals(other.schedule)
&& reminder.equals(other.reminder);
}
}

}
46 changes: 34 additions & 12 deletions src/main/java/seedu/address/logic/commands/AddScheduleCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@
+ "Example: " + COMMAND_WORD
+ " 1"
+ " type/cca"
+ " en/CS2103T Lecture\n"
+ " en/Basketball\n"
+ " h/Monday 1400 1600\n"
+ "NOTE: If you want to add an event to yourself, use index user\n"
+ "NOTE: If you want to add a cca/module to yourself, use index user\n"
+ "Example: " + COMMAND_WORD
+ " user"
+ " type/cca"
+ " en/CS2103T Lecture"
+ " en/Basketball"
+ " h/Monday 1400 1600";

public static final String MESSAGE_SUCCESS = "New event added: ";
Expand All @@ -45,10 +45,10 @@

/**
* Constructs an AddScheduleCommand object with the specified event name, index, schedule and event type.
* @param eventName
* @param eventType
* @param index
* @param schedule
* @param eventName The name of the event.
* @param eventType The type of the event.
* @param index The index of the friend to add the event to.
* @param schedule The schedule of the event.
*/
public AddScheduleCommand(String eventName, String eventType, Index index, String schedule) {
this.eventName = eventName;
Expand All @@ -59,9 +59,9 @@

/**
* Constructs an AddScheduleCommand object with the specified event name, schedule and event type.
* @param eventName
* @param eventType
* @param schedule
* @param eventName The name of the event.
* @param eventType The type of the event.
* @param schedule The schedule of the event.
*/
public AddScheduleCommand(String eventName, String eventType, String schedule) {
this(eventName, eventType, null, schedule);
Expand Down Expand Up @@ -108,8 +108,8 @@
+ friend.getName(), false, false, true, false);
case "module":
// If the event type is module, add the event to the friend's module schedule
Schedule friendScedule = friend.getSchedule();
friendScedule.addModule(eventName + " " + schedule);
friendSchedule = friend.getSchedule();
friendSchedule.addModule(eventName + " " + schedule);
return new CommandResult(MESSAGE_SUCCESS
+ "\nModule:\n"
+ eventName
Expand All @@ -126,4 +126,26 @@
throw new CommandException(e.getMessage());
}
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;

Check warning on line 133 in src/main/java/seedu/address/logic/commands/AddScheduleCommand.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/commands/AddScheduleCommand.java#L133

Added line #L133 was not covered by tests
}

if (!(o instanceof AddScheduleCommand)) {
return false;

Check warning on line 137 in src/main/java/seedu/address/logic/commands/AddScheduleCommand.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/commands/AddScheduleCommand.java#L137

Added line #L137 was not covered by tests
}

AddScheduleCommand other = (AddScheduleCommand) o;
if (index == null && other.index != null) {
return false;

Check warning on line 142 in src/main/java/seedu/address/logic/commands/AddScheduleCommand.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/commands/AddScheduleCommand.java#L142

Added line #L142 was not covered by tests
} else if (index != null && other.index == null) {
return false;

Check warning on line 144 in src/main/java/seedu/address/logic/commands/AddScheduleCommand.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/commands/AddScheduleCommand.java#L144

Added line #L144 was not covered by tests
} else {
return eventName.equals(other.eventName)
&& eventType.equals(other.eventType)
&& schedule.equals(other.schedule);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import seedu.address.logic.Messages;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.person.Name;
import seedu.address.model.person.Person;
import seedu.address.model.person.timetable.FreeTime;
import seedu.address.model.person.timetable.Schedule;
Expand Down Expand Up @@ -161,26 +160,6 @@ public StringBuilder createCommonFreeTimeMessage(ArrayList<Person> overlappingCo
}
}

/**
* Returns a List of common free times with specified contact.
*
* @param model {@code Model} which the command should operate on.
* @param contactName Name of contact to find common free time with.
* @return List of common free times with specified contact.
* @throws CommandException if an error occurs during command execution.
*/
public List<FreeTime> getCommonFreeTimeWith(Model model, Name contactName) throws CommandException {
Person friend = model.getPersonWithName(contactName);
Schedule friendSchedule = friend.getSchedule();
Schedule userSchedule = model.getUser().getSchedule();
List<FreeTime> commonFreeTime = userSchedule.getThisWeeksFreeTimesWith(friendSchedule);
if (commonFreeTime.isEmpty()) {
throw new CommandException(createNoOverlapFriendMessage(friend));
} else {
return commonFreeTime;
}
}

@Override
public boolean equals(Object other) {
if (other == this) {
Expand Down
52 changes: 32 additions & 20 deletions src/main/java/seedu/address/logic/commands/RemoveEventCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,29 +63,20 @@
Person friend;

Schedule userSchedule = model.getUser().getSchedule();
try {
if (index == null) {
userSchedule.deleteDatedEvent(eventName);
return new CommandResult("Dated Event '"
+ eventName
if (index == null) {
userSchedule.deleteDatedEvent(eventName);
return new CommandResult("Dated Event '" + eventName
+ "' deleted from your calendar!", false, false, true, false);
} else {
List<Person> lastShownList = model.getFilteredPersonList();
if (index.getZeroBased() >= lastShownList.size()) {
throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX + "\n"
} else {
List<Person> lastShownList = model.getFilteredPersonList();
if (index.getZeroBased() >= lastShownList.size()) {
throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX + "\n"
+ "Index can be max " + lastShownList.size() + "!");
}
friend = model.getFilteredPersonList().get(index.getZeroBased());
friend.getSchedule().deleteDatedEvent(eventName);
return new CommandResult("Dated Event '"
+ eventName
+ "' deleted from "
+ friend.getName().toString()
+ "'s calendar!", false, false, true, false);
}
} catch (Exception e) {
throw new CommandException("Event " + eventName + " does not exist!\n"
+ "Please check that you have entered the correct event name!\n");
friend = model.getFilteredPersonList().get(index.getZeroBased());
friend.getSchedule().deleteDatedEvent(eventName);
return new CommandResult("Dated Event '" + eventName + "' deleted from "
+ friend.getName().toString() + "'s calendar!", false, false, true, false);
}
}

Expand All @@ -103,4 +94,25 @@
}
return result;
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;

Check warning on line 101 in src/main/java/seedu/address/logic/commands/RemoveEventCommand.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/commands/RemoveEventCommand.java#L101

Added line #L101 was not covered by tests
}

if (!(o instanceof RemoveEventCommand)) {
return false;

Check warning on line 105 in src/main/java/seedu/address/logic/commands/RemoveEventCommand.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/commands/RemoveEventCommand.java#L105

Added line #L105 was not covered by tests
}

RemoveEventCommand other = (RemoveEventCommand) o;
if (index == null && other.index != null) {
return false;

Check warning on line 110 in src/main/java/seedu/address/logic/commands/RemoveEventCommand.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/commands/RemoveEventCommand.java#L110

Added line #L110 was not covered by tests
} else if (index != null && other.index == null) {
return false;

Check warning on line 112 in src/main/java/seedu/address/logic/commands/RemoveEventCommand.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/commands/RemoveEventCommand.java#L112

Added line #L112 was not covered by tests
} else {
return eventName.equals(other.eventName);
}
}

}
101 changes: 56 additions & 45 deletions src/main/java/seedu/address/logic/commands/RemoveScheduleCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@
+ "en/EVENT_NAME\n"
+ "Example: " + COMMAND_WORD
+ " 1"
+ " type/dated"
+ " en/CS2103T Lecture\n"
+ " type/cca"
+ " en/Basketball\n"
+ "NOTE: If you want to remove an event from yourself, use index user\n"
+ "Example: " + COMMAND_WORD
+ " user"
+ " type/dated"
+ " en/CS2103T Lecture";
+ " type/cca"
+ " en/Basketball";

private final String eventName;
private final String eventType;
Expand Down Expand Up @@ -74,56 +74,45 @@
Person friend;

Schedule userSchedule = model.getUser().getSchedule();
try {
if (this.index == null) {
friend = model.getUser();
} else {
List<Person> lastShownList = model.getFilteredPersonList();
if (index.getZeroBased() >= lastShownList.size()) {
throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX + "\n"
if (this.index == null) {
friend = model.getUser();
} else {
List<Person> lastShownList = model.getFilteredPersonList();
if (index.getZeroBased() >= lastShownList.size()) {
throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX + "\n"
+ "Index can be max " + lastShownList.size() + "!");
}
friend = model.getFilteredPersonList().get(index.getZeroBased());
}
switch (eventType) {
// If the event is a cca event, remove it from the specified contact's calendar.
case "cca":
if (index == null) {
userSchedule.deleteCca(eventName);
return new CommandResult("CCA '"
+ eventName
friend = model.getFilteredPersonList().get(index.getZeroBased());
}

switch (eventType) {
case "cca":
if (index == null) {
userSchedule.deleteCca(eventName);
return new CommandResult("CCA '" + eventName
+ "'' deleted from your calendar!", false, false, true, false);
} else {
friend = model.getFilteredPersonList().get(index.getZeroBased());
friend.getSchedule().deleteCca(eventName);
return new CommandResult("CCA '"
+ eventName
+ "'' deleted from "
} else {
friend = model.getFilteredPersonList().get(index.getZeroBased());
friend.getSchedule().deleteCca(eventName);
return new CommandResult("CCA '" + eventName + "'' deleted from "
+ friend.getName().toString()
+ "'s calendar!", false, false, true, false);
}
// If the event is a module event, remove it from the specified contact's calendar.
case "module":
if (index == null) {
userSchedule.deleteModule(eventName);
return new CommandResult("Module" + eventName
}
case "module":
if (index == null) {
userSchedule.deleteModule(eventName);
return new CommandResult("Module '" + eventName
+ "'' deleted from your calendar!", false, false, true, false);
} else {
friend = model.getFilteredPersonList().get(index.getZeroBased());
friend.getSchedule().deleteModule(eventName);
return new CommandResult("Module '"
+ eventName
+ "'' deleted from "
} else {
friend = model.getFilteredPersonList().get(index.getZeroBased());
friend.getSchedule().deleteModule(eventName);
return new CommandResult("Module '" + eventName + "'' deleted from "
+ friend.getName().toString()
+ "'s calendar!", false, false, true, false);
}
// If the event type is invalid, throw an exception.
default:
throw new CommandException("Invalid event type!\n"
+ "Event type must either be 'cca' or 'module'!\n");
}
} catch (Exception e) {
throw new CommandException(e.getMessage());
default:
throw new CommandException("Invalid event type!\n"
+ "Event type must either be 'cca' or 'module'!\n");
}
}

Expand All @@ -139,4 +128,26 @@
}
return result;
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;

Check warning on line 135 in src/main/java/seedu/address/logic/commands/RemoveScheduleCommand.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/commands/RemoveScheduleCommand.java#L135

Added line #L135 was not covered by tests
}

if (!(o instanceof RemoveScheduleCommand)) {
return false;

Check warning on line 139 in src/main/java/seedu/address/logic/commands/RemoveScheduleCommand.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/commands/RemoveScheduleCommand.java#L139

Added line #L139 was not covered by tests
}

RemoveScheduleCommand other = (RemoveScheduleCommand) o;
if (index == null && other.index != null) {
return false;

Check warning on line 144 in src/main/java/seedu/address/logic/commands/RemoveScheduleCommand.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/commands/RemoveScheduleCommand.java#L144

Added line #L144 was not covered by tests
} else if (index != null && other.index == null) {
return false;

Check warning on line 146 in src/main/java/seedu/address/logic/commands/RemoveScheduleCommand.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/commands/RemoveScheduleCommand.java#L146

Added line #L146 was not covered by tests
} else {
return eventName.equals(other.eventName)
&& eventType.equals(other.eventType);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,17 @@ public AddEventCommand parse(String args) throws ParseException {
String schedule = argMultimap.getValue(PREFIX_SCHEDULE).get();
String reminder = argMultimap.getValue(PREFIX_REMINDER).get();

try {
indexString = argMultimap.getPreamble().toLowerCase();
if (indexString.equals("user")) {
return new AddEventCommand(eventName, schedule, reminder);
} else if (Integer.parseInt(indexString) > 0) {
return new AddEventCommand(eventName, ParserUtil.parseIndex(indexString),
schedule, reminder);
} else {
indexString = argMultimap.getPreamble().toLowerCase();
if (indexString.equals("user")) {
return new AddEventCommand(eventName, schedule, reminder);
} else {
try {
Integer.parseInt(indexString);
return new AddEventCommand(eventName, ParserUtil.parseIndex(indexString), schedule, reminder);
} catch (NumberFormatException e) {
throw new ParseException(String.format("Invalid index!" + "\n"
+ "Index can only be 'user' or a positive integer! \n"));
}
} catch (Exception pe) {
throw new ParseException(String.format("Please input an index!" + "\n"
+ "Message Usage:\n" + AddEventCommand.MESSAGE_USAGE));
}
}

Expand Down
Loading
Loading