diff options
author | Steffen Pingel | 2012-02-11 13:41:58 +0000 |
---|---|---|
committer | Steffen Pingel | 2012-02-11 13:41:58 +0000 |
commit | fa6a5fb9967a08f54e5800a1b239c03bfb4850ba (patch) | |
tree | dcbc5b4518cc80209932a12944612dd29519d863 /org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks | |
parent | a7f0e7fc780376a7ec5b21dd4a8a15d2ca015090 (diff) | |
download | org.eclipse.mylyn.tasks-fa6a5fb9967a08f54e5800a1b239c03bfb4850ba.tar.gz org.eclipse.mylyn.tasks-fa6a5fb9967a08f54e5800a1b239c03bfb4850ba.tar.xz org.eclipse.mylyn.tasks-fa6a5fb9967a08f54e5800a1b239c03bfb4850ba.zip |
NEW - bug 371010: [api] provide abstracted priority mapping
https://bugs.eclipse.org/bugs/show_bug.cgi?id=371010
Change-Id: I858678eac8c4803811553e18e65775244f61c78c
Diffstat (limited to 'org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks')
-rw-r--r-- | org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/ITask.java | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/ITask.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/ITask.java index f3d77eacd..6cf012962 100644 --- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/ITask.java +++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/ITask.java @@ -13,6 +13,7 @@ package org.eclipse.mylyn.tasks.core; import java.util.Date; +import org.eclipse.core.runtime.Assert; import org.eclipse.mylyn.internal.tasks.core.Messages; /** @@ -72,11 +73,29 @@ public interface ITask extends IRepositoryElement, IAttributeContainer { } /** + * Defines an interface for priorities that have an associated integer value. + * + * @author Steffen Pingel + * @since 3.7 + * @see PriorityLevel#fromValue(IPriorityValue[], IPriorityValue) + */ + public static interface IPriorityValue { + + /** + * Returns the integer value of this priority. + */ + int getPriorityValue(); + + } + + /** * @since 3.0 */ public enum PriorityLevel { P1, P2, P3, P4, P5; + private static final int LEVEL_COUNT = PriorityLevel.values().length; + @Override public String toString() { switch (this) { @@ -185,6 +204,34 @@ public interface ITask extends IRepositoryElement, IAttributeContainer { } /** + * Maps a priority value to a {@link PriorityLevel}. The value needs to be present in <code>priorities</code>, + * otherwise {@link PriorityLevel#getDefault()} is returned. + * <p> + * NOTE: <code>priorities</code> needs to be sorted in ascending order. + * + * @param priorities + * a sorted array of priority levels + * @param value + * the value to map + * @since 3.7 + */ + public static PriorityLevel fromValue(IPriorityValue[] priorities, IPriorityValue value) { + Assert.isNotNull(priorities); + if (value != null) { + int minValue = priorities[0].getPriorityValue(); + int range = priorities[priorities.length - 1].getPriorityValue() - minValue; + for (IPriorityValue priority : priorities) { + if (value.equals(priority)) { + float relativeValue = (float) (priority.getPriorityValue() - minValue) / range; + int level = (int) (relativeValue * LEVEL_COUNT) + 1; + return PriorityLevel.fromLevel(level); + } + } + } + return PriorityLevel.getDefault(); + } + + /** * @since 3.0 */ public static PriorityLevel getDefault() { |