Class Version

  • All Implemented Interfaces:
    java.lang.Comparable<Version>

    public final class Version
    extends java.lang.Object
    implements java.lang.Comparable<Version>
    Represents a semantic version (SemVer).
    • Method Detail

      • of

        public static Version of​(long major,
                                 long minor)
        Obtains a Version instance of the specified major, minor and patch versions.
        Parameters:
        major - a major version number, non-negative
        minor - a minor version number, non-negative
        Returns:
        the version
      • of

        public static Version of​(long major,
                                 long minor,
                                 long patch)
        Obtains a Version instance of the specified major, minor and patch versions.
        Parameters:
        major - a major version number, non-negative
        minor - a minor version number, non-negative
        patch - a patch version number, non-negative
        Returns:
        the version
      • parse

        public static Version parse​(java.lang.String version)
        Parses a Version from the specified SemVer string.
        Parameters:
        version - the SemVer string to parse
        Returns:
        the version
      • tryParse

        public static java.util.Optional<Version> tryParse​(java.lang.String version)
        Parses a Version from the specified SemVer string.
        Parameters:
        version - the SemVer string to parse
        Returns:
        the version if it can be parsed; empty otherwise
      • majorVersion

        public long majorVersion()
        Returns the major version.
        Returns:
        the major version number
      • minorVersion

        public long minorVersion()
        Returns the minor version.
        Returns:
        the minor version number
      • patchVersion

        public long patchVersion()
        Returns the patch version.
        Returns:
        the patch version number
      • isHigherThan

        public boolean isHigherThan​(Version other)
        Determines if this Version has a higher precedence compared with the specified Version.
        Parameters:
        other - the Version to compare with, non-null
        Returns:
        true, if this Version is higher than the other Version; false otherwise
      • isHigherThanOrEquivalentTo

        public boolean isHigherThanOrEquivalentTo​(Version other)
        Determines if this Version has a higher or equal precedence compared with the specified Version.
        Parameters:
        other - the Version to compare with, non-null
        Returns:
        true, if this Version is higher than or equivalent to the other Version; false otherwise
      • isLowerThan

        public boolean isLowerThan​(Version other)
        Determines if this Version has a lower precedence compared with the specified Version.
        Parameters:
        other - the Version to compare with, non-null
        Returns:
        true, if this Version is lower than the other Version; false otherwise
      • isLowerThanOrEquivalentTo

        public boolean isLowerThanOrEquivalentTo​(Version other)
        Determines if this Version has a lower or equal precedence compared with the specified Version.
        Parameters:
        other - the Version to compare with, non-null
        Returns:
        true, if this Version is lower than or equivalent to the other Version; false otherwise
      • isEquivalentTo

        public boolean isEquivalentTo​(Version other)
        Determines if this Version has the same precedence as the specified Version.
        Parameters:
        other - the Version to compare with, non-null
        Returns:
        true, if this Version is equivalent to the other Version; false otherwise
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • compareTo

        public int compareTo​(Version o)
        Specified by:
        compareTo in interface java.lang.Comparable<Version>
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object