forked from nus-cs2103-AY2223S1/ip
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from yilinzyl/branch-C-Sort
Add sort functionality
- Loading branch information
Showing
9 changed files
with
166 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package duke.command; | ||
|
||
import duke.exception.DukeException; | ||
import duke.Response; | ||
import duke.Storage; | ||
import duke.TaskList; | ||
|
||
import duke.task.Task; | ||
|
||
/** | ||
* Represents a command to sort dated tasks according to their dates. | ||
*/ | ||
public class SortCommand extends Command { | ||
|
||
/* Type of task to be shown - Event, Deadline or both */ | ||
private String taskType; | ||
|
||
/** | ||
* Initialises the SortCommand with the task type of tasks to be sorted. | ||
* @param taskType Type of tasks to be displayed. | ||
*/ | ||
public SortCommand(String taskType) { | ||
this.taskType = taskType; | ||
} | ||
|
||
/** | ||
* Initialises the SortCommand with all deadline and events to be sorted. | ||
*/ | ||
public SortCommand() { | ||
this.taskType = "dated"; | ||
} | ||
|
||
/** | ||
* Executes this command to sort all deadlines and events, or just deadlines or events. | ||
* @param tasks Task list that contains tasks to be sorted. | ||
* @param storage Storage used in application. | ||
* @return The response of the execution. | ||
*/ | ||
@Override | ||
public Response execute(TaskList tasks, Storage storage) { | ||
TaskList sortedTasks = tasks.sort(taskType); | ||
String message = sortedTasks.toString(); | ||
return new Response(message, false); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package duke.task; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
/** | ||
* Represents a task that is associated with a date. | ||
*/ | ||
abstract public class DatedTask extends Task { | ||
|
||
/** | ||
* Initialises a Task with its description. | ||
* | ||
* @param description Description of the Task. | ||
*/ | ||
public DatedTask(String description) { | ||
super(description); | ||
} | ||
|
||
/** | ||
* Checks if another DatedTask occurs later or earlier than self. | ||
* @param task Task to compare to. | ||
* @return returns 1 if self is later than task, -1 if task if it is earlier. | ||
*/ | ||
public abstract int compareTo(DatedTask task); | ||
|
||
/** | ||
* Gets the date the task occurs/is due. | ||
* @return LocalDateTime of date. | ||
*/ | ||
public abstract LocalDateTime getDate(); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters