Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorspingel2010-07-28 21:25:33 -0400
committerspingel2010-07-28 21:25:33 -0400
commit055961cd9fbea5b8a0fd862d971d1c267d613129 (patch)
tree71940c35a68780061d0b4b7c2c3a6b1b771abfce
parent90bde6d3d073342c99f32b79fad67ce43e060ea5 (diff)
downloadorg.eclipse.mylyn.tasks-055961cd9fbea5b8a0fd862d971d1c267d613129.tar.gz
org.eclipse.mylyn.tasks-055961cd9fbea5b8a0fd862d971d1c267d613129.tar.xz
org.eclipse.mylyn.tasks-055961cd9fbea5b8a0fd862d971d1c267d613129.zip
NEW - bug 303509: [patch] TaskComparator.sortByRank(...) does not sort when one of the tasks has null in RANK
https://bugs.eclipse.org/bugs/show_bug.cgi?id=303509
-rw-r--r--org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskListSorterTest.java39
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/util/TaskComparator.java23
2 files changed, 50 insertions, 12 deletions
diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskListSorterTest.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskListSorterTest.java
index 4d1fdcb41..48a2e00d4 100644
--- a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskListSorterTest.java
+++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskListSorterTest.java
@@ -9,6 +9,7 @@
* Tasktop Technologies - initial API and implementation
* George Lindholm - improvements
* Frank Becker - improvements for bug 212967
+ * Julio Gesser - fixes for bug 303509
*******************************************************************************/
package org.eclipse.mylyn.tasks.tests;
@@ -48,6 +49,7 @@ import org.eclipse.ui.XMLMemento;
* @author Mik Kersten
* @author George Lindholm
* @author Frank Becker
+ * @author Julio Gesser
*/
public class TaskListSorterTest extends TestCase {
@@ -293,6 +295,43 @@ public class TaskListSorterTest extends TestCase {
assertEquals("5", tasks[5].getTaskKey());
}
+ public void testRankOrderSortingWithNullRank() {
+ MockTask[] tasks = new MockTask[6];
+ tasks[0] = new MockTask("local", "1", "a");
+ tasks[1] = new MockTask("local", "2", "b");
+ tasks[2] = new MockTask("local", "3", "c");
+ tasks[3] = new MockTask("local", "4", "d");
+ tasks[4] = new MockTask("local", "5", "e");
+ tasks[5] = new MockTask("local", "6", "f");
+
+ Date start = new Date();
+ tasks[5].setCreationDate(start);
+ tasks[4].setCreationDate(new Date(start.getTime() - 1));
+ tasks[3].setCreationDate(new Date(start.getTime() - 2));
+ tasks[2].setCreationDate(new Date(start.getTime() - 3));
+ tasks[1].setCreationDate(new Date(start.getTime() - 4));
+ tasks[0].setCreationDate(new Date(start.getTime() - 5));
+
+ tasks[0].setAttribute(TaskAttribute.RANK, "3");
+ tasks[1].setAttribute(TaskAttribute.RANK, null);
+ tasks[2].setAttribute(TaskAttribute.RANK, "2");
+ tasks[3].setAttribute(TaskAttribute.RANK, "1");
+ tasks[4].setAttribute(TaskAttribute.RANK, "");
+ tasks[5].setAttribute(TaskAttribute.RANK, null);
+
+ TaskListSorter sorter = new TaskListSorter();
+ sorter.getComparator().getSortCriterion(0).setKey(SortCriterion.SortKey.RANK);
+ sorter.getComparator().getSortCriterion(1).setKey(SortCriterion.SortKey.DATE_CREATED);
+ sorter.sort(new EmptyViewer(), tasks);
+
+ assertEquals("2", tasks[0].getTaskKey());
+ assertEquals("5", tasks[1].getTaskKey());
+ assertEquals("6", tasks[2].getTaskKey());
+ assertEquals("4", tasks[3].getTaskKey());
+ assertEquals("3", tasks[4].getTaskKey());
+ assertEquals("1", tasks[5].getTaskKey());
+ }
+
public void testModuleSummaryOrderSorting() {
MockTask[] tasks = new MockTask[5];
tasks[0] = new MockTask("local", "MYLN:4", "c");
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/util/TaskComparator.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/util/TaskComparator.java
index 6f8b810bc..8d980d1e2 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/util/TaskComparator.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/util/TaskComparator.java
@@ -8,6 +8,7 @@
* Contributors:
* Tasktop Technologies - initial API and implementation
* Frank Becker - improvements for bug 231336
+ * Julio Gesser - fixes for bug 303509
*******************************************************************************/
package org.eclipse.mylyn.internal.tasks.ui.util;
@@ -177,29 +178,27 @@ public class TaskComparator implements Comparator<ITask> {
}
private int sortByRank(ITask element1, ITask element2, int sortDirection) {
-
if (element1.getConnectorKind() != null && element2.getConnectorKind() != null
&& element1.getConnectorKind().equals(element2.getConnectorKind())) {
// only compare rank of elements from the same connector
-
if (element1.getRepositoryUrl() != null && element2.getRepositoryUrl() != null
&& element1.getRepositoryUrl().equals(element2.getRepositoryUrl())) {
-
// only compare the rank of elements in the same repository
String rankString1 = element1.getAttribute(TaskAttribute.RANK);
String rankString2 = element2.getAttribute(TaskAttribute.RANK);
- if (rankString1 != null && rankString2 != null && rankString1.length() > 0 && rankString2.length() > 0) {
- try {
- Double rank1 = Double.parseDouble(rankString1);
- Double rank2 = Double.parseDouble(rankString2);
- return sortDirection * rank1.compareTo(rank2);
- } catch (NumberFormatException e) {
- // ignore, means that there is no rank on one of the elements
- }
+
+ try {
+ // considers zero if the rank is null or empty
+ Double rank1 = rankString1 == null || rankString1.length() == 0 ? Double.valueOf(0)
+ : Double.valueOf(rankString1);
+ Double rank2 = rankString2 == null || rankString2.length() == 0 ? Double.valueOf(0)
+ : Double.valueOf(rankString2);
+ return sortDirection * rank1.compareTo(rank2);
+ } catch (NumberFormatException e) {
+ // ignore, means that there is an invalid rank on one of the elements
}
}
}
-
return 0;
}

Back to the top