public class Version extends Object implements Comparable<Version>
4.5.12.12345
.
The second, third, and fourth parts, representing a minor version, a bug-fix version, and a build version, are optional. When comparing versions, a missing part is considered to be 0.
Constructor and Description |
---|
Version(int major)
Constructs a new
Version instance with one part. |
Version(Integer major,
Integer minor,
Integer bugFix,
Integer build)
Constructs a new
Version instance with all four parts. |
Version(int major,
int minor)
Constructs a new
Version instance with two parts. |
Version(int major,
int minor,
int bugFix)
Constructs a new
Version instance with three parts. |
Version(String versionString)
Constructs a new
Version instance from a
one-, two-, three-, or four-part dotted version string. |
Modifier and Type | Method and Description |
---|---|
int |
compareBugFixVersionTo(Version other)
Compares this
Version to another,
considering only the major, minor, and bug-fix parts. |
int |
compareMajorVersionTo(Version other)
Compares this
Version to another,
considering only the major part. |
int |
compareMinorVersionTo(Version other)
Compares this
Version to another,
considering only the major and minor parts. |
int |
compareTo(Version other) |
Integer |
getBugFix()
Gets the bug-fix version number.
|
Integer |
getBuild()
Gets the build version number.
|
String |
getDisplayString()
Converts this
Version |
Integer |
getMajor()
Gets the major version number.
|
Integer |
getMinor()
Gets the minor version number number.
|
String |
toString() |
public Version(Integer major, Integer minor, Integer bugFix, Integer build)
Version
instance with all four parts.major
- The major version number.minor
- The minor version number.bugFix
- The bug-fix version number.build
- The build version number or null
.public Version(int major, int minor, int bugFix)
Version
instance with three parts.major
- The major version number.minor
- The minor version number or null
.bugFix
- The bug-fix version number or null
.public Version(int major, int minor)
Version
instance with two parts.major
- The major version number.minor
- The minor version number or null
.public Version(int major)
Version
instance with one part.major
- The major version number.public Version(String versionString)
Version
instance from a
one-, two-, three-, or four-part dotted version string.public int compareTo(Version other)
compareTo
in interface Comparable<Version>
public Integer getMajor()
Integer
for the major version.public Integer getMinor()
Integer
for the minor version or null
.public Integer getBugFix()
Integer
for the bug-fix version or null
.public Integer getBuild()
Integer
for the build version or null
.public String getDisplayString()
Version to a string for display.
Null parts of the version are not displayed.
"1.2"
.public int compareMajorVersionTo(Version other)
Version
to another,
considering only the major part.other
- Another Version
object.public int compareMinorVersionTo(Version other)
Version
to another,
considering only the major and minor parts.other
- Another Version
object.public int compareBugFixVersionTo(Version other)
Version
to another,
considering only the major, minor, and bug-fix parts.other
- Another Version
object.Copyright © 2016 The Apache Software Foundation. All rights reserved.