Skip to content

Commit

Permalink
Merge branch 'refactor'
Browse files Browse the repository at this point in the history
  • Loading branch information
fauzt committed Oct 10, 2019
2 parents 920eced + 50696ed commit 456995c
Show file tree
Hide file tree
Showing 15 changed files with 383 additions and 138 deletions.
4 changes: 3 additions & 1 deletion config/checkstyle/checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@
<property name="max" value="120"/>
<property name="ignorePattern" value="^package.*|^import.*|a href|href|http://|https://|ftp://"/>
</module>
<module name="AvoidStarImport"/>
<module name="AvoidStarImport">
<property name="excludes" value="task"/>
</module>
<module name="OneTopLevelClass"/>
<module name="NoLineWrap"/>
<module name="EmptyBlock">
Expand Down
55 changes: 34 additions & 21 deletions src/main/java/command/AddCommand.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
package command;

import exception.DukeException;
import task.Task;
import task.*;
import storage.Storage;
import task.Deadline;
import task.Event;
import task.TaskList;
import task.Todo;
import ui.Ui;

import java.time.LocalDateTime;

import static parser.DateTimeExtractor.NULL_DATE;

/**
* The AddCommand class is used when the user has input a command which requires
* a task to be added to the TaskList.
Expand All @@ -22,10 +20,9 @@ public class AddCommand extends Command {

private String command;
private String taskFeatures;
private final LocalDateTime nullDate = LocalDateTime.of(1, 1, 1, 1, 1, 1, 1);
private LocalDateTime formattedToDate = nullDate;
private LocalDateTime formattedAtDate = nullDate;
private LocalDateTime formattedFromDate = nullDate;
private LocalDateTime formattedStartDate = NULL_DATE;
private LocalDateTime formattedEndDate = NULL_DATE;
private int duration = 0;

/**
* This AddCommand function is used to assign the different parameters required
Expand All @@ -35,20 +32,30 @@ public class AddCommand extends Command {
* to process the user input.
* @param taskFeatures this string holds the description of the task provided by
* the user.
* @param atDate string contains the formatted user input that has the
* desired date time format.
* @param toDate string contains the formatted user input that has the
* @param startDate string contains the formatted user input that has the
* desired date time format.
* @param fromDate string contains the formatted user input that has the
* @param endDate string contains the formatted user input that has the
* desired date time format.
*/
public AddCommand(String command, String taskFeatures, LocalDateTime atDate, LocalDateTime toDate,
LocalDateTime fromDate) {
public AddCommand(String command, String taskFeatures, LocalDateTime startDate, LocalDateTime endDate) {
this.command = command;
this.taskFeatures = taskFeatures;
this.formattedFromDate = fromDate;
this.formattedAtDate = atDate;
this.formattedToDate = toDate;
this.formattedStartDate = startDate;
this.formattedEndDate = endDate;
}

/**
* Creates an AddCommand based on duration of the task.
* @param command holds command type determinant to decide how
* to process the user input.
* @param taskFeatures holds the description of the task provided by
* the user.
* @param duration holds the duration period of how long the task should last
*/
public AddCommand(String command, String taskFeatures, int duration) {
this.command = command;
this.taskFeatures = taskFeatures;
this.duration = duration;
}

/**
Expand All @@ -66,16 +73,22 @@ public void execute(TaskList tasks, Storage storage) throws DukeException {
Task task;
switch (command) {
case "todo":
task = new Todo(taskFeatures, formattedFromDate, formattedToDate);
if (!formattedStartDate.equals(NULL_DATE)) {
task = new TodoWithinPeriod(taskFeatures, formattedStartDate, formattedEndDate);
} else if (duration != 0) {
task = new TodoWithDuration(taskFeatures, duration);
} else {
task = new Todo(taskFeatures);
}
break;
case "deadline":
task = new Deadline(taskFeatures, formattedAtDate);
task = new Deadline(taskFeatures, formattedStartDate);
if (tasks.isClash(task)) {
throw new DukeException(DukeException.taskClash());
}
break;
case "event":
task = new Event(taskFeatures, formattedToDate, formattedFromDate);
task = new Event(taskFeatures, formattedStartDate, formattedEndDate);
if (tasks.isClash(task)) {
throw new DukeException(DukeException.taskClash());
}
Expand Down
28 changes: 28 additions & 0 deletions src/main/java/command/IgnoreCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package command;

import exception.DukeException;
import storage.Storage;
import task.Task;
import task.TaskList;
import ui.Ui;

public class IgnoreCommand extends Command {
private int indexOfTask;

public IgnoreCommand(int index) {
indexOfTask = index;
}

@Override
public void execute(TaskList tasks, Storage storage) throws DukeException {
if (indexOfTask < 0 || indexOfTask > (tasks.getSize() - 1)) {
throw new DukeException(DukeException.taskDoesNotExist());
}

Task task = tasks.markAsIgnorable(indexOfTask);
storage.saveFile(tasks.getTasks());

Ui.printMessage("Noted. This task has been marked as ignored:");
Ui.printMessage(" " + task.toString());
}
}
Loading

0 comments on commit 456995c

Please sign in to comment.