Skip to content

Commit 1ff3af6

Browse files
committed
Improve Javadoc for Ordered/@order regarding sort semantics
1 parent a07ba69 commit 1ff3af6

File tree

5 files changed

+77
-49
lines changed

5 files changed

+77
-49
lines changed

spring-core/src/main/java/org/springframework/core/OrderComparator.java

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -24,23 +24,31 @@
2424
import org.springframework.util.ObjectUtils;
2525

2626
/**
27-
* {@link Comparator} implementation for {@link Ordered} objects,
28-
* sorting by order value ascending (resp. by priority descending).
27+
* {@link Comparator} implementation for {@link Ordered} objects, sorting
28+
* by order value ascending, respectively by priority descending.
2929
*
30-
* <p>Non-{@code Ordered} objects are treated as greatest order
31-
* values, thus ending up at the end of the list, in arbitrary order
32-
* (just like same order values of {@code Ordered} objects).
30+
* <h3>Same Order Objects</h3>
31+
* <p>Objects that have the same order value will be sorted with arbitrary
32+
* ordering with respect to other objects with the same order value.
33+
*
34+
* <h3>Non-ordered Objects</h3>
35+
* <p>Any object that does not provide its own order value is implicitly
36+
* assigned a value of {@link Ordered#LOWEST_PRECEDENCE}, thus ending up
37+
* at the end of a sorted collection in arbitrary order with respect to
38+
* other objects with the same order value.
3339
*
3440
* @author Juergen Hoeller
41+
* @author Sam Brannen
3542
* @since 07.04.2003
3643
* @see Ordered
44+
* @see org.springframework.core.annotation.AnnotationAwareOrderComparator
3745
* @see java.util.Collections#sort(java.util.List, java.util.Comparator)
3846
* @see java.util.Arrays#sort(Object[], java.util.Comparator)
3947
*/
4048
public class OrderComparator implements Comparator<Object> {
4149

4250
/**
43-
* Shared default instance of OrderComparator.
51+
* Shared default instance of {@code OrderComparator}.
4452
*/
4553
public static final OrderComparator INSTANCE = new OrderComparator();
4654

spring-core/src/main/java/org/springframework/core/Ordered.java

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,21 +17,28 @@
1717
package org.springframework.core;
1818

1919
/**
20-
* Interface that can be implemented by objects that should be
21-
* orderable, for example in a Collection.
20+
* {@code Ordered} is an interface that can be implemented by objects that
21+
* should be <em>orderable</em>, for example in a {@code Collection}.
2222
*
23-
* <p>The actual order can be interpreted as prioritization, with
24-
* the first object (with the lowest order value) having the highest
23+
* <p>The actual {@link #getOrder() order} can be interpreted as prioritization,
24+
* with the first object (with the lowest order value) having the highest
2525
* priority.
2626
*
27-
* <p>Note that there is a 'priority' marker for this interface:
28-
* {@link PriorityOrdered}. Order values expressed by PriorityOrdered
29-
* objects always apply before order values of 'plain' Ordered values.
27+
* <p>Note that there is also a <em>priority</em> marker for this interface:
28+
* {@link PriorityOrdered}. Order values expressed by {@code PriorityOrdered}
29+
* objects always apply before same order values expressed by <em>plain</em>
30+
* {@link Ordered} objects.
31+
*
32+
* <p>Consult the Javadoc for {@link OrderComparator} for details on the
33+
* sort semantics for non-ordered objects.
3034
*
3135
* @author Juergen Hoeller
36+
* @author Sam Brannen
3237
* @since 07.04.2003
38+
* @see PriorityOrdered
3339
* @see OrderComparator
3440
* @see org.springframework.core.annotation.Order
41+
* @see org.springframework.core.annotation.AnnotationAwareOrderComparator
3542
*/
3643
public interface Ordered {
3744

@@ -49,15 +56,15 @@ public interface Ordered {
4956

5057

5158
/**
52-
* Return the order value of this object, with a
53-
* higher value meaning greater in terms of sorting.
54-
* <p>Normally starting with 0, with {@code Integer.MAX_VALUE}
55-
* indicating the greatest value. Same order values will result
56-
* in arbitrary positions for the affected objects.
57-
* <p>Higher values can be interpreted as lower priority. As a
58-
* consequence, the object with the lowest value has highest priority
59-
* (somewhat analogous to Servlet "load-on-startup" values).
59+
* Get the order value of this object.
60+
* <p>Higher values are interpreted as lower priority. As a consequence,
61+
* the object with the lowest value has the highest priority (somewhat
62+
* analogous to Servlet {@code load-on-startup} values).
63+
* <p>Same order values will result in arbitrary sort positions for the
64+
* affected objects.
6065
* @return the order value
66+
* @see #HIGHEST_PRECEDENCE
67+
* @see #LOWEST_PRECEDENCE
6168
*/
6269
int getOrder();
6370

spring-core/src/main/java/org/springframework/core/PriorityOrdered.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2009 the original author or authors.
2+
* Copyright 2002-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,19 +17,20 @@
1717
package org.springframework.core;
1818

1919
/**
20-
* Extension of the {@link Ordered} interface, expressing a 'priority'
21-
* ordering: Order values expressed by PriorityOrdered objects always
22-
* apply before order values of 'plain' Ordered values.
20+
* Extension of the {@link Ordered} interface, expressing a <em>priority</em>
21+
* ordering: order values expressed by {@code PriorityOrdered} objects
22+
* always apply before same order values expressed by <em>plain</em>
23+
* {@link Ordered} objects.
2324
*
24-
* <p>This is primarily a special-purpose interface, used for objects
25-
* where it is particularly important to determine 'prioritized'
26-
* objects first, without even obtaining the remaining objects.
27-
* A typical example: Prioritized post-processors in a Spring
25+
* <p>This is primarily a special-purpose interface, used for objects where
26+
* it is particularly important to recognize <em>prioritized</em> objects
27+
* first, without even obtaining the remaining objects. A typical example:
28+
* prioritized post-processors in a Spring
2829
* {@link org.springframework.context.ApplicationContext}.
2930
*
30-
* <p>Note: PriorityOrdered post-processor beans are initialized in
31+
* <p>Note: {@code PriorityOrdered} post-processor beans are initialized in
3132
* a special phase, ahead of other post-processor beans. This subtly
32-
* affects their autowiring behavior: They will only be autowired against
33+
* affects their autowiring behavior: they will only be autowired against
3334
* beans which do not require eager initialization for type matching.
3435
*
3536
* @author Juergen Hoeller

spring-core/src/main/java/org/springframework/core/annotation/AnnotationAwareOrderComparator.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,16 @@
2525
import org.springframework.core.OrderComparator;
2626

2727
/**
28-
* {@link java.util.Comparator} implementation that checks Spring's
28+
* {@code AnnotationAwareOrderComparator} is an extension of
29+
* {@link OrderComparator} that supports Spring's
2930
* {@link org.springframework.core.Ordered} interface as well as the
3031
* {@link Order @Order} and {@link javax.annotation.Priority @Priority}
3132
* annotations, with an order value provided by an {@code Ordered}
3233
* instance overriding a statically defined annotation value (if any).
3334
*
35+
* <p>Consult the Javadoc for {@link OrderComparator} for details on the
36+
* sort semantics for non-ordered objects.
37+
*
3438
* @author Juergen Hoeller
3539
* @author Oliver Gierke
3640
* @author Stephane Nicoll
@@ -42,15 +46,16 @@
4246
public class AnnotationAwareOrderComparator extends OrderComparator {
4347

4448
/**
45-
* Shared default instance of AnnotationAwareOrderComparator.
49+
* Shared default instance of {@code AnnotationAwareOrderComparator}.
4650
*/
4751
public static final AnnotationAwareOrderComparator INSTANCE = new AnnotationAwareOrderComparator();
4852

4953

5054
/**
51-
* This implementation checks for the {@link Order} annotation
52-
* on various kinds of elements, in addition to the
53-
* {@link org.springframework.core.Ordered} check in the superclass.
55+
* This implementation checks for {@link Order @Order} or
56+
* {@link javax.annotation.Priority @Priority} on various kinds of
57+
* elements, in addition to the {@link org.springframework.core.Ordered}
58+
* check in the superclass.
5459
*/
5560
protected Integer findOrder(Object obj) {
5661
// Check for regular Ordered interface
@@ -59,7 +64,7 @@ protected Integer findOrder(Object obj) {
5964
return order;
6065
}
6166

62-
// Check for @Order annotation on various kinds of elements
67+
// Check for @Order and @Priority on various kinds of elements
6368
if (obj instanceof Class) {
6469
return OrderUtils.getOrder((Class<?>) obj);
6570
}

spring-core/src/main/java/org/springframework/core/annotation/Order.java

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,24 @@
2525
import org.springframework.core.Ordered;
2626

2727
/**
28-
* Annotation that defines ordering. The value is optional, and represents order value
29-
* as defined in the {@link Ordered} interface. Lower values have higher priority.
30-
* The default value is {@code Ordered.LOWEST_PRECEDENCE}, indicating
28+
* {@code @Order} defines the sort order for an annotated component.
29+
*
30+
* <p>The {@link #value} is optional and represents an order value as defined
31+
* in the {@link Ordered} interface. Lower values have higher priority. The
32+
* default value is {@code Ordered.LOWEST_PRECEDENCE}, indicating
3133
* lowest priority (losing to any other specified order value).
3234
*
33-
* <p>Since Spring 4.1, the standard {@link javax.annotation.Priority} can be used as
34-
* a drop-in replacement of this annotation.
35+
* <p>Since Spring 4.1, the standard {@link javax.annotation.Priority}
36+
* annotation can be used as a drop-in replacement for this annotation.
37+
*
38+
* <p><b>NOTE</b>: Annotation-based ordering is supported for specific kinds
39+
* of components only &mdash; for example, for annotation-based AspectJ
40+
* aspects. Ordering strategies within the Spring container, on the other
41+
* hand, are typically based on the {@link Ordered} interface in order to
42+
* allow for programmatically configurable ordering of each <i>instance</i>.
3543
*
36-
* <p><b>NOTE:</b> Annotation-based ordering is supported for specific kinds of
37-
* components only, e.g. for annotation-based AspectJ aspects. Spring container
38-
* strategies, on the other hand, are typically based on the {@link Ordered}
39-
* interface in order to allow for configurable ordering of each <i>instance</i>.
44+
* <p>Consult the Javadoc for {@link org.springframework.core.OrderComparator
45+
* OrderComparator} for details on the sort semantics for non-ordered objects.
4046
*
4147
* @author Rod Johnson
4248
* @author Juergen Hoeller
@@ -52,7 +58,8 @@
5258
public @interface Order {
5359

5460
/**
55-
* The order value. Default is {@link Ordered#LOWEST_PRECEDENCE}.
61+
* The order value.
62+
* <p>Default is {@link Ordered#LOWEST_PRECEDENCE}.
5663
* @see Ordered#getOrder()
5764
*/
5865
int value() default Ordered.LOWEST_PRECEDENCE;

0 commit comments

Comments
 (0)