Class VersionNumberComparator

  • All Implemented Interfaces:
    Comparator<String>

    public class VersionNumberComparator
    extends Object
    implements Comparator<String>
    Provides a comparator for version numbers in the format a.b.c (e.g. 3.6.0). Up to four levels are supported (e.g. 4.0.0.1). If less than 4 levels are used, unused levels are assumed to be 0 (e.g. 1.5 is treated internally as 1.5.0.0)
    Since:
    4.0.0
    • Constructor Detail

      • VersionNumberComparator

        public VersionNumberComparator()
    • Method Detail

      • compare

        public int compare​(String value1,
                           String value2)
        Compares two version numbers in the format a.b.c (e.g. 3.6.0). Up to four levels are supported (e.g. 4.0.0.1). If less than 4 levels are used, unused levels are assumed to be 0 (e.g. 1.5 is treated internally as 1.5.0.0). Null version numbers are treated as being "less than" other version numbers. Note: If version numbers use non-numeric components on the significant levels (e.g. 3.6a), the comparator will fail. You have been warned.
        Specified by:
        compare in interface Comparator<String>
        Parameters:
        value1 - the first version number string
        value2 - the second version number string
        Returns:
        -1, 0 or 1 if the first version number is less than, equal to or greater than the second version number