001: /*******************************************************************************
002: * Copyright (c) 2003, 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.ui.navigator;
011:
012: /**
013: * <p>
014: * Enumeration of the Priority values supported by the Common Navigator.
015: * </p>
016: *
017: * @since 3.2
018: */
019: public final class Priority {
020:
021: /**
022: * Indicates Highest priority as an int.
023: */
024: public static final int HIGHEST_PRIORITY_VALUE = 0;
025:
026: /**
027: * Indicates Higher priority as an int.
028: */
029: public static final int HIGHER_PRIORITY_VALUE = 1;
030:
031: /**
032: * Indicates High priority as an int.
033: */
034: public static final int HIGH_PRIORITY_VALUE = 2;
035:
036: /**
037: * Indicates Normal priority as an int.
038: */
039: public static final int NORMAL_PRIORITY_VALUE = 3;
040:
041: /**
042: * Indicates Low priority as an int.
043: */
044: public static final int LOW_PRIORITY_VALUE = 4;
045:
046: /**
047: * Indicates Lower priority as an int.
048: */
049: public static final int LOWER_PRIORITY_VALUE = 5;
050:
051: /**
052: * Indicates Lowest priority as an int.
053: */
054: public static final int LOWEST_PRIORITY_VALUE = 6;
055:
056: /**
057: * Indicates Highest priority as a String.
058: */
059: public static final String HIGHEST_PRIORITY_LITERAL = "highest"; //$NON-NLS-1$
060:
061: /**
062: * Indicates Higher priority as a String.
063: */
064: public static final String HIGHER_PRIORITY_LITERAL = "higher"; //$NON-NLS-1$
065:
066: /**
067: * Indicates High priority as a String.
068: */
069: public static final String HIGH_PRIORITY_LITERAL = "high"; //$NON-NLS-1$
070:
071: /**
072: * Indicates Normal priority as a String.
073: */
074: public static final String NORMAL_PRIORITY_LITERAL = "normal"; //$NON-NLS-1$
075:
076: /**
077: * Indicates Low priority as a String.
078: */
079: public static final String LOW_PRIORITY_LITERAL = "low"; //$NON-NLS-1$
080:
081: /**
082: * Indicates Lower priority as a String.
083: */
084: public static final String LOWER_PRIORITY_LITERAL = "lower"; //$NON-NLS-1$
085:
086: /**
087: * Indicates Lowest priority as a String.
088: */
089: public static final String LOWEST_PRIORITY_LITERAL = "lowest"; //$NON-NLS-1$
090:
091: /**
092: * Indicates Highest priority as a Priority enumeration.
093: */
094: public static final Priority HIGHEST = new Priority(
095: HIGHEST_PRIORITY_VALUE, HIGHEST_PRIORITY_LITERAL);
096:
097: /**
098: * Indicates Higher priority as a Priority enumeration.
099: */
100: public static final Priority HIGHER = new Priority(
101: HIGHER_PRIORITY_VALUE, HIGHER_PRIORITY_LITERAL);
102:
103: /**
104: * Indicates High priority as a Priority enumeration.
105: */
106: public static final Priority HIGH = new Priority(
107: HIGH_PRIORITY_VALUE, HIGH_PRIORITY_LITERAL);
108:
109: /**
110: * Indicates Normal priority as a Priority enumeration.
111: */
112: public static final Priority NORMAL = new Priority(
113: NORMAL_PRIORITY_VALUE, NORMAL_PRIORITY_LITERAL);
114:
115: /**
116: * Indicates Low priority as a Priority enumeration.
117: */
118: public static final Priority LOW = new Priority(LOW_PRIORITY_VALUE,
119: LOW_PRIORITY_LITERAL);
120:
121: /**
122: * Indicates Lower priority as a Priority enumeration.
123: */
124: public static final Priority LOWER = new Priority(
125: LOWER_PRIORITY_VALUE, LOWER_PRIORITY_LITERAL);
126:
127: /**
128: * Indicates Lowest priority as a Priority enumeration.
129: */
130: public static final Priority LOWEST = new Priority(
131: LOWEST_PRIORITY_VALUE, LOWEST_PRIORITY_LITERAL);
132:
133: /**
134: * The ordered array of possible enumeration values (0=> Highest,
135: * length-1=>Lowest)
136: */
137: public static final Priority[] ENUM_ARRAY = new Priority[] {
138: HIGHEST, HIGHER, HIGH, NORMAL, LOW, LOWER, LOWEST };
139:
140: /**
141: *
142: * Returns the correct instance of the Priority ENUM for aLiteral.
143: *
144: * <p>
145: * This method will return NORMAL if the supplied value of aLiteral is
146: * invalid.
147: * </p>
148: *
149: * @param aLiteral
150: * One of the defined *_LITERAL constants of this class
151: * @return The corresponding Priority Enum or NORMAL if aLiteral is invalid
152: */
153: public static Priority get(String aLiteral) {
154: for (int i = 0; i < ENUM_ARRAY.length; i++) {
155: if (ENUM_ARRAY[i].getLiteral().equals(aLiteral)) {
156: return ENUM_ARRAY[i];
157: }
158: }
159: return NORMAL;
160: }
161:
162: /**
163: *
164: * Returns the correct instance of the Priority ENUM for aValue.
165: *
166: * <p>
167: * This method will return NORMAL if the supplied value of aValue is
168: * invalid.
169: * </p>
170: *
171: * @param aValue
172: * One of the defined *_VALUE constants of this class
173: * @return The corresponding Priority Enum or NORMAL if aValue is invalid
174: */
175: public static Priority get(int aValue) {
176:
177: switch (aValue) {
178: case HIGHEST_PRIORITY_VALUE:
179: return HIGHEST;
180: case HIGHER_PRIORITY_VALUE:
181: return HIGHER;
182: case HIGH_PRIORITY_VALUE:
183: return HIGH;
184: case LOWER_PRIORITY_VALUE:
185: return LOWER;
186: case LOWEST_PRIORITY_VALUE:
187: return LOWEST;
188: case NORMAL_PRIORITY_VALUE:
189: default:
190: return NORMAL;
191: }
192: }
193:
194: private final int value;
195:
196: private final String literal;
197:
198: protected Priority(int aValue, String aLiteral) {
199: value = aValue;
200: literal = aLiteral;
201: }
202:
203: /**
204: *
205: * @return The literal string for this specific Priority.
206: */
207: public String getLiteral() {
208: return literal;
209: }
210:
211: /**
212: * 0 is the lowest priority; 7 is the highest.
213: *
214: * @return The integer value for this specific Priority.
215: */
216: public int getValue() {
217: return value;
218: }
219:
220: /* (non-Javadoc)
221: * @see java.lang.Object#toString()
222: */
223: public String toString() {
224: return "Priority [" + getLiteral() + "]"; //$NON-NLS-1$//$NON-NLS-2$
225: }
226: }
|