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

Add more data formats for schedule command #122

Merged
merged 2 commits into from
Apr 2, 2024
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
11 changes: 4 additions & 7 deletions src/main/java/seedu/address/logic/commands/DeleteCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,15 @@

model.deletePerson(personToDelete);
return new CommandResult(String.format(MESSAGE_DELETE_PERSON_SUCCESS, Messages.format(personToDelete)));
}
else {
} else {
List<Person> peopleToDelete = new ArrayList<Person>();
Set<Group> deletedGroup = new HashSet<Group>();
deletedGroup.add(group);


for (int i = 0; i < lastShownList.size(); i++) {
if (lastShownList.get(i).getGroups().equals(deletedGroup) ) {
if (lastShownList.get(i).getGroups().equals(deletedGroup)) {
peopleToDelete.add(lastShownList.get(i));

Check warning on line 76 in src/main/java/seedu/address/logic/commands/DeleteCommand.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/commands/DeleteCommand.java#L76

Added line #L76 was not covered by tests
}
}
System.out.println(lastShownList.size());
Expand All @@ -83,10 +82,10 @@
}

for (int i = 0; i < peopleToDelete.size(); i++) {
model.deletePerson(peopleToDelete.get(i));

Check warning on line 85 in src/main/java/seedu/address/logic/commands/DeleteCommand.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/commands/DeleteCommand.java#L85

Added line #L85 was not covered by tests
}

return new CommandResult(String.format(MESSAGE_DELETE_GROUP_SUCCESS, this.group.groupName));

Check warning on line 88 in src/main/java/seedu/address/logic/commands/DeleteCommand.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/commands/DeleteCommand.java#L88

Added line #L88 was not covered by tests
}
}

Expand All @@ -104,11 +103,10 @@
DeleteCommand otherDeleteCommand = (DeleteCommand) other;
if (nusId != null) {
return nusId.equals(otherDeleteCommand.nusId);
}
else if (group != null) {
} else if (group != null) {
return group.equals(otherDeleteCommand.group);
}
return false;

Check warning on line 109 in src/main/java/seedu/address/logic/commands/DeleteCommand.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/commands/DeleteCommand.java#L109

Added line #L109 was not covered by tests
}

@Override
Expand All @@ -117,12 +115,11 @@
return new ToStringBuilder(this)
.add("targetNusId", nusId.toString())
.toString();
}
else if (group != null) {
} else if (group != null) {
return new ToStringBuilder(this)
.add("targetGroup", group.toString())
.toString();

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

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/commands/DeleteCommand.java#L119-L121

Added lines #L119 - L121 were not covered by tests
}
return null;

Check warning on line 123 in src/main/java/seedu/address/logic/commands/DeleteCommand.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/commands/DeleteCommand.java#L123

Added line #L123 was not covered by tests
}
}
15 changes: 3 additions & 12 deletions src/main/java/seedu/address/logic/parser/DeleteCommandParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,27 +28,18 @@
try {

if (argMultimap.getValue(PREFIX_NUSID).isPresent() && argMultimap.getValue(PREFIX_GROUP).isPresent()) {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, DeleteCommand.MESSAGE_USAGE));

Check warning on line 31 in src/main/java/seedu/address/logic/parser/DeleteCommandParser.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/parser/DeleteCommandParser.java#L31

Added line #L31 was not covered by tests
}
else if (argMultimap.getValue(PREFIX_GROUP).isPresent()) {
} else if (argMultimap.getValue(PREFIX_GROUP).isPresent()) {
return new DeleteCommand(ParserUtil.parseGroup(argMultimap.getValue(PREFIX_GROUP).get()));
}
else if (argMultimap.getValue(PREFIX_NUSID).isPresent()) {
} else if (argMultimap.getValue(PREFIX_NUSID).isPresent()) {
return new DeleteCommand(ParserUtil.parseNusId(argMultimap.getValue(PREFIX_NUSID).get()));

}

else {
} else {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, DeleteCommand.MESSAGE_USAGE));
}




} catch (ParseException pe) {
throw new ParseException(
String.format(MESSAGE_INVALID_COMMAND_FORMAT, DeleteCommand.MESSAGE_USAGE), pe);
}
}

}
20 changes: 16 additions & 4 deletions src/main/java/seedu/address/model/person/Schedule.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,27 @@
import static java.util.Objects.requireNonNull;
import static seedu.address.commons.util.AppUtil.checkArgument;

import java.util.ArrayList;
import java.util.List;

/**
* Represents a Person's schedule in the address book with the user.
* Guarantees: immutable; is valid as declared in {@link #isValidSchedule(String)}
*/
public class Schedule {

public static final String MESSAGE_CONSTRAINTS =
"Schedule should contain only dates formatted as DD/MM/YYYY or DD-MM-YYYY";
"Schedule should contain only dates formatted as DD/MM/YYYY, DD-MM-YYYY, "
+ "DD.MM.YYYY, DD MMM YYYY, MMM DD, YYYY";

/*
* Date should be formatted as DD/MM/YYYY or DD-MM-YYYY
*/
public static final String VALIDATION_REGEX_WITH_DATA =
"^([0]?[1-9]|[1|2][0-9]|[3][0|1])[./-]([0]?[1-9]|[1][0-2])[./-]([0-9]{4}|[0-9]{2})$";
public static final List<String> VALIDATION_REGEX_WITH_DATA = new ArrayList<>(
List.of(
"^([0]?[1-9]|[1|2][0-9]|[3][0|1])[./-]([0]?[1-9]|[1][0-2])[./-]([0-9]{4}|[0-9]{2})$",
"^(0?[1-9]|[1-2][0-9]|3[01])\\s+(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\\s+\\d{4}$",
"^(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\\s+(0?[1-9]|[1-2][0-9]|3[01]),\\s+\\d{4}$"));

public static final String VALIDATION_REGEX_WITHOUT_DATA = "^$";

Expand All @@ -39,7 +46,12 @@ public Schedule(String date) {
* Returns true if a given string is a valid date.
*/
public static boolean isValidSchedule(String test) {
return test.matches(VALIDATION_REGEX_WITH_DATA) || test.matches(VALIDATION_REGEX_WITHOUT_DATA);
for (String regex : VALIDATION_REGEX_WITH_DATA) {
if (test.matches(regex)) {
return true;
}
}
return test.matches(VALIDATION_REGEX_WITHOUT_DATA);
}


Expand Down
Loading