Skip to content

Commit

Permalink
Merge pull request #1 from CS2103AUG2016-F10-C3/Add-Task-package
Browse files Browse the repository at this point in the history
Added relevant classes in a new package
  • Loading branch information
ravishwetha authored Oct 6, 2016
2 parents 789d938 + 062293e commit 9e1e9b6
Show file tree
Hide file tree
Showing 5 changed files with 244 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/logic/commands/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class AddCommand extends Command {

public static final String COMMAND_WORD = "add";

public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds a person to the address book. "
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds a task to the GTD. "
+ "Parameters: NAME p/PHONE e/EMAIL a/ADDRESS [t/TAG]...\n"
+ "Example: " + COMMAND_WORD
+ " John Doe p/98765432 e/johnd@gmail.com a/311, Clementi Ave 2, #02-25 t/friends t/owesMoney";
Expand Down
54 changes: 54 additions & 0 deletions src/main/java/seedu/address/model/task/DueDate.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package seedu.address.model.task;

import seedu.address.commons.exceptions.IllegalValueException;

/**
* Represents a Task's due date in the address book.
* Guarantees: immutable; is valid as declared in {@link #isValidDueDate(String)}
*/
public class DueDate {

public static final String MESSAGE_DUEDATE_CONSTRAINTS = "Task duedate numbers should only contain numbers";
public static final String DUEDATE_VALIDATION_REGEX = "\\d+";

public final String value;

/**
* Validates given due date.
*
* @throws IllegalValueException if given due date string is invalid.
*/
public DueDate(String duedate) throws IllegalValueException {
assert duedate != null;
duedate = duedate.trim();
if (!isValidDueDate(duedate)) {
throw new IllegalValueException(MESSAGE_DUEDATE_CONSTRAINTS);
}
this.value = duedate;
}

/**
* Returns true if a given string is a valid person due date number.
*/
public static boolean isValidDueDate(String test) {
return test.matches(DUEDATE_VALIDATION_REGEX);
}

@Override
public String toString() {
return value;
}

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

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

}
55 changes: 55 additions & 0 deletions src/main/java/seedu/address/model/task/Name.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package seedu.address.model.task;

import seedu.address.commons.exceptions.IllegalValueException;

/**
* Represents a Person's name in the address book.
* Guarantees: immutable; is valid as declared in {@link #isValidName(String)}
*/
public class Name {

public static final String MESSAGE_NAME_CONSTRAINTS = "Person names should be spaces or alphanumeric characters";
public static final String NAME_VALIDATION_REGEX = "[\\p{Alnum} ]+";

public final String fullName;

/**
* Validates given name.
*
* @throws IllegalValueException if given name string is invalid.
*/
public Name(String name) throws IllegalValueException {
assert name != null;
name = name.trim();
if (!isValidName(name)) {
throw new IllegalValueException(MESSAGE_NAME_CONSTRAINTS);
}
this.fullName = name;
}

/**
* Returns true if a given string is a valid person name.
*/
public static boolean isValidName(String test) {
return test.matches(NAME_VALIDATION_REGEX);
}


@Override
public String toString() {
return fullName;
}

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

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

}
57 changes: 57 additions & 0 deletions src/main/java/seedu/address/model/task/ReadOnlyTask.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package seedu.address.model.task;

import seedu.address.model.tag.UniqueTagList;

/**
* A read-only immutable interface for a Task in the GTD.
* Implementations should guarantee: details are present and not null, field values are validated.
*/
public interface ReadOnlyTask {

Name getName();
DueDate getDueDate();

/**
* The returned TagList is a deep copy of the internal TagList,
* changes on the returned list will not affect the task's internal tags.
*/
UniqueTagList getTags();

/**
* Returns true if both have the same state. (interfaces cannot override .equals)
*/
default boolean isSameStateAs(ReadOnlyTask other) {
return other == this // short circuit if same object
|| (other != null // this is first to avoid NPE below
&& other.getName().equals(this.getName()) // state checks here onwards
&& other.getDueDate().equals(this.getDueDate()));
}

/**
* Formats the task as text, showing all contact details.
*/
default String getAsText() {
final StringBuilder builder = new StringBuilder();
builder.append(getName())
.append(" DueDate: ")
.append(getDueDate())
.append(" Tags: ");
getTags().forEach(builder::append);
return builder.toString();
}

/**
* Returns a string representation of this Task's tags
*/
default String tagsString() {
final StringBuffer buffer = new StringBuffer();
final String separator = ", ";
getTags().forEach(tag -> buffer.append(tag).append(separator));
if (buffer.length() == 0) {
return "";
} else {
return buffer.substring(0, buffer.length() - separator.length());
}
}

}
77 changes: 77 additions & 0 deletions src/main/java/seedu/address/model/task/Task.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package seedu.address.model.task;

import seedu.address.commons.util.CollectionUtil;
import seedu.address.model.person.ReadOnlyPerson;
import seedu.address.model.tag.UniqueTagList;

import java.util.Objects;

/**
* Represents a Person in the address book.
* Guarantees: details are present and not null, field values are validated.
*/
public class Task implements ReadOnlyTask {

private Name name;
private DueDate dueDate;

private UniqueTagList tags;

/**
* Every field must be present and not null.
*/
public Task(Name name, DueDate dueDate, UniqueTagList tags) {
assert !CollectionUtil.isAnyNull(name, dueDate, tags);
this.name = name;
this.dueDate = dueDate;
this.tags = new UniqueTagList(tags); // protect internal tags from changes in the arg list
}

/**
* Copy constructor.
*/
public Task(ReadOnlyTask source) {
this(source.getName(), source.getDueDate() , source.getTags());
}

@Override
public Name getName() {
return name;
}

@Override
public DueDate getDueDate() {
return dueDate;
}

@Override
public UniqueTagList getTags() {
return new UniqueTagList(tags);
}

/**
* Replaces this person's tags with the tags in the argument tag list.
*/
public void setTags(UniqueTagList replacement) {
tags.setTags(replacement);
}

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

@Override
public int hashCode() {
// use this method for custom fields hashing instead of implementing your own
return Objects.hash(name, dueDate, tags);
}

@Override
public String toString() {
return getAsText();
}

}

0 comments on commit 9e1e9b6

Please sign in to comment.