Class PropertyComparator<T>
java.lang.Object
org.springframework.beans.support.PropertyComparator<T>
- Type Parameters:
T
- the type of objects that may be compared by this comparator
- All Implemented Interfaces:
Comparator<T>
PropertyComparator performs a comparison of two beans,
evaluating the specified bean property via a BeanWrapper.
- Since:
- 19.05.2003
- Author:
- Juergen Hoeller, Jean-Pierre Pawlak
- See Also:
-
Field Summary
-
Constructor Summary
ConstructorDescriptionPropertyComparator
(String property, boolean ignoreCase, boolean ascending) Create a PropertyComparator for the given settings.PropertyComparator
(SortDefinition sortDefinition) Create a new PropertyComparator for the given SortDefinition. -
Method Summary
Modifier and TypeMethodDescriptionint
final SortDefinition
Return the SortDefinition that this comparator uses.static void
sort
(Object[] source, SortDefinition sortDefinition) Sort the given source according to the given sort definition.static void
sort
(List<?> source, SortDefinition sortDefinition) Sort the given List according to the given sort definition.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, reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
-
Field Details
-
logger
-
-
Constructor Details
-
PropertyComparator
Create a new PropertyComparator for the given SortDefinition.- See Also:
-
PropertyComparator
Create a PropertyComparator for the given settings.- Parameters:
property
- the property to compareignoreCase
- whether upper and lower case in String values should be ignoredascending
- whether to sort ascending (true) or descending (false)
-
-
Method Details
-
getSortDefinition
Return the SortDefinition that this comparator uses. -
compare
- Specified by:
compare
in interfaceComparator<T>
-
sort
Sort the given List according to the given sort definition.Note: Contained objects have to provide the given property in the form of a bean property, i.e. a getXXX method.
- Parameters:
source
- the input ListsortDefinition
- the parameters to sort by- Throws:
IllegalArgumentException
- in case of a missing propertyNameBeansException
-
sort
Sort the given source according to the given sort definition.Note: Contained objects have to provide the given property in the form of a bean property, i.e. a getXXX method.
- Parameters:
source
- input sourcesortDefinition
- the parameters to sort by- Throws:
IllegalArgumentException
- in case of a missing propertyNameBeansException
-