001/* 002 * Copyright 2002-2019 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.core; 018 019/** 020 * {@code Ordered} is an interface that can be implemented by objects that 021 * should be <em>orderable</em>, for example in a {@code Collection}. 022 * 023 * <p>The actual {@link #getOrder() order} can be interpreted as prioritization, 024 * with the first object (with the lowest order value) having the highest 025 * priority. 026 * 027 * <p>Note that there is also a <em>priority</em> marker for this interface: 028 * {@link PriorityOrdered}. Consult the Javadoc for {@code PriorityOrdered} for 029 * details on how {@code PriorityOrdered} objects are ordered relative to 030 * <em>plain</em> {@link Ordered} objects. 031 * 032 * <p>Consult the Javadoc for {@link OrderComparator} for details on the 033 * sort semantics for non-ordered objects. 034 * 035 * @author Juergen Hoeller 036 * @author Sam Brannen 037 * @since 07.04.2003 038 * @see PriorityOrdered 039 * @see OrderComparator 040 * @see org.springframework.core.annotation.Order 041 * @see org.springframework.core.annotation.AnnotationAwareOrderComparator 042 */ 043public interface Ordered { 044 045 /** 046 * Useful constant for the highest precedence value. 047 * @see java.lang.Integer#MIN_VALUE 048 */ 049 int HIGHEST_PRECEDENCE = Integer.MIN_VALUE; 050 051 /** 052 * Useful constant for the lowest precedence value. 053 * @see java.lang.Integer#MAX_VALUE 054 */ 055 int LOWEST_PRECEDENCE = Integer.MAX_VALUE; 056 057 058 /** 059 * Get the order value of this object. 060 * <p>Higher values are interpreted as lower priority. As a consequence, 061 * the object with the lowest value has the highest priority (somewhat 062 * analogous to Servlet {@code load-on-startup} values). 063 * <p>Same order values will result in arbitrary sort positions for the 064 * affected objects. 065 * @return the order value 066 * @see #HIGHEST_PRECEDENCE 067 * @see #LOWEST_PRECEDENCE 068 */ 069 int getOrder(); 070 071}