Skip to content

Commit

Permalink
Merge pull request #241 from Kailash201/v1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
ZD292 authored Nov 10, 2023
2 parents 489d17b + 1454c07 commit 2ad215a
Show file tree
Hide file tree
Showing 16 changed files with 710 additions and 97 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ public AddCommand parse(String args) throws ParseException {
Phone phone = ParserUtil.parsePhone(argMultimap.getValue(PREFIX_PHONE).get());
Email email = ParserUtil.parseEmail(argMultimap.getValue(PREFIX_EMAIL).get());

// edit here of add more than 1 group
if (arePrefixesPresent(argMultimap, PREFIX_GROUPTAG)) {
Group group = ParserUtil.parseGroup(argMultimap.getValue(PREFIX_GROUPTAG).get());
groupList.add(group);
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/seedu/address/logic/parser/CliSyntax.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ public class CliSyntax {
public static final Prefix PREFIX_EMAIL = new Prefix("e/");
public static final Prefix PREFIX_GROUPTAG = new Prefix("g/");
public static final Prefix PREFIX_ADDRESS = new Prefix("a/");
public static final Prefix PREFIX_TAG = new Prefix("t/");

public static final Prefix PREFIX_FREETIME = new Prefix("t/");
public static final Prefix PREFIX_ENDINTERVAL = new Prefix(";");
public static final Prefix PREFIX_TOFRO = new Prefix("-");
public static final Prefix PREFIX_GROUPREMARK = new Prefix("r/");
public static final Prefix PREFIX_DURATION = new Prefix("d/");

Expand Down
27 changes: 0 additions & 27 deletions src/main/java/seedu/address/logic/parser/ParserUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,33 +131,6 @@ public static Group parseGroup(String groupName) throws ParseException {
return group;
}

/**
* Parses a {@code String tag} into a {@code Tag}.
* Leading and trailing whitespaces will be trimmed.
*
* @throws ParseException if the given {@code tag} is invalid.
*/
public static Tag parseTag(String tag) throws ParseException {
requireNonNull(tag);
String trimmedTag = tag.trim();
if (!Tag.isValidTagName(trimmedTag)) {
throw new ParseException(Tag.MESSAGE_CONSTRAINTS);
}
return new Tag(trimmedTag);
}

/**
* Parses {@code Collection<String> tags} into a {@code Set<Tag>}.
*/
public static Set<Tag> parseTags(Collection<String> tags) throws ParseException {
requireNonNull(tags);
final Set<Tag> tagSet = new HashSet<>();
for (String tagName : tags) {
tagSet.add(parseTag(tagName));
}
return tagSet;
}

/**
* Parses a {@code String groupName} into a {@code Group}.
* Leading and trailing whitespaces will be trimmed.
Expand Down
11 changes: 4 additions & 7 deletions src/main/java/seedu/address/model/ModelManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -218,13 +218,10 @@ public Pair<Person, Group> ungroupPerson(String personName, String groupName) th
public String addTimeToPerson(Name toAddPerson, ArrayList<TimeInterval> toAddTime) throws CommandException {
requireNonNull(toAddPerson);
Person person = addressBook.getPerson(toAddPerson.fullName);
try {
String msg = person.addFreeTime(toAddTime);
forceUpdateList();
return msg;
} catch (CommandException e) {
throw new CommandException(e.getMessage());
}
String msg = person.addFreeTime(toAddTime);
forceUpdateList();
return msg;

}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/seedu/address/model/Time.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public class Time {
* @param hour The time of the day.
*/
public Time(DayOfWeek day, LocalTime hour) {
requireNonNull(day);
requireNonNull(hour);
this.day = day;
this.hour = hour;
}
Expand Down
16 changes: 7 additions & 9 deletions src/main/java/seedu/address/model/TimeInterval.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package seedu.address.model;


import static java.util.Objects.requireNonNull;
import static seedu.address.logic.parser.CliSyntax.PREFIX_FREETIME;

import java.time.DayOfWeek;
Expand Down Expand Up @@ -31,6 +32,8 @@ public class TimeInterval {
* @param end The end time of the interval.
*/
public TimeInterval(Time start, Time end) {
requireNonNull(start);
requireNonNull(end);
this.start = start;
this.end = end;
}
Expand All @@ -42,15 +45,10 @@ public TimeInterval(Time start, Time end) {
* @return Returns true if the timeInterval overlaps with one another.
*/
public static boolean isTimeIntervalOverlap(ArrayList<TimeInterval> intervals) {
for (int i = 0; i < intervals.size(); i++) {
for (int j = i + 1; j < intervals.size(); j++) {
int startComparison = intervals.get(i).compareStart(intervals.get(j));
int endComparison = intervals.get(i).compareEnd(intervals.get(j));
boolean noClash = ((startComparison < 0 && endComparison < 0)
|| (startComparison > 0 && endComparison > 0));
if ((startComparison == 0 && endComparison == 0) || !noClash) {
return true;
}
intervals.sort(TimeInterval::compareStart);
for (int i = 0; i < intervals.size() - 1; i++) {
if (intervals.get(i).isClash(intervals.get(i + 1))) {
return true;
}
}
return false;
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/seedu/address/model/person/Person.java
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,8 @@ public boolean equals(Object other) {
return name.equals(otherPerson.name)
&& phone.equals(otherPerson.phone)
&& email.equals(otherPerson.email)
&& personGroups.equals(otherPerson.personGroups);
&& personGroups.equals(otherPerson.personGroups)
&& timeIntervalList.equals(otherPerson.timeIntervalList);
}

@Override
Expand All @@ -205,7 +206,7 @@ public void addFreeTime(TimeInterval toAddFreeTime) {
this.timeIntervalList.addTime(toAddFreeTime);
}

public String addFreeTime(ArrayList<TimeInterval> toAddFreeTime) throws CommandException {
public String addFreeTime(ArrayList<TimeInterval> toAddFreeTime) {
return this.timeIntervalList.addTime(toAddFreeTime);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void execute_newPerson_success() {
public void execute_duplicatePerson_throwsCommandException() {
Person personInList = model.getAddressBook().getPersonList().get(0);
assertCommandFailure(new AddCommand(personInList), model,
AddCommand.MESSAGE_DUPLICATE_PERSON);
String.format(AddCommand.MESSAGE_DUPLICATE_PERSON, personInList.getName().toString()));
}

}
Loading

0 comments on commit 2ad215a

Please sign in to comment.