Skip to content

Commit

Permalink
Merge branch 'master' into v1.2-tests-JK
Browse files Browse the repository at this point in the history
  • Loading branch information
SoulUseless committed Mar 16, 2021
2 parents f98f755 + 3f753c7 commit ae91cec
Show file tree
Hide file tree
Showing 9 changed files with 231 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package seedu.address.logic.parser;


import static java.util.Objects.requireNonNull;

import java.util.Collection;
Expand Down Expand Up @@ -112,7 +113,6 @@ public static Time parseTime(String time) throws ParseException {
* Parses a {@code String priority} into a {@code priority}.
* Leading and trailing whitespaces will be trimmed.
*
* @throws ParseException if the given {@code priority} is invalid.
*/
public static Priority parsePriority(String priority) throws ParseException {
requireNonNull(priority);
Expand All @@ -129,16 +129,19 @@ public static Priority parsePriority(String priority) throws ParseException {
*
* @throws ParseException if the given {@code category} is invalid.
*/
public static Category parseCategory(String category) {
public static Category parseCategory(String category) throws ParseException {
requireNonNull(category);
String trimmedCategory = category.trim();
if (!Category.isValidCategoryName(trimmedCategory)) {
throw new ParseException(Category.MESSAGE_CONSTRAINTS);
}
return new Category(trimmedCategory);
}

/**
* Parses {@code Collection<String> categories} into a {@code Set<Category>}.
*/
public static Set<Category> parseCategories(Collection<String> categories) {
public static Set<Category> parseCategories(Collection<String> categories) throws ParseException {
requireNonNull(categories);
final Set<Category> categorySet = new HashSet<>();
for (String categoryName : categories) {
Expand Down
26 changes: 24 additions & 2 deletions src/main/java/seedu/address/model/common/Category.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@
import static java.util.Objects.requireNonNull;
import static seedu.address.commons.util.AppUtil.checkArgument;

/**
* Represents a Category in SOChedule.
* Guarantees: immutable; categoryName is valid as declared in {@link #isValidCategoryName(String)}.
*/
public class Category {

public static final String MESSAGE_CONSTRAINTS = "Category names should be alphanumeric";
public static final String VALIDATION_REGEX = "\\p{Alnum}+";

private String categoryName;
public final String categoryName;

/**
* Constructs a {@code Category}.
Expand All @@ -28,12 +32,30 @@ public static boolean isValidCategoryName(String test) {
return test.matches(VALIDATION_REGEX);
}

/**
* Returns the name of the category.
*
* @return the name of the category.
*/
public String getCategoryName() {
return this.categoryName;
}

@Override
public boolean equals(Object other) {
return other == this // short circuit if same object
|| (other instanceof Category // instanceof handles nulls
&& categoryName.equals(((Category) other).categoryName)); // state check
}

@Override
public int hashCode() {
return categoryName.hashCode();
}

@Override
public String toString() {
return this.categoryName;
return categoryName;
}

}
20 changes: 18 additions & 2 deletions src/main/java/seedu/address/model/common/Date.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

/**
* Represents a Category in SOChedule.
* Guarantees: immutable; date is valid as declared in {@link #isValidDate(String)}.
*/
public class Date {
public static final DateTimeFormatter DATE_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd");
public static final String MESSAGE_CONSTRAINTS =
"Date should be represented in the format of yyyy-MM-dd";
public static final String VALIDATION_REGEX = "^[0-9]{4}-(1[0-2]|0[1-9])-(3[01]|[12][0-9]|0[1-9])$";

private LocalDate date;
public final LocalDate date;

/**
* Constructs an {@code Date}.
Expand All @@ -26,7 +30,7 @@ public Date(String dateString) {
}

public LocalDate getDate() {
return this.date;
return date;
}

/**
Expand All @@ -36,6 +40,18 @@ public static boolean isValidDate(String test) {
return test.matches(VALIDATION_REGEX);
}

@Override
public boolean equals(Object other) {
return other == this // short circuit if same object
|| (other instanceof Date // instanceof handles nulls
&& date.equals(((Date) other).date)); // state check
}

@Override
public int hashCode() {
return date.hashCode();
}

/**
* Returns the date in a string.
*/
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/seedu/address/model/common/Tag.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public static boolean isValidTagName(String test) {
@Override
public boolean equals(Object other) {
return other == this // short circuit if same object
|| (other instanceof seedu.address.model.common.Tag // instanceof handles nulls
&& tagName.equals(((seedu.address.model.common.Tag) other).tagName)); // state check
|| (other instanceof Tag // instanceof handles nulls
&& tagName.equals(((Tag) other).tagName)); // state check
}

@Override
Expand Down
32 changes: 24 additions & 8 deletions src/main/java/seedu/address/model/event/Time.java
Original file line number Diff line number Diff line change
@@ -1,34 +1,38 @@
package seedu.address.model.event;

import static java.util.Objects.requireNonNull;
import static seedu.address.commons.util.AppUtil.checkArgument;

import java.time.LocalTime;
import java.time.format.DateTimeFormatter;

/**
* Represents a Time in SOChedule.
* Guarantees: immutable; time is valid as declared in {@link #isValidTime(String)}.
*/
public class Time {

public static final DateTimeFormatter TIME_FORMATTER = DateTimeFormatter.ofPattern("HH:mm");
public static final String MESSAGE_CONSTRAINTS =
"Time should be represented in 24-hour notation, in the format of HH:mm";
public static final String VALIDATION_REGEX = "^(2[0-3]|[01]?[0-9]):([0-5]?[0-9])$";

private LocalTime time;
public final LocalTime time;


/**
* Constructs an {@code Time}.
*
* @param time A valid time.
* @param timeString A valid time.
*/
public Time(String time) {
checkArgument(isValidTime(time), MESSAGE_CONSTRAINTS);
if (time != null) {
this.time = LocalTime.parse(time, TIME_FORMATTER);
}
public Time(String timeString) {
requireNonNull(timeString);
checkArgument(isValidTime(timeString), MESSAGE_CONSTRAINTS);
time = LocalTime.parse(timeString, TIME_FORMATTER);
}

public LocalTime getTime() {
return this.time;
return time;
}

/**
Expand All @@ -38,6 +42,18 @@ public static boolean isValidTime(String test) {
return test == null || test.matches(VALIDATION_REGEX);
}

@Override
public boolean equals(Object other) {
return other == this // short circuit if same object
|| (other instanceof Time // instanceof handles nulls
&& time.equals(((Time) other).time)); // state check
}

@Override
public int hashCode() {
return time.hashCode();
}

/**
* Returns the time in a string.
*/
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/seedu/address/model/task/CompletionStatus.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package seedu.address.model.task;

/**
* Represents the completion status of a task in SOChedule.
* Guarantees: the status is either COMPLETE or INCOMPLETE.
*/
public class CompletionStatus {
public static final String VALIDATION_REGEX = "COMPLETE|INCOMPLETE";
public static final String MESSAGE_CONSTRAINTS =
Expand Down Expand Up @@ -70,6 +74,18 @@ public static boolean isValidStatus(String test) {
return test.matches(VALIDATION_REGEX);
}

@Override
public boolean equals(Object other) {
return other == this // short circuit if same object
|| (other instanceof CompletionStatus // instanceof handles nulls
&& completionStatus.equals(((CompletionStatus) other).completionStatus)); // state check
}

@Override
public int hashCode() {
return completionStatus.hashCode();
}

/**
* Returns a String representation of {@code CompletionStatus}.
*/
Expand Down
22 changes: 19 additions & 3 deletions src/main/java/seedu/address/model/task/Priority.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@

import static seedu.address.commons.util.AppUtil.checkArgument;

/**
* Represents a Priority in SOChedule.
* Guarantees: immutable; priority is valid as declared in {@link #isValidPriority(String)}.
*/
public class Priority {

public static final String MESSAGE_CONSTRAINTS =
"Priority should be represented as an integer from 0 to 9";
public static final String VALIDATION_REGEX = "^[0-9]$";
public static final int DEFAULT_PRIORITY = 5;


private int priority;
public final int priority;

/**
* Constructs an {@code Priority}.
Expand All @@ -27,7 +30,7 @@ public Priority(String priorityString) {
}

public int getPriority() {
return this.priority;
return priority;
}

/**
Expand All @@ -37,6 +40,19 @@ public static boolean isValidPriority(String test) {
return test == null || test.matches(VALIDATION_REGEX);
}

@Override
public boolean equals(Object other) {
return other == this // short circuit if same object
|| (other instanceof Priority // instanceof handles nulls
&& priority == ((Priority) other).priority); // state check
}

@Override
public int hashCode() {
return priority;
}

@Override
public String toString() {
return Integer.toString(this.priority);
}
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/seedu/address/model/task/Task.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class Task {
private final CompletionStatus completionStatus = new CompletionStatus();
private final Set<Category> categories = new HashSet<>();
private final Set<Tag> tags = new HashSet<>();

/**
* Name field must be present and not null.
*/
Expand Down Expand Up @@ -99,7 +100,8 @@ public boolean equals(Object other) {
&& otherTask.getDeadline().equals(getDeadline())
&& otherTask.getPriority().equals(getPriority())
&& otherTask.getCategories().equals(getCategories())
&& otherTask.getTags().equals(getTags());
&& otherTask.getTags().equals(getTags())
&& otherTask.getCompletionStatus().equals(getCompletionStatus());
}

@Override
Expand Down
Loading

0 comments on commit ae91cec

Please sign in to comment.