forked from se-edu/addressbook-level4
-
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 #53 from CS2103AUG2016-T16-C3/sort-by-priority
Let users sort tasks by priority
- Loading branch information
Showing
22 changed files
with
318 additions
and
34 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
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
22 changes: 22 additions & 0 deletions
22
src/main/java/seedu/manager/logic/commands/SortCommand.java
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,22 @@ | ||
package seedu.manager.logic.commands; | ||
|
||
public class SortCommand extends Command { | ||
|
||
public static final String COMMAND_WORD = "sort"; | ||
|
||
public static final String MESSAGE_USAGE = COMMAND_WORD | ||
+ ": Sorts the displayed tasks by priority, from highest to lowest. Tasks with no priority are shown last.\n" | ||
+ "Parameters: None\n" | ||
+ "Example: " + COMMAND_WORD; | ||
|
||
public static final String MESSAGE_SUCCESS = "Sorted Tasks"; | ||
|
||
public SortCommand() {} | ||
|
||
@Override | ||
public CommandResult execute() { | ||
model.sortSortedFilteredTaskListByPriority(); | ||
return new CommandResult(MESSAGE_SUCCESS); | ||
} | ||
|
||
} |
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
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
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,56 @@ | ||
package guitests; | ||
|
||
import static org.junit.Assert.assertTrue; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.Comparator; | ||
import java.util.List; | ||
|
||
import org.junit.Test; | ||
|
||
import guitests.guihandles.TaskCardHandle; | ||
import javafx.collections.ObservableList; | ||
import seedu.manager.logic.commands.SortCommand; | ||
import seedu.manager.model.task.ReadOnlyTask; | ||
import seedu.manager.model.task.Task.TaskProperties; | ||
import seedu.manager.testutil.TestTask; | ||
|
||
public class SortCommandTest extends TaskManagerGuiTest { | ||
|
||
@Test | ||
public void sort() { | ||
assertSortSuccess(true); | ||
|
||
TestTask taskToAdd = td.hotel; | ||
commandBox.runCommand(taskToAdd.getAddCommand()); | ||
|
||
assertSortSuccess(false); | ||
|
||
commandBox.runCommand("find CS2101"); | ||
assertSortSuccess(true); | ||
} | ||
|
||
private void assertSortSuccess(boolean runSortCommand) { | ||
if (runSortCommand) { | ||
commandBox.runCommand("sort"); | ||
} | ||
|
||
Comparator<? super ReadOnlyTask> priorityComparator = (t1, t2) -> t1.compareProperty(t2, TaskProperties.PRIORITY); | ||
|
||
assertTrue(isSorted(priorityComparator, taskListPanel.getListView().getItems())); | ||
|
||
if (runSortCommand) { | ||
assertResultMessage(SortCommand.MESSAGE_SUCCESS); | ||
} | ||
} | ||
|
||
private boolean isSorted(Comparator<? super ReadOnlyTask> comparator, ObservableList<ReadOnlyTask> listToCheck) { | ||
for (int i = 1; i < listToCheck.size(); i++) { | ||
if (comparator.compare(listToCheck.get(i - 1), listToCheck.get(i)) > 0) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
} |
Oops, something went wrong.