Class VersionUtils

  • All Implemented Interfaces:
    Utils

    public abstract class VersionUtils
    extends java.lang.Object
    implements Utils
    The utility class for version
    Since:
    1.0.0
    Author:
    Mercy
    See Also:
    Version
    • Field Detail

      • LATEST_JAVA_VERSION

        public static final javax.lang.model.SourceVersion LATEST_JAVA_VERSION
        The latest Java Release Version
      • CURRENT_JAVA_VERSION

        public static final Version CURRENT_JAVA_VERSION
        The Version instance for current Java Version
      • JAVA_VERSION_8

        public static final Version JAVA_VERSION_8
        The Version instance for Java 8
      • JAVA_VERSION_9

        public static final Version JAVA_VERSION_9
        The Version instance for Java 9
      • JAVA_VERSION_10

        public static final Version JAVA_VERSION_10
        The Version instance for Java 10
      • JAVA_VERSION_11

        public static final Version JAVA_VERSION_11
        The Version instance for Java 11
      • JAVA_VERSION_12

        public static final Version JAVA_VERSION_12
        The Version instance for Java 12
      • JAVA_VERSION_13

        public static final Version JAVA_VERSION_13
        The Version instance for Java 13
      • JAVA_VERSION_14

        public static final Version JAVA_VERSION_14
        The Version instance for Java 14
      • JAVA_VERSION_15

        public static final Version JAVA_VERSION_15
        The Version instance for Java 15
      • JAVA_VERSION_16

        public static final Version JAVA_VERSION_16
        The Version instance for Java 16
      • JAVA_VERSION_17

        public static final Version JAVA_VERSION_17
        The Version instance for Java 17
      • JAVA_VERSION_18

        public static final Version JAVA_VERSION_18
        The Version instance for Java 18
      • JAVA_VERSION_19

        public static final Version JAVA_VERSION_19
        The Version instance for Java 19
      • JAVA_VERSION_20

        public static final Version JAVA_VERSION_20
        The Version instance for Java 20
      • JAVA_VERSION_21

        public static final Version JAVA_VERSION_21
        The Version instance for Java 21
      • JAVA_VERSION_22

        public static final Version JAVA_VERSION_22
        The Version instance for Java 22
      • JAVA_VERSION_23

        public static final Version JAVA_VERSION_23
        The Version instance for Java 23
      • JAVA_VERSION_24

        public static final Version JAVA_VERSION_24
        The Version instance for Java 24
    • Method Detail

      • testCurrentJavaVersion

        public static boolean testCurrentJavaVersion​(java.lang.String operatorSymbol,
                                                     Version comparedVersion)
        Determines whether the current Java version matches the specified version based on the given operator symbol.

        Supported Operators

        • = - Equal to
        • > - Greater than
        • >= - Greater than or equal to
        • < - Less than
        • <= - Less than or equal to

        Example Usage

        
         VersionUtils.testCurrentJavaVersion("=", VersionUtils.JAVA_VERSION_8);  // true if current Java version is 8
         VersionUtils.testCurrentJavaVersion(">", VersionUtils.JAVA_VERSION_8);   // true if current Java version is higher than 8
         VersionUtils.testCurrentJavaVersion("<", VersionUtils.JAVA_VERSION_11);  // true if current Java version is lower than 11
         
        Parameters:
        operatorSymbol - the symbol of the comparison operator; must not be null
        comparedVersion - the version to compare against; must not be null
        Returns:
        true if the result of applying the operator to the current Java version and the compared version is true; otherwise, false
        Throws:
        java.lang.IllegalArgumentException - if any argument is null or the operator symbol is not supported
      • testVersion

        public static boolean testVersion​(java.lang.String baseVersion,
                                          java.lang.String operatorSymbol,
                                          java.lang.String comparedVersion)
        Determines whether the specified base version matches the compared version based on the given operator symbol.

        Supported Operators

        • = - Equal to
        • > - Greater than
        • >= - Greater than or equal to
        • < - Less than
        • <= - Less than or equal to

        Example Usage

        
         VersionUtils.testVersion("1.8", "=", "1.8.0") == true
         VersionUtils.testVersion("1.8", ">=", "1.7") == true
         VersionUtils.testVersion("1.8", "<=", "1.7") == false
         VersionUtils.testVersion("1.8", "<", "1.7") == false
         VersionUtils.testVersion("1.8", ">", "1.7") == true
         
        Parameters:
        baseVersion - the version to be tested; must not be null
        operatorSymbol - the symbol of the comparison operator; must not be null
        comparedVersion - the version to compare against; must not be null
        Returns:
        true if the result of applying the operator to the base and compared versions is true; otherwise, false
        Throws:
        java.lang.IllegalArgumentException - if any argument is null or the operator symbol is not supported
      • testVersion

        public static boolean testVersion​(Version baseVersion,
                                          Version.Operator versionOperator,
                                          Version comparedVersion)
        Determines whether the specified base version matches the compared version based on the given operator.

        Supported Operators

        • = - Equal to
        • > - Greater than
        • >= - Greater than or equal to
        • < - Less than
        • <= - Less than or equal to

        Example Usage

        
         Version v1 = Version.of("1.8.0");
         Version v2 = Version.of("1.7.0");
        
         Version.Operator eq = Version.Operator.of("=");  // Equals
         Version.Operator gt = Version.Operator.of(">");  // Greater than
         Version.Operator lt = Version.Operator.of("<");  // Less than
        
         testVersion(v1, eq, v1); // true
         testVersion(v1, gt, v2); // true
         testVersion(v2, lt, v1); // true
         
        Parameters:
        baseVersion - the version to be tested; must not be null
        versionOperator - the comparison operator; must not be null
        comparedVersion - the version to compare against; must not be null
        Returns:
        true if the result of applying the operator to the base and compared versions is true; otherwise, false
        Throws:
        java.lang.IllegalArgumentException - if any argument is null