Class ComparatorHelper


  • public class ComparatorHelper
    extends Object
    ComparatorHelper is a utility class that provides a factory method used to create a java.util.Comparator instance from a string expression.

    The string expression should be in the form of comma-separated values, where each value represents the name of property whose value is used as input to the Comparator#compare(Object, Object) method and an optional order string ("asc" or "desc"). If not specified, ascending order will be assumed.

    For example, the string name:asc,dateOfBirth:desc will create the following comparator chain:

    new ChainedComparator(new Comparator[]
        {
        new ExtractorComparator(new ReflectionExtractor("getName")),
        new InverseComparator(new ExtractorComparator(new ReflectionExtractor("getDateOfBirth")))
        });

    Author:
    ic 2011.06.30
    • Constructor Detail

      • ComparatorHelper

        public ComparatorHelper()
    • Method Detail

      • createComparator

        public static Comparator createComparator​(String sExpr)
        Create a new Comparator from the specified string.
        Parameters:
        sExpr - a string expression representing a Comparator. Contains a list of property name/ordering pairs, separated by a colon. For example:
        • name:asc,dateOfBirth:desc
        • address.state,address.zip:desc
        Returns:
        Comparator representing specified string expression