/*
 * Copyright 2002-2019 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.springframework.core;

Ordered is an interface that can be implemented by objects that should be orderable, for example in a Collection.

The actual order can be interpreted as prioritization, with the first object (with the lowest order value) having the highest priority.

Note that there is also a priority marker for this interface: PriorityOrdered. Consult the Javadoc for PriorityOrdered for details on how PriorityOrdered objects are ordered relative to plain Ordered objects.

Consult the Javadoc for OrderComparator for details on the sort semantics for non-ordered objects.

Author:Juergen Hoeller, Sam Brannen
See Also:
Since:07.04.2003
/** * {@code Ordered} is an interface that can be implemented by objects that * should be <em>orderable</em>, for example in a {@code Collection}. * * <p>The actual {@link #getOrder() order} can be interpreted as prioritization, * with the first object (with the lowest order value) having the highest * priority. * * <p>Note that there is also a <em>priority</em> marker for this interface: * {@link PriorityOrdered}. Consult the Javadoc for {@code PriorityOrdered} for * details on how {@code PriorityOrdered} objects are ordered relative to * <em>plain</em> {@link Ordered} objects. * * <p>Consult the Javadoc for {@link OrderComparator} for details on the * sort semantics for non-ordered objects. * * @author Juergen Hoeller * @author Sam Brannen * @since 07.04.2003 * @see PriorityOrdered * @see OrderComparator * @see org.springframework.core.annotation.Order * @see org.springframework.core.annotation.AnnotationAwareOrderComparator */
public interface Ordered {
Useful constant for the highest precedence value.
See Also:
  • MIN_VALUE.MIN_VALUE
/** * Useful constant for the highest precedence value. * @see java.lang.Integer#MIN_VALUE */
int HIGHEST_PRECEDENCE = Integer.MIN_VALUE;
Useful constant for the lowest precedence value.
See Also:
  • MAX_VALUE.MAX_VALUE
/** * Useful constant for the lowest precedence value. * @see java.lang.Integer#MAX_VALUE */
int LOWEST_PRECEDENCE = Integer.MAX_VALUE;
Get the order value of this object.

Higher values are interpreted as lower priority. As a consequence, the object with the lowest value has the highest priority (somewhat analogous to Servlet load-on-startup values).

Same order values will result in arbitrary sort positions for the affected objects.

See Also:
Returns:the order value
/** * Get the order value of this object. * <p>Higher values are interpreted as lower priority. As a consequence, * the object with the lowest value has the highest priority (somewhat * analogous to Servlet {@code load-on-startup} values). * <p>Same order values will result in arbitrary sort positions for the * affected objects. * @return the order value * @see #HIGHEST_PRECEDENCE * @see #LOWEST_PRECEDENCE */
int getOrder(); }