Skip to content

Commit

Permalink
Merge pull request #182 from CS2103AUG2016-W09-C2/fix
Browse files Browse the repository at this point in the history
first round of refactoring
  • Loading branch information
Yichen-D committed Nov 6, 2016
2 parents 0891f99 + 1a66a1b commit 5ce9dfa
Show file tree
Hide file tree
Showing 35 changed files with 290 additions and 268 deletions.
4 changes: 2 additions & 2 deletions src/main/java/seedu/address/commons/core/GuiSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
*/
public class GuiSettings implements Serializable {

private static final double DEFAULT_HEIGHT = 1020;
private static final double DEFAULT_WIDTH = 1200;
private static final double DEFAULT_HEIGHT = 870;
private static final double DEFAULT_WIDTH = 1545;

private Double windowWidth;
private Double windowHeight;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public AddNonFloatingCommand(String name, Set<String> tags, TaskDate startDate,
recurringType,
recurringPeriod
);
if(!this.toAdd.getLastAppendedComponent().isValidTimeSlot()){
if(!this.toAdd.getLastAppendedComponent().isValidNonFloatingTime()){
indicateAttemptToExecuteIncorrectCommand();
throw new IllegalValueException(MESSAGE_ILLEGAL_TIME_SLOT);
}
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/seedu/address/logic/commands/BlockCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ public class BlockCommand extends Command {
public static final String MESSAGE_SUCCESS = "Timeslot blocked: %1$s";
public static final String MESSAGE_TIMESLOT_OCCUPIED = "This timeslot is already blocked or overlapped with existing tasks.";
public static final String MESSAGE_ILLEGAL_TIME_SLOT = "End time must be later than Start time.";
public static final String DUMMY_NAME = "BLOCKED SLOT";

private final Task toBlock;

Expand All @@ -45,9 +44,9 @@ public BlockCommand(Set<String> tags, TaskDate startDate, TaskDate endDate) thro
for (String tagName : tags) {
tagSet.add(new Tag(tagName));
}
this.toBlock = new Task(new Name(DUMMY_NAME), new UniqueTagList(tagSet), new TaskDate(startDate),
this.toBlock = new Task(new Name(Name.DUMMY_NAME), new UniqueTagList(tagSet), new TaskDate(startDate),
new TaskDate(endDate), RecurringType.NONE, Task.NO_RECURRING_PERIOD);
if (!this.toBlock.getLastAppendedComponent().isValidTimeSlot()) {
if (!this.toBlock.getLastAppendedComponent().isValidNonFloatingTime()) {
indicateAttemptToExecuteIncorrectCommand();
throw new IllegalValueException(MESSAGE_ILLEGAL_TIME_SLOT);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ public CommandResult execute() {
return new CommandResult(Messages.MESSAGE_INVALID_TASK_DISPLAYED_INDEX);
}

TaskOccurrence taskToDelete = lastShownList.get(targetIndex - 1);
TaskOccurrence taskToArchive = lastShownList.get(targetIndex - 1);

try {
model.archiveTask(taskToDelete);
model.archiveTask(taskToArchive);
} catch (TaskNotFoundException pnfe) {
assert false : "The target task cannot be missing";
}

return new CommandResult(String.format(MESSAGE_COMPLETE_TASK_SUCCESS, taskToDelete.getTaskReference()));
return new CommandResult(String.format(MESSAGE_COMPLETE_TASK_SUCCESS, taskToArchive));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public CommandResult execute() {
assert false : "The target task cannot be missing";
}

return new CommandResult(String.format(MESSAGE_DELETE_TASK_SUCCESS, taskToDelete.getTaskReference()));
return new CommandResult(String.format(MESSAGE_DELETE_TASK_SUCCESS, taskToDelete));
}

}
4 changes: 2 additions & 2 deletions src/main/java/seedu/address/logic/commands/EditCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ public CommandResult execute() {
}

TaskOccurrence taskToEdit = lastShownList.get(targetIndex - 1);
//Task targetTask = (Task) taskToEdit.getTaskReference();

try {
model.editTask(taskToEdit, taskName, tags, startDate, endDate, recurringType);
CommandResult result = new CommandResult(String.format(MESSAGE_EDIT_TASK_SUCCESS, taskToEdit.getTaskReference()));
CommandResult result = new CommandResult(String.format(MESSAGE_EDIT_TASK_SUCCESS, taskToEdit));
EventsCenter.getInstance().post(new JumpToListRequestEvent(targetIndex - 1));
return result;
} catch (TaskNotFoundException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public CommandResult execute() {
}

EventsCenter.getInstance().post(new JumpToListRequestEvent(targetIndex - 1));
return new CommandResult(String.format(MESSAGE_SELECT_TASK_SUCCESS, targetIndex));
return new CommandResult(String.format(MESSAGE_SELECT_TASK_SUCCESS, lastShownList.get(targetIndex-1)));

}

Expand Down
21 changes: 8 additions & 13 deletions src/main/java/seedu/address/logic/parser/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,8 @@ private Command prepareAddNonFloatingFromDateToDate(Matcher matcher) {
try {
List<Date> datesToAdd = DateParser.getInstance().getFromToDatesFromString(startInput);
return new AddNonFloatingCommand(matcher.group("name"), getTagsFromArgs(matcher.group("tagArguments")),
new TaskDate(datesToAdd.get(0)),
new TaskDate(datesToAdd.get(1)),
new TaskDate(datesToAdd.get(START_TIME_INDEX)),
new TaskDate(datesToAdd.get(END_TIME_INDEX)),
recurringType, repeatCount);
} catch (IllegalValueException ive) {
return new IncorrectCommand(ive.getMessage());
Expand All @@ -358,11 +358,10 @@ private Command prepareBlock(String args) {
try {

String startInput = matcher.group("startTime");
String endInput = matcher.group("endTime");

List<Date> datesToAdd = DateParser.getInstance().getFromToDatesFromString(startInput);
return new BlockCommand(getTagsFromArgs(matcher.group("tagArguments")),
new TaskDate(DateParser.getInstance().getDateFromString(startInput).getTime()),
new TaskDate(DateParser.getInstance().getDateFromString(endInput).getTime()));
new TaskDate(datesToAdd.get(START_TIME_INDEX)),
new TaskDate(datesToAdd.get(END_TIME_INDEX)));
} catch (IllegalValueException ive) {
return new IncorrectCommand(ive.getMessage());
}
Expand Down Expand Up @@ -754,14 +753,10 @@ private Command prepareView(String arguments) {
public static ArrayList<Date> extractDateInfo(Matcher m) throws IllegalValueException{
ArrayList<Date> resultSet = new ArrayList<Date>();
try {
String[] time = m.group("startTime").replace(" from ", "").split(" to ");
List<Date> datesToAdd = DateParser.getInstance().getFromToDatesFromString(m.group("startTime"));
resultSet.clear();
try {
resultSet.add(DateParser.getInstance().getDateFromString(time[START_TIME_INDEX]));
resultSet.add(DateParser.getInstance().getDateFromString(time[END_TIME_INDEX]));
} catch (IllegalValueException e) {
throw new IllegalValueException(MESSAGE_ILLEGAL_DATE_INPUT);
}
resultSet.add(datesToAdd.get(START_TIME_INDEX));
resultSet.add(datesToAdd.get(END_TIME_INDEX));
} catch (Exception ise) {
resultSet.clear();
try {
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/seedu/address/logic/util/RecurringTaskUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public static void correctRecurringTask(ReadOnlyTask task, int elapsedPeriod, Re
TaskDate startDate = task.getLastAppendedComponent().getStartDate();
TaskDate endDate = task.getLastAppendedComponent().getEndDate();

if (!task.getLastAppendedComponent().hasOnlyEndDate()) {
if (task.getLastAppendedComponent().isSlot()) {
calendar.setTime(startDate.getDate());
correctCalendarByElapsed(calendar, elapsedPeriod, recurringType);
correctedStartDate.setDateInLong(calendar.getTime().getTime());
Expand Down Expand Up @@ -270,7 +270,7 @@ private static int getElapsedPeriodByRecurringType(LocalDate localDateCurrently,
* @return null if there is no start date in target
*/
public static Calendar getStartCalendar(TaskOccurrence target) {
if (!target.getStartDate().isValid()) {
if (!target.getStartDate().isPresent()) {
return null;
}
Calendar startDate = new GregorianCalendar();
Expand All @@ -297,7 +297,7 @@ public static Calendar getEndCalendar(TaskOccurrence target) {
* @return null if there is no start date in target
*/
public static LocalDate getStartLocalDate(TaskOccurrence target) {
if (target.hasOnlyEndDate()) {
if (!target.isSlot()) {
return null;
}
return DateFormatterUtil.dateToLocalDate(target.getStartDate().getDate());
Expand Down
15 changes: 12 additions & 3 deletions src/main/java/seedu/address/model/task/ReadOnlyTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public interface ReadOnlyTask {
/**
* Updates the task's params, used for edit.
*/
void updateTask(Name name, UniqueTagList tags, TaskDate startDate, TaskDate endDate, RecurringType recurringType);
void updateTask(Name name, UniqueTagList tags, TaskDate startDate, TaskDate endDate, RecurringType recurringType, int index);

/**
* Returns true if both have the same state. (interfaces cannot override .equals)
Expand All @@ -41,7 +41,8 @@ default boolean isSameStateAs(ReadOnlyTask other) {
&& other.getName().equals(this.getName()) // state checks here onwards
&& ((other.getTaskType().equals(this.getTaskType())) || !other.getRecurringType().equals(RecurringType.NONE)));
}


//@@author A0147967J
/**
* Formats the task as text, showing all contact details.
*/
Expand All @@ -50,9 +51,16 @@ default String getAsText() {
builder.append(getName());
builder.append(" Tags: ");
getTags().forEach(builder::append);
builder.append("\nRecurring: " + getRecurringType());
if(getRecurringPeriod() >= 0){
builder.append(" repeat " + getTaskDateComponent().size() + " times");
} else if(getRecurringType()!=RecurringType.NONE) {
builder.append(" always");
}
return builder.toString();
}

//@@author

/**
* Returns a string representation of this Task's tags
*/
Expand All @@ -74,4 +82,5 @@ default String tagsString() {
TaskOccurrence getLastAppendedComponent();

int getRecurringPeriod();

}
8 changes: 4 additions & 4 deletions src/main/java/seedu/address/model/task/Task.java
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public void completeTaskWhenAllOccurrencesArchived() {
// @@author A0147995H
@Override
public void updateTask(Name name, UniqueTagList tags, TaskDate startDate, TaskDate endDate,
RecurringType recurringType) {
RecurringType recurringType, int index) {
if (name != null)
this.name = name;

Expand All @@ -183,12 +183,12 @@ public void updateTask(Name name, UniqueTagList tags, TaskDate startDate, TaskDa
}

if (endDate != null)
this.getLastAppendedComponent().update(startDate, endDate);
this.recurringDates.get(index).update(startDate, endDate);

if (recurringType != RecurringType.IGNORED)
this.recurringType = recurringType;

getLastAppendedComponent().setTaskReferrence(this);
this.recurringDates.get(index).setTaskReferrence(this);
}
// @@author

Expand Down Expand Up @@ -223,7 +223,7 @@ public int getRecurringPeriod() {
}

public int decrementRecurringPeriod() {
recurringPeriod -= 1;
recurringPeriod -= 1;
return recurringPeriod;
}
// @@author
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/model/task/TaskDate.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public boolean equals(Object other){
&& this.getDate().equals(((TaskDate) other).getDate()));
}

public boolean isValid() {
public boolean isPresent() {
return date != DATE_NOT_PRESENT;
}

Expand Down
51 changes: 40 additions & 11 deletions src/main/java/seedu/address/model/task/TaskOccurrence.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,37 +49,66 @@ public TaskDate getEndDate() {
return endDate;
}

//@@author A0147967J
/**
* Checks if TaskDateOccurrence is in a valid time slot
* Checks if TaskDateOccurrence is in a valid non-floating time.
*
* @return True if it is in a valid time slot
*/
public boolean isValidTimeSlot(){
if(startDate!=null && endDate!=null){
public boolean isValidNonFloatingTime(){
if(isSlot()){
return (endDate.getDate()).after(startDate.getDate());
}else{
return true;
}
return true;
}

/**
* Returns true if it is a blocked time slot
*/
public boolean isBlockedSlot(){
return taskReference.getName().fullName.equals(Name.DUMMY_NAME);
}

/**
* Returns true if it is a valid time slot
*/
public boolean isSlot(){
return startDate.getDateInLong() != TaskDate.DATE_NOT_PRESENT
&& endDate.getDateInLong() != TaskDate.DATE_NOT_PRESENT;
return startDate.isPresent() && endDate.isPresent();
}

/**
* Returns true if it has only end date.
* Returns true if it is a deadline
*/
public boolean hasOnlyEndDate() {
if (startDate.getDateInLong() != TaskDate.DATE_NOT_PRESENT){
public boolean isDeadline(){
return !startDate.isPresent() && endDate.isPresent();
}

/** Returns true if this slot overlaps with the given one. */
public boolean isOverlappedWith(TaskOccurrence given) {
if(!isSlot()){
return false;
}
return true;
return !(!given.getEndDate().getDate().after(startDate.getDate())
|| !given.getStartDate().getDate().before(endDate.getDate()));
}

@Override
public String toString(){
final StringBuilder builder = new StringBuilder();
builder.append(taskReference.getAsText());
if(isSlot()){
builder.append("\nFrom: "+startDate.getFormattedDate());
builder.append(" To: "+endDate.getFormattedDate());
}else if(isDeadline()){
builder.append("\nBy: "+endDate.getFormattedDate());
}else{

}
return builder.toString();
}
//@@author


public ReadOnlyTask getTaskReference() {
return taskReference;
}
Expand Down
Loading

0 comments on commit 5ce9dfa

Please sign in to comment.