KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > navigator > Priority


1 /*******************************************************************************
2  * Copyright (c) 2003, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.ui.navigator;
12
13 /**
14  * <p>
15  * Enumeration of the Priority values supported by the Common Navigator.
16  * </p>
17  *
18  * @since 3.2
19  */

20 public final class Priority {
21
22     /**
23      * Indicates Highest priority as an int.
24      */

25     public static final int HIGHEST_PRIORITY_VALUE = 0;
26
27     /**
28      * Indicates Higher priority as an int.
29      */

30     public static final int HIGHER_PRIORITY_VALUE = 1;
31
32     /**
33      * Indicates High priority as an int.
34      */

35     public static final int HIGH_PRIORITY_VALUE = 2;
36
37     /**
38      * Indicates Normal priority as an int.
39      */

40     public static final int NORMAL_PRIORITY_VALUE = 3;
41
42     /**
43      * Indicates Low priority as an int.
44      */

45     public static final int LOW_PRIORITY_VALUE = 4;
46
47     /**
48      * Indicates Lower priority as an int.
49      */

50     public static final int LOWER_PRIORITY_VALUE = 5;
51
52     /**
53      * Indicates Lowest priority as an int.
54      */

55     public static final int LOWEST_PRIORITY_VALUE = 6;
56
57     /**
58      * Indicates Highest priority as a String.
59      */

60     public static final String JavaDoc HIGHEST_PRIORITY_LITERAL = "highest"; //$NON-NLS-1$
61

62     /**
63      * Indicates Higher priority as a String.
64      */

65     public static final String JavaDoc HIGHER_PRIORITY_LITERAL = "higher"; //$NON-NLS-1$
66

67     /**
68      * Indicates High priority as a String.
69      */

70     public static final String JavaDoc HIGH_PRIORITY_LITERAL = "high"; //$NON-NLS-1$
71

72     /**
73      * Indicates Normal priority as a String.
74      */

75     public static final String JavaDoc NORMAL_PRIORITY_LITERAL = "normal"; //$NON-NLS-1$
76

77     /**
78      * Indicates Low priority as a String.
79      */

80     public static final String JavaDoc LOW_PRIORITY_LITERAL = "low"; //$NON-NLS-1$
81

82     /**
83      * Indicates Lower priority as a String.
84      */

85     public static final String JavaDoc LOWER_PRIORITY_LITERAL = "lower"; //$NON-NLS-1$
86

87     /**
88      * Indicates Lowest priority as a String.
89      */

90     public static final String JavaDoc LOWEST_PRIORITY_LITERAL = "lowest"; //$NON-NLS-1$
91

92     /**
93      * Indicates Highest priority as a Priority enumeration.
94      */

95     public static final Priority HIGHEST = new Priority(HIGHEST_PRIORITY_VALUE,
96             HIGHEST_PRIORITY_LITERAL);
97
98     /**
99      * Indicates Higher priority as a Priority enumeration.
100      */

101     public static final Priority HIGHER = new Priority(HIGHER_PRIORITY_VALUE,
102             HIGHER_PRIORITY_LITERAL);
103
104     /**
105      * Indicates High priority as a Priority enumeration.
106      */

107     public static final Priority HIGH = new Priority(HIGH_PRIORITY_VALUE,
108             HIGH_PRIORITY_LITERAL);
109
110     /**
111      * Indicates Normal priority as a Priority enumeration.
112      */

113     public static final Priority NORMAL = new Priority(NORMAL_PRIORITY_VALUE,
114             NORMAL_PRIORITY_LITERAL);
115
116     /**
117      * Indicates Low priority as a Priority enumeration.
118      */

119     public static final Priority LOW = new Priority(LOW_PRIORITY_VALUE,
120             LOW_PRIORITY_LITERAL);
121
122     /**
123      * Indicates Lower priority as a Priority enumeration.
124      */

125     public static final Priority LOWER = new Priority(LOWER_PRIORITY_VALUE,
126             LOWER_PRIORITY_LITERAL);
127
128     /**
129      * Indicates Lowest priority as a Priority enumeration.
130      */

131     public static final Priority LOWEST = new Priority(LOWEST_PRIORITY_VALUE,
132             LOWEST_PRIORITY_LITERAL);
133
134     /**
135      * The ordered array of possible enumeration values (0=> Highest,
136      * length-1=>Lowest)
137      */

138     public static final Priority[] ENUM_ARRAY = new Priority[] { HIGHEST,
139             HIGHER, HIGH, NORMAL, LOW, LOWER, LOWEST };
140
141     /**
142      *
143      * Returns the correct instance of the Priority ENUM for aLiteral.
144      *
145      * <p>
146      * This method will return NORMAL if the supplied value of aLiteral is
147      * invalid.
148      * </p>
149      *
150      * @param aLiteral
151      * One of the defined *_LITERAL constants of this class
152      * @return The corresponding Priority Enum or NORMAL if aLiteral is invalid
153      */

154     public static Priority get(String JavaDoc aLiteral) {
155         for (int i = 0; i < ENUM_ARRAY.length; i++) {
156             if (ENUM_ARRAY[i].getLiteral().equals(aLiteral)) {
157                 return ENUM_ARRAY[i];
158             }
159         }
160         return NORMAL;
161     }
162
163     /**
164      *
165      * Returns the correct instance of the Priority ENUM for aValue.
166      *
167      * <p>
168      * This method will return NORMAL if the supplied value of aValue is
169      * invalid.
170      * </p>
171      *
172      * @param aValue
173      * One of the defined *_VALUE constants of this class
174      * @return The corresponding Priority Enum or NORMAL if aValue is invalid
175      */

176     public static Priority get(int aValue) {
177
178         switch (aValue) {
179         case HIGHEST_PRIORITY_VALUE:
180             return HIGHEST;
181         case HIGHER_PRIORITY_VALUE:
182             return HIGHER;
183         case HIGH_PRIORITY_VALUE:
184             return HIGH;
185         case LOWER_PRIORITY_VALUE:
186             return LOWER;
187         case LOWEST_PRIORITY_VALUE:
188             return LOWEST;
189         case NORMAL_PRIORITY_VALUE:
190         default:
191             return NORMAL;
192         }
193     }
194
195     private final int value;
196
197     private final String JavaDoc literal;
198
199     protected Priority(int aValue, String JavaDoc aLiteral) {
200         value = aValue;
201         literal = aLiteral;
202     }
203
204     /**
205      *
206      * @return The literal string for this specific Priority.
207      */

208     public String JavaDoc getLiteral() {
209         return literal;
210     }
211
212     /**
213      * 0 is the lowest priority; 7 is the highest.
214      *
215      * @return The integer value for this specific Priority.
216      */

217     public int getValue() {
218         return value;
219     }
220     
221     /* (non-Javadoc)
222      * @see java.lang.Object#toString()
223      */

224     public String JavaDoc toString() {
225         return "Priority ["+getLiteral()+"]"; //$NON-NLS-1$//$NON-NLS-2$
226
}
227 }
228
Popular Tags