Skip to content

Commit

Permalink
Merge pull request nus-cs2103-AY2223S1#88 from ciaoosuuu/fix-bugs
Browse files Browse the repository at this point in the history
Fix delete item command and item conflict logic
  • Loading branch information
ciaoosuuu authored Oct 25, 2022
2 parents 3b3dcac + 058aea6 commit a10528f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
public class MultiIndex {
public static final String MESSAGE_CONSTRAINTS =
"Index should only contain positive integers separated by a decimal point";
public static final String VALIDATION_REGEX = "\\d+\\.\\d+";
public static final String VALIDATION_REGEX = "\\d+\\.?\\d*";
private List<Index> indices;

public MultiIndex() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public AddItemCommand parse(String args) throws ParseException {

String description = ParserUtil.parseDescription(argMultimap.getValue(PREFIX_DESCRIPTION).get());
Priority priority;

if (arePrefixesPresent(argMultimap, PREFIX_PRIORITY)) {
priority = ParserUtil.parsePriority(argMultimap.getValue(PREFIX_PRIORITY).get());
} else {
Expand All @@ -54,7 +55,7 @@ public AddItemCommand parse(String args) throws ParseException {
if (arePrefixesPresent(argMultimap, PREFIX_DURATION)) {
duration = ParserUtil.parseDuration(argMultimap.getValue(PREFIX_DURATION).get());
} else {
duration = null;
duration = ParserUtil.parseDuration("0");
}

Item item = new Item(description, priority, cost, duration);
Expand Down
26 changes: 13 additions & 13 deletions src/main/java/seedu/waddle/logic/parser/ParserUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -199,19 +199,6 @@ public static Cost parseCost(String cost) throws ParseException {
return new Cost(trimmedCost);
}

/**
* Parses a {@code int Day Number}.
* Leading and trailing whitespaces will be trimmed.
*/
public static DayNumber parseDayNumber(String dayNumber) throws ParseException {
requireNonNull(dayNumber);
String trimmedDayNumber = dayNumber.trim();
if (!DayNumber.isValidDayNumber(trimmedDayNumber)) {
throw new ParseException(DayNumber.MESSAGE_CONSTRAINTS);
}
return new DayNumber(trimmedDayNumber);
}

/**
* Parses a {@code String duration} into a {@code Duration}.
* Leading and trailing whitespaces will be trimmed.
Expand All @@ -227,6 +214,19 @@ public static Duration parseDuration(String duration) throws ParseException {
return new Duration(trimmedDuration);
}

/**
* Parses a {@code int Day Number}.
* Leading and trailing whitespaces will be trimmed.
*/
public static DayNumber parseDayNumber(String dayNumber) throws ParseException {
requireNonNull(dayNumber);
String trimmedDayNumber = dayNumber.trim();
if (!DayNumber.isValidDayNumber(trimmedDayNumber)) {
throw new ParseException(DayNumber.MESSAGE_CONSTRAINTS);
}
return new DayNumber(trimmedDayNumber);
}

/**
* Parses a {@code String startTime} into a {@code StartTime}.
* Leading and trailing whitespaces will be trimmed.
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/seedu/waddle/model/item/Day.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,12 @@ public ArrayList<Item> getConflictingItems(Item newItem) {
// same start time
boolean sameStartTime = item.getStartTime().equals(newItem.getStartTime());
// start time of new item is within the duration of a preceding item
boolean startTimeConflict = newItem.getStartTime().isBefore(item.getEndTime());
boolean startTimeConflict = newItem.getStartTime().isAfter(item.getStartTime())
&& newItem.getStartTime().isBefore(item.getEndTime());
// end time of new item eats into a proceeding item
boolean endTimeConflict = newItem.getEndTime().isAfter(item.getStartTime());
boolean endTimeConflict = newItem.getEndTime().isAfter(item.getStartTime())
&& newItem.getEndTime().isBefore(item.getEndTime());


if (sameStartTime || startTimeConflict || endTimeConflict) {
conflictingItems.add(item);
Expand Down

0 comments on commit a10528f

Please sign in to comment.