Created
April 25, 2016 16:20
-
-
Save lucasmelin/40441fa8d69a0bce7265eb2aba5e8448 to your computer and use it in GitHub Desktop.
Sorting using completion comparator
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
/** | |
* Sorts the task list using the TaskIsCompleteComparator comparator. | |
* <p> | |
* Checks to make sure that the array is not empty before attempting to compare elements. | |
*/ | |
private void sortByIsComplete(){ | |
if (tasks.isEmpty()==false){ | |
Collections.sort(tasks, new TaskIsCompleteComparator()); | |
System.out.println("Sorting by Is-Complete is complete"); | |
} | |
else{ | |
System.out.print("Nothing to sort, no tasks"); | |
} | |
} |
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
import java.util.Comparator; | |
public class TaskIsCompleteComparator implements Comparator<Task>{ | |
@Override | |
public int compare(Task t1, Task t2){ | |
return Boolean.compare(t1.getIsComplete(), t2.getIsComplete()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment