Class PropertyComparator<T>

  • Type Parameters:
    T - the type of objects that may be compared by this comparator
    All Implemented Interfaces:
    Comparator<T>

    public class PropertyComparator<T>
    extends Object
    implements 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:
    BeanWrapper
    • Field Detail

    • Constructor Detail

      • PropertyComparator

        public PropertyComparator​(String property,
                                  boolean ignoreCase,
                                  boolean ascending)
        Create a PropertyComparator for the given settings.
        Parameters:
        property - the property to compare
        ignoreCase - whether upper and lower case in String values should be ignored
        ascending - whether to sort ascending (true) or descending (false)
    • Method Detail

      • sort

        public static void sort​(List<?> source,
                                SortDefinition sortDefinition)
                         throws BeansException
        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 List
        sortDefinition - the parameters to sort by
        Throws:
        IllegalArgumentException - in case of a missing propertyName
        BeansException
      • sort

        public static void sort​(Object[] source,
                                SortDefinition sortDefinition)
                         throws BeansException
        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 source
        sortDefinition - the parameters to sort by
        Throws:
        IllegalArgumentException - in case of a missing propertyName
        BeansException