public class JavaVersion extends Object
java.version
property and extracts the components to able to compare versions.
Handles Java 9 version 9.1.3.0-ea
(spec.feature.security.patch[-prebuildinfo]
). Handles old Java versions
1.8.0_40-ea
(major.minor.micro_update[-prebuildinfo]
). Does not do any
interpretation of the numbers. Does not handle comparison between 9.1.0
and
1.9.2.0
(a version which should never exist).Modifier and Type | Field and Description |
---|---|
static int |
UNKNOWN
Constant denoting an unparsable number.
|
Constructor and Description |
---|
JavaVersion(boolean isEarlyAccess,
int... versionNumbers)
Create an instance based on version numbers.
|
JavaVersion(int... versionNumbers)
Create an instance based on version numbers.
|
JavaVersion(String version)
Create an instance based on a Java version string as reported by a Java runtime.
|
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object obj) |
int |
getMajorVersion() |
int |
hashCode() |
boolean |
isEarlyAccess() |
boolean |
isGreaterOrEqualThan(JavaVersion otherVersion)
Compare another version instance with this instance.
|
boolean |
isSameMajorVersion(JavaVersion otherVersion)
Check if another version instance has the same major version as this instance.
|
String |
toString() |
public static final int UNKNOWN
public JavaVersion(String version)
version
- Java version stringpublic JavaVersion(int... versionNumbers)
versionNumbers
- One or more numbers denoting a Java version. The first number is the major
version, the second number is the minor version, the third number is the micro
version, and the fourth number is the update version. If one or more numbers are
omitted, then zeroes will be used for them.public JavaVersion(boolean isEarlyAccess, int... versionNumbers)
isEarlyAccess
- true
if this version should indicate an early access build, false
otherwiseversionNumbers
- One or more numbers denoting a Java version. The first number is the major
version, the second number is the minor version, the third number is the micro
version, and the fourth number is the update version. If one or more numbers are
omitted, then zeroes will be used for them.public boolean isGreaterOrEqualThan(JavaVersion otherVersion)
otherVersion
- version to compare withtrue
if this instance is greater than or equal to otherVersion
public boolean isSameMajorVersion(JavaVersion otherVersion)
otherVersion
- version to compare withtrue
if this instance has the same major version number as
otherVersion
public int getMajorVersion()
public boolean isEarlyAccess()
true
if this instance indicates an early access releaseCopyright © 2020. All rights reserved.