diff options
author | Sam Davis | 2016-02-22 23:20:10 +0000 |
---|---|---|
committer | Gerrit Code Review @ Eclipse.org | 2016-02-23 22:26:01 +0000 |
commit | 30ce0120faab7592239bdffdd3eff70908d1c2e1 (patch) | |
tree | a6feb0aae108e91cc9b1f85e65f698a16bd5d654 | |
parent | f09f773bc622943bcc870d6b71beece7d1993d63 (diff) | |
download | org.eclipse.mylyn.tasks-30ce0120faab7592239bdffdd3eff70908d1c2e1.tar.gz org.eclipse.mylyn.tasks-30ce0120faab7592239bdffdd3eff70908d1c2e1.tar.xz org.eclipse.mylyn.tasks-30ce0120faab7592239bdffdd3eff70908d1c2e1.zip |
488263: support sorting by rank when rank is not a base 10 number
Change-Id: If72f072d219ae5c79fe4ae8c4dfef13e1a2b90ff
Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=488263
2 files changed, 61 insertions, 2 deletions
diff --git a/org.eclipse.mylyn.tasks.ui.tests/src/org/eclipse/mylyn/internal/tasks/ui/util/TaskComparatorTest.java b/org.eclipse.mylyn.tasks.ui.tests/src/org/eclipse/mylyn/internal/tasks/ui/util/TaskComparatorTest.java new file mode 100644 index 000000000..eaa65c5a0 --- /dev/null +++ b/org.eclipse.mylyn.tasks.ui.tests/src/org/eclipse/mylyn/internal/tasks/ui/util/TaskComparatorTest.java @@ -0,0 +1,59 @@ +/******************************************************************************* + * Copyright (c) 2016 Tasktop Technologies and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Tasktop Technologies - initial API and implementation + *******************************************************************************/ + +package org.eclipse.mylyn.internal.tasks.ui.util; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import org.eclipse.mylyn.internal.tasks.core.TaskTask; +import org.eclipse.mylyn.tasks.core.ITask; +import org.eclipse.mylyn.tasks.core.data.TaskAttribute; +import org.junit.Test; + +public class TaskComparatorTest { + + @Test + public void compareRank() { + assertCompare(taskWithRank("5"), taskWithRank("7")); + assertCompare(taskWithRank("5"), taskWithRank("17")); + assertCompare(taskWithRank("5"), taskWithRank("17.1")); + assertCompare(taskWithRank("5.3"), taskWithRank("17.1")); + assertCompare(taskWithRank("#$d"), taskWithRank("#$e")); + assertCompare(taskWithRank("gjp"), taskWithRank("gkp")); + assertCompare(taskWithRank("A"), taskWithRank("a")); + assertCompare(taskWithRank("dsfhgSd"), taskWithRank("dsfhgsd")); + assertCompare(taskWithRank("dsfhgS"), taskWithRank("dsfhgsd")); + assertCompare(taskWithRank("dsfhgs"), taskWithRank("dsfhgsd")); + + assertEquals(0, compare(taskWithRank("5"), taskWithRank("5"))); + assertEquals(0, compare(taskWithRank("17.1"), taskWithRank("17.1"))); + assertEquals(0, compare(taskWithRank("dsfhgs"), taskWithRank("dsfhgs"))); + assertEquals(0, compare(taskWithRank("ds#fHgs"), taskWithRank("ds#fHgs"))); + } + + private void assertCompare(ITask task1, ITask task2) { + assertTrue(compare(task1, task2) < 0); + assertTrue(compare(task2, task1) > 0); + } + + private int compare(ITask task1, ITask task2) { + return new TaskComparator().compare(task1, task2); + } + + private ITask taskWithRank(String rank) { + @SuppressWarnings("restriction") + ITask task = new TaskTask("kind", "http://mock", "1"); + task.setPriority(""); + task.setAttribute(TaskAttribute.RANK, rank); + return task; + } +} 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 0ee528aa7..371e47eac 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 @@ -43,7 +43,7 @@ public class TaskComparator implements Comparator<ITask> { /** * Return a array of values to pass to taskKeyComparator.compare() for sorting - * + * * @param element * the element to sort * @return String array[component, taskId, summary] @@ -199,7 +199,7 @@ public class TaskComparator implements Comparator<ITask> { : Double.valueOf(rankString2); return compare(rank1, rank2, sortDirection); } catch (NumberFormatException e) { - // ignore, means that there is no rank on one of the elements + return compare(rankString1, rankString2, sortDirection); } } } |