2017-07-11 15:12:03 +02:00
# Version
## Description
Handles version numbers.
2017-11-24 15:59:34 +01:00
2017-07-11 15:12:03 +02:00
## Constructors
### Version(major, minor, patch)
#### Parameters
| parameter | mandatory | default | possible values |
| ----------|-----------|---------|-----------------|
| major | yes | | |
| minor | yes | | |
| patch | no | `-1` | |
2017-11-24 15:59:34 +01:00
* `major` - The major version number.
* `minor` - The minor version number.
* `patch` - The patch version number.
2017-07-11 15:12:03 +02:00
#### Exceptions
2017-11-24 15:59:34 +01:00
* `IllegalArgumentException` :
* If the `major` or `minor` version number is less than `0` .
2017-07-11 15:12:03 +02:00
#### Example
```groovy
def toolVersion = new Version(1, 2, 3)
```
2017-11-24 15:59:34 +01:00
2017-07-11 15:12:03 +02:00
### Version(text)
#### Parameters
| parameter | mandatory | default | possible values |
| ----------|-----------|---------|-----------------|
| text | yes | | |
2017-11-24 15:59:34 +01:00
* `text` - As an alternative to calling the constructor with `major` , `minor` , and `patch` version numbers, you can pass this as a String of format 'major.minor.patch'.
2017-07-11 15:12:03 +02:00
#### Exceptions
2017-11-24 15:59:34 +01:00
* `IllegalArgumentException` :
* If the `text` parameter is `null` or empty.
* `AbortException` :
* If the version `text` has an unexpected format.
2017-07-11 15:12:03 +02:00
#### Example
```groovy
def toolVersion = new Version('1.2.3')
```
2017-11-24 15:59:34 +01:00
2017-07-11 15:12:03 +02:00
## Method Details
2017-11-24 15:59:34 +01:00
### equals(version)
2017-07-11 15:12:03 +02:00
#### Description
Indicates whether some other version instance is equal to this one. The two versions are considered equal when they have the same `major` , `minor` and `patch` version number.
#### Parameters
2017-11-24 15:59:34 +01:00
* `version` - The Version instance to compare to this Version instance.
2017-07-11 15:12:03 +02:00
#### Return value
`true` if `major` , `minor` and `patch` version numbers are equal to each other. Otherwise `false` .
#### Side effects
none
#### Exceptions
2017-11-24 15:59:34 +01:00
* `AbortException` :
* If the parameter `version` is `null` .
2017-07-11 15:12:03 +02:00
#### Example
```groovy
assert new Version('1.2.3').equals(new Version('1.2.3'))
```
2017-11-24 15:59:34 +01:00
### isCompatibleVersion(version)
2017-07-11 15:12:03 +02:00
#### Description
Checks whether a version is compatible. Two versions are compatible if the major version number is the same, while the minor and patch version number are the same or higher.
#### Parameters
2017-11-24 15:59:34 +01:00
* `version` - The Version instance to compare to this Version instance.
2017-07-11 15:12:03 +02:00
#### Return value
`true` if this Version instance is compatible to the other Version instance. Otherwise `false` .
#### Side effects
none
#### Exceptions
2017-11-24 15:59:34 +01:00
* `AbortException` :
* If the parameter `version` is `null` .
2017-07-11 15:12:03 +02:00
#### Example
```groovy
assert new Version('1.2.3').isCompatibleVersion(new Version('1.3.1'))
```
2017-11-24 15:59:34 +01:00
### isHigher(version)
2017-07-11 15:12:03 +02:00
#### Description
Checks whether this Version instance is higher than the other Version instance.
#### Parameters
2017-11-24 15:59:34 +01:00
* `version` - The Version instance to compare to this Version instance.
2017-07-11 15:12:03 +02:00
#### Return value
`true` if this Version instance is higher than the other Version instance. Otherwise `false` .
#### Side effects
none
#### Exceptions
2017-11-24 15:59:34 +01:00
* `AbortException` :
* If the parameter `version` is `null` .
2017-07-11 15:12:03 +02:00
#### Example
```groovy
assert new Version('1.2.3').isHigher(new Version('1.1.6'))
```
2017-11-24 15:59:34 +01:00
### toString()
2017-07-11 15:12:03 +02:00
#### Description
Print the version number in format '< major > .< minor > .< patch > '. If no patch version number exists the format is '< major > .< minor > '.
#### Parameters
none
#### Return value
A String consisting of `major` , `minor` and if available `patch` , separated by dots.
#### Side effects
none
#### Exceptions
none
#### Example
```groovy
assert "${new Version('1.2.3')}" == "1.2.3"
```