The Spring Framework

org.springframework.core
Class OrderComparator

java.lang.Object
  extended by org.springframework.core.OrderComparator
All Implemented Interfaces:
Comparator
Direct Known Subclasses:
AnnotationAwareOrderComparator

public class OrderComparator
extends Object
implements Comparator

Comparator implementation for Ordered objects, sorting by order value ascending (resp. by priority descending).

Non-Ordered objects are treated as greatest order values, thus ending up at the end of the list, in arbitrary order (just like same order values of Ordered objects).

Since:
07.04.2003
Author:
Juergen Hoeller
See Also:
Ordered, Collections.sort(java.util.List, java.util.Comparator), Arrays.sort(Object[], java.util.Comparator)

Constructor Summary
OrderComparator()
           
 
Method Summary
 int compare(Object o1, Object o2)
           
protected  int getOrder(Object obj)
          Determine the order value for the given object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.Comparator
equals
 

Constructor Detail

OrderComparator

public OrderComparator()
Method Detail

compare

public int compare(Object o1,
                   Object o2)
Specified by:
compare in interface Comparator

getOrder

protected int getOrder(Object obj)
Determine the order value for the given object.

The default implementation checks against the Ordered interface. Can be overridden in subclasses.

Parameters:
obj - the object to check
Returns:
the order value, or Ordered.LOWEST_PRECEDENCE as fallback

The Spring Framework

Copyright © 2002-2007 The Spring Framework.