Package rs.baselib.util
Class BeanComparator<T>
java.lang.Object
rs.baselib.util.BeanComparator<T>
- All Implemented Interfaces:
java.util.Comparator<T>
public class BeanComparator<T>
extends java.lang.Object
implements java.util.Comparator<T>
A comparator based on a list of bean properties.
The comparison will be null-safe and exception-safe.
- Author:
- ralph
-
Constructor Summary
Constructors Constructor Description BeanComparator(java.lang.String... beanProperties)Constructor.BeanComparator(java.util.Comparator<java.lang.Object> comparator, java.lang.String... beanProperties)Constructor.BeanComparator(java.util.Comparator<java.lang.Object> comparator, IValueProvider... valueProviders)Constructor.BeanComparator(IValueProvider... valueProviders)Constructor. -
Method Summary
Modifier and Type Method Description intcompare(T o1, T o2)java.util.Comparator<java.lang.Object>getComparator()Returns the comparator used to compare the values.IValueProvider[]getValueProviders()Returns the value providers of this comparator.
-
Constructor Details
-
BeanComparator
public BeanComparator(java.lang.String... beanProperties)Constructor.- Parameters:
beanProperties- the properties in order of priority.
-
BeanComparator
public BeanComparator(java.util.Comparator<java.lang.Object> comparator, java.lang.String... beanProperties)Constructor.- Parameters:
comparator- the comparator to be usedbeanProperties- the properties in order of priority.
-
BeanComparator
Constructor.- Parameters:
valueProviders- the value providers for each of the properties to be compared
-
BeanComparator
public BeanComparator(java.util.Comparator<java.lang.Object> comparator, IValueProvider... valueProviders)Constructor.- Parameters:
comparator- the comparator to be usedvalueProviders- the value providers for each of the properties to be compared
-
-
Method Details
-
getComparator
public java.util.Comparator<java.lang.Object> getComparator()Returns the comparator used to compare the values.- Returns:
- the comparator
-
getValueProviders
Returns the value providers of this comparator.- Returns:
- providers that will be used
-
compare
- Specified by:
comparein interfacejava.util.Comparator<T>
-