XPInstall API Reference:InstallVersion Object:Methods:compareTo
From MDC
Contents |
[edit] compareTo
Compares the version information specified in this object to the version information specified in the version parameter.
[edit] Method of
InstallVersion object
[edit] Syntax
compareTo ( InstallVersion version); compareTo ( String version); compareTo ( int major, int minor, int release, int build);
[edit] Parameters
The compareTo method has the following parameters:
maj- The major version number.
min- Minor version number.
rev- Revision number.
bld- Build number.
version- An InstallVersion object or a String representing version information in the format "4.1.2.1234".
[edit] Returns
If the versions are the same, this method returns 0. If this version object represents a smaller (earlier) version than that represented by the version parameter, this method returns a negative number. Otherwise, it returns a positive number. In particular, this method returns one of the following values:
- -4
- This version object has a smaller (earlier) major number than version.
- -3
- This version object has a smaller (earlier) minor number than version.
- -2
- This version object has a smaller (earlier) release number than version.
- -1
- This version object has a smaller (earlier) build number than version.
- 0
- The version numbers are the same; both objects represent the same version.
- 1
- This version object has a larger (newer) build number than version.
- 2
- This version object has a larger (newer) release number than version.
- 3
- This version object has a larger (newer) minor number than version.
- 4
- This version object has a larger (newer) major number than version.
The following constants are defined and available for checking the value returned by compareTo:
InstallVersion.MAJOR_DIFFInstallVersion.MINOR_DIFFInstallVersion.REL_DIFFInstallVersion.BLD_DIFFInstallVersion.EQUALInstallVersion.MAJOR_DIFF_MINUSInstallVersion.MINOR_DIFF_MINUSInstallVersion.REL_DIFF_MINUSInstallVersion.BLD_DIFF_MINUS
[edit] Example
This code uses the compareTo method to determine whether or not version 3.2.1 of the Royal Airways software has been previously installed:
existingVI = InstallTrigger.getVersion("/royalairways/royalsw");
if ( existingVI.compareTo("3.2.1") <= 0 ) {
// ... proceed to update ...
}