Skip to content

Commit

Permalink
Rectified some storage bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
chel-seyy committed Nov 11, 2018
1 parent ade6920 commit 3a28e69
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/commons/core/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class Messages {
public static final String MESSAGE_INVALID_TASK_DISPLAYED_INDEX = "The task index provided is invalid";
public static final String MESSAGE_COMPLETED_TASK = "The task has completed already...";
public static final String MESSAGE_TASKS_LISTED_OVERVIEW = "%1$d tasks listed!";
public static final String MESSAGE_ZERO_HOURS_COMPLETION = "It is impossible to complete it in 0 hours ;)";
public static final String MESSAGE_ZERO_HOURS_COMPLETION = "It is impossible to complete it in less than 1 hour ;)";
public static final String MESSAGE_INVALID_DEADLINE = "The date selected does not exist";
public static final String MESSAGE_DEADLINE_CONTAINS_ILLEGAL_CHARACTERS = "Input deadline "
+ "contains illegal characters";
Expand Down
9 changes: 8 additions & 1 deletion src/main/java/seedu/address/storage/XmlAdaptedTask.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package seedu.address.storage;

import static seedu.address.commons.core.Messages.MESSAGE_ZERO_HOURS_COMPLETION;
import static seedu.address.commons.util.StringUtil.isNonZeroUnsignedInteger;
import static seedu.address.logic.parser.ParserUtil.MESSAGE_INVALID_HOURS;

Expand Down Expand Up @@ -184,7 +185,7 @@ public Task toModelType() throws IllegalValueException {

// Check validity of completed num of hours
final int modelCompletedNumOfHours;
if (!completedNumOfHours.equals("-1") || Integer.valueOf(completedNumOfHours) < -1) {
if (completedNumOfHours == null) {
throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT,
"Number of hours taken to complete"));
} else {
Expand All @@ -195,6 +196,12 @@ public Task toModelType() throws IllegalValueException {
//Boolean cannot be checked for null --> if (isCompleted == null)
final boolean modelIsCompleted = isCompleted;

if (isCompleted && modelCompletedNumOfHours <= 0) {
throw new IllegalValueException(MESSAGE_ZERO_HOURS_COMPLETION);
} else if (!isCompleted && modelCompletedNumOfHours > 0) {
throw new IllegalValueException("Task is not completed yet ...");
}

// Check validity of Milestones
final List<Milestone> milestoneEntries = new ArrayList<Milestone>();
if (milestonelist != null && !milestonelist.isEmpty()) {
Expand Down

0 comments on commit 3a28e69

Please sign in to comment.