Skip to content

Commit d9e7fd0

Browse files
committed
Improve the Priority constants
This addresses two issues: 1. They were redundantly named. Now e.g. Priority.LOW reads more nicely. 2. The FIRST and LAST constants were set to +Infinity and -Infinity, which meant it was mathematically to inject anything before or after, e.g. for testing or workaround purposes. The new FIRST and LAST constants are set to +1e300 and -1e300 respectively, so that it is still possible to bypass them in the rare cases where that is needed.
1 parent 324973a commit d9e7fd0

36 files changed

+118
-70
lines changed

src/main/java/org/scijava/AbstractUIDetails.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public abstract class AbstractUIDetails extends AbstractBasicDetails implements
5151
private String iconPath;
5252

5353
/** Sort priority of the object. */
54-
private double priority = Priority.NORMAL_PRIORITY;
54+
private double priority = Priority.NORMAL;
5555

5656
/** Whether the object can be selected in the user interface. */
5757
private boolean selectable;

src/main/java/org/scijava/Priority.java

Lines changed: 57 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,26 +46,45 @@ private Priority() {
4646
// prevent instantiation of utility class
4747
}
4848

49-
/** Priority for items that must be sorted first. */
50-
public static final double FIRST_PRIORITY = Double.POSITIVE_INFINITY;
49+
/**
50+
* Priority for items that must be sorted first.
51+
* <p>
52+
* Note that it <em>is</em> still possible to prioritize something earlier
53+
* than this value (e.g., for testing purposes), although doing so strongly
54+
* discouraged in production.
55+
* </p>
56+
*/
57+
public static final double FIRST = +1e300;
58+
59+
/** Priority for items that very strongly prefer to be sorted early. */
60+
public static final double EXTREMELY_HIGH = +1000000;
5161

5262
/** Priority for items that strongly prefer to be sorted early. */
53-
public static final double VERY_HIGH_PRIORITY = +10000;
63+
public static final double VERY_HIGH = +10000;
5464

5565
/** Priority for items that prefer to be sorted earlier. */
56-
public static final double HIGH_PRIORITY = +100;
66+
public static final double HIGH = +100;
5767

5868
/** Default priority for items. */
59-
public static final double NORMAL_PRIORITY = 0;
69+
public static final double NORMAL = 0;
6070

6171
/** Priority for items that prefer to be sorted later. */
62-
public static final double LOW_PRIORITY = -100;
72+
public static final double LOW = -100;
6373

6474
/** Priority for items that strongly prefer to be sorted late. */
65-
public static final double VERY_LOW_PRIORITY = -10000;
75+
public static final double VERY_LOW = -10000;
6676

67-
/** Priority for items that must be sorted last. */
68-
public static final double LAST_PRIORITY = Double.NEGATIVE_INFINITY;
77+
/** Priority for items that very strongly prefer to be sorted late. */
78+
public static final double EXTREMELY_LOW = -1000000;
79+
80+
/** Priority for items that must be sorted last.
81+
* <p>
82+
* Note that it <em>is</em> still possible to prioritize something later
83+
* than this value (e.g., for testing purposes), although doing so strongly
84+
* discouraged in production.
85+
* </p>
86+
*/
87+
public static final double LAST = -1e300;
6988

7089
/**
7190
* Compares two {@link Prioritized} objects.
@@ -109,4 +128,33 @@ public static boolean inject(final Object o, final double priority) {
109128
return true;
110129
}
111130

131+
// -- Deprecated --
132+
133+
/** @deprecated Use {@link #FIRST} instead. */
134+
@Deprecated
135+
public static final double FIRST_PRIORITY = Double.POSITIVE_INFINITY;
136+
137+
/** @deprecated Use {@link #VERY_HIGH} instead. */
138+
@Deprecated
139+
public static final double VERY_HIGH_PRIORITY = +10000;
140+
141+
/** @deprecated Use {@link #HIGH} instead. */
142+
@Deprecated
143+
public static final double HIGH_PRIORITY = +100;
144+
145+
/** @deprecated Use {@link #NORMAL} instead. */
146+
@Deprecated
147+
public static final double NORMAL_PRIORITY = 0;
148+
149+
/** @deprecated Use {@link #LOW} instead. */
150+
@Deprecated
151+
public static final double LOW_PRIORITY = -100;
152+
153+
/** @deprecated Use {@link #VERY_LOW} instead. */
154+
@Deprecated
155+
public static final double VERY_LOW_PRIORITY = -10000;
156+
157+
/** @deprecated Use {@link #LAST} instead. */
158+
@Deprecated
159+
public static final double LAST_PRIORITY = Double.NEGATIVE_INFINITY;
112160
}

src/main/java/org/scijava/app/SciJavaApp.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
* @see AppService
4343
*/
4444
@Plugin(type = App.class, name = SciJavaApp.NAME,
45-
priority = Priority.LOW_PRIORITY)
45+
priority = Priority.LOW)
4646
public class SciJavaApp extends AbstractApp {
4747

4848
public static final String NAME = "SciJava";

src/main/java/org/scijava/cache/DefaultCacheService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
/**
4444
* Trivial {@link CacheService} implementation. Wraps a {@link WeakHashMap}
4545
*/
46-
@Plugin(type = Service.class, priority = Priority.VERY_LOW_PRIORITY)
46+
@Plugin(type = Service.class, priority = Priority.VERY_LOW)
4747
public class DefaultCacheService extends AbstractService implements
4848
CacheService
4949
{

src/main/java/org/scijava/convert/ArrayConverters.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public class ArrayConverters {
5454

5555
// -- Integer array converters --
5656

57-
@Plugin(type = Converter.class, priority = Priority.HIGH_PRIORITY)
57+
@Plugin(type = Converter.class, priority = Priority.HIGH)
5858
public static class IntArrayWrapper extends
5959
PrimitiveArrayWrapper<int[], Integer, IntArray>
6060
{
@@ -70,7 +70,7 @@ public Class<int[]> getInputType() {
7070
}
7171
}
7272

73-
@Plugin(type = Converter.class, priority = Priority.HIGH_PRIORITY)
73+
@Plugin(type = Converter.class, priority = Priority.HIGH)
7474
public static class IntArrayUnwrapper extends
7575
PrimitiveArrayUnwrapper<int[], Integer, IntArray>
7676
{
@@ -88,7 +88,7 @@ public Class<IntArray> getInputType() {
8888

8989
// -- Byte array converters --
9090

91-
@Plugin(type = Converter.class, priority = Priority.HIGH_PRIORITY)
91+
@Plugin(type = Converter.class, priority = Priority.HIGH)
9292
public static class ByteArrayWrapper extends
9393
PrimitiveArrayWrapper<byte[], Byte, ByteArray>
9494
{
@@ -104,7 +104,7 @@ public Class<byte[]> getInputType() {
104104
}
105105
}
106106

107-
@Plugin(type = Converter.class, priority = Priority.HIGH_PRIORITY)
107+
@Plugin(type = Converter.class, priority = Priority.HIGH)
108108
public static class ByteArrayUnwrapper extends
109109
PrimitiveArrayUnwrapper<byte[], Byte, ByteArray>
110110
{
@@ -122,7 +122,7 @@ public Class<ByteArray> getInputType() {
122122

123123
// -- Bool array converters --
124124

125-
@Plugin(type = Converter.class, priority = Priority.HIGH_PRIORITY)
125+
@Plugin(type = Converter.class, priority = Priority.HIGH)
126126
public static class BoolArrayWrapper extends
127127
PrimitiveArrayWrapper<boolean[], Boolean, BoolArray>
128128
{
@@ -138,7 +138,7 @@ public Class<boolean[]> getInputType() {
138138
}
139139
}
140140

141-
@Plugin(type = Converter.class, priority = Priority.HIGH_PRIORITY)
141+
@Plugin(type = Converter.class, priority = Priority.HIGH)
142142
public static class BoolArrayUnwrapper extends
143143
PrimitiveArrayUnwrapper<boolean[], Boolean, BoolArray>
144144
{
@@ -156,7 +156,7 @@ public Class<BoolArray> getInputType() {
156156

157157
// -- Char array converters --
158158

159-
@Plugin(type = Converter.class, priority = Priority.HIGH_PRIORITY)
159+
@Plugin(type = Converter.class, priority = Priority.HIGH)
160160
public static class CharArrayWrapper extends
161161
PrimitiveArrayWrapper<char[], Character, CharArray>
162162
{
@@ -172,7 +172,7 @@ public Class<char[]> getInputType() {
172172
}
173173
}
174174

175-
@Plugin(type = Converter.class, priority = Priority.HIGH_PRIORITY)
175+
@Plugin(type = Converter.class, priority = Priority.HIGH)
176176
public static class CharArrayUnwrapper extends
177177
PrimitiveArrayUnwrapper<char[], Character, CharArray>
178178
{
@@ -190,7 +190,7 @@ public Class<CharArray> getInputType() {
190190

191191
// -- Short array converters --
192192

193-
@Plugin(type = Converter.class, priority = Priority.HIGH_PRIORITY)
193+
@Plugin(type = Converter.class, priority = Priority.HIGH)
194194
public static class ShortArrayWrapper extends
195195
PrimitiveArrayWrapper<short[], Short, ShortArray>
196196
{
@@ -206,7 +206,7 @@ public Class<short[]> getInputType() {
206206
}
207207
}
208208

209-
@Plugin(type = Converter.class, priority = Priority.HIGH_PRIORITY)
209+
@Plugin(type = Converter.class, priority = Priority.HIGH)
210210
public static class ShortArrayUnwrapper extends
211211
PrimitiveArrayUnwrapper<short[], Short, ShortArray>
212212
{
@@ -224,7 +224,7 @@ public Class<ShortArray> getInputType() {
224224

225225
// -- Float array converters --
226226

227-
@Plugin(type = Converter.class, priority = Priority.HIGH_PRIORITY)
227+
@Plugin(type = Converter.class, priority = Priority.HIGH)
228228
public static class FloatArrayWrapper extends
229229
PrimitiveArrayWrapper<float[], Float, FloatArray>
230230
{
@@ -240,7 +240,7 @@ public Class<float[]> getInputType() {
240240
}
241241
}
242242

243-
@Plugin(type = Converter.class, priority = Priority.HIGH_PRIORITY)
243+
@Plugin(type = Converter.class, priority = Priority.HIGH)
244244
public static class FloatArrayUnwrapper extends
245245
PrimitiveArrayUnwrapper<float[], Float, FloatArray>
246246
{
@@ -258,7 +258,7 @@ public Class<FloatArray> getInputType() {
258258

259259
// -- Double array converters --
260260

261-
@Plugin(type = Converter.class, priority = Priority.HIGH_PRIORITY)
261+
@Plugin(type = Converter.class, priority = Priority.HIGH)
262262
public static class DoubleArrayWrapper extends
263263
PrimitiveArrayWrapper<double[], Double, DoubleArray>
264264
{
@@ -274,7 +274,7 @@ public Class<double[]> getInputType() {
274274
}
275275
}
276276

277-
@Plugin(type = Converter.class, priority = Priority.HIGH_PRIORITY)
277+
@Plugin(type = Converter.class, priority = Priority.HIGH)
278278
public static class DoubleArrayUnwrapper extends
279279
PrimitiveArrayUnwrapper<double[], Double, DoubleArray>
280280
{
@@ -292,7 +292,7 @@ public Class<DoubleArray> getInputType() {
292292

293293
// -- Long array converters --
294294

295-
@Plugin(type = Converter.class, priority = Priority.HIGH_PRIORITY)
295+
@Plugin(type = Converter.class, priority = Priority.HIGH)
296296
public static class LongArrayWrapper extends
297297
PrimitiveArrayWrapper<long[], Long, LongArray>
298298
{
@@ -308,7 +308,7 @@ public Class<long[]> getInputType() {
308308
}
309309
}
310310

311-
@Plugin(type = Converter.class, priority = Priority.HIGH_PRIORITY)
311+
@Plugin(type = Converter.class, priority = Priority.HIGH)
312312
public static class LongArrayUnwrapper extends
313313
PrimitiveArrayUnwrapper<long[], Long, LongArray>
314314
{

src/main/java/org/scijava/convert/CastingConverter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
*
4343
* @author Mark Hiner
4444
*/
45-
@Plugin(type = Converter.class, priority = Priority.FIRST_PRIORITY)
45+
@Plugin(type = Converter.class, priority = Priority.FIRST)
4646
public class CastingConverter extends AbstractConverter<Object, Object> {
4747

4848
@SuppressWarnings("deprecation")

src/main/java/org/scijava/convert/NullConverter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
* basic casting when given a {@code null} source and returns {@code} null
4444
* directly when given a {@code} null destination.
4545
* <p>
46-
* By running at {@link Priority#FIRST_PRIORITY}, other converters should
46+
* By running at {@link Priority#FIRST}, other converters should
4747
* not need to worry about {@code null} source or destination parameters.
4848
* </p>
4949
* <p>
@@ -54,7 +54,7 @@
5454
*
5555
* @author Mark Hiner
5656
*/
57-
@Plugin(type = Converter.class, priority = Priority.FIRST_PRIORITY)
57+
@Plugin(type = Converter.class, priority = Priority.FIRST)
5858
public class NullConverter extends AbstractConverter<Object, Object> {
5959

6060
@Override

src/main/java/org/scijava/display/ActiveDisplayPreprocessor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
* @author Curtis Rueden
5555
*/
5656
@Plugin(type = PreprocessorPlugin.class,
57-
priority = Priority.VERY_HIGH_PRIORITY)
57+
priority = Priority.VERY_HIGH)
5858
public class ActiveDisplayPreprocessor extends AbstractPreprocessorPlugin {
5959

6060
@Parameter(required = false)

src/main/java/org/scijava/display/DefaultDisplay.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
// using Object#toString()), but until it exists, discovery of this display
4040
// merely causes the UIService to eventually issue some warnings anyway
4141
// ("No suitable viewer found for display" and "No viewer found for display").
42-
//@Plugin(type = Display.class, priority = Priority.VERY_LOW_PRIORITY)
42+
//@Plugin(type = Display.class, priority = Priority.VERY_LOW)
4343
/**
4444
* Default display for objects, when no other displays are available.
4545
*

src/main/java/org/scijava/display/DefaultTextDisplay.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
*
4141
* @author Curtis Rueden
4242
*/
43-
@Plugin(type = Display.class, priority = Priority.LOW_PRIORITY)
43+
@Plugin(type = Display.class, priority = Priority.LOW)
4444
public class DefaultTextDisplay extends AbstractDisplay<String> implements
4545
TextDisplay
4646
{

0 commit comments

Comments
 (0)