Class JavaVersion
- All Implemented Interfaces:
Comparable<JavaVersion>
An instance of this class consists of a specification version, a version and a VM version. This is usually for instance 1.7, 1.7.1_11 and 24.11-b01. However, the numbering scheme may differ slightly between different vendors, especially concerning the VM version.
In the following,
version usually means the second part of the 3
version numbers not the complete triple.
All numbers are parsed and compared by number. This allows for different amount of digits. For instance, comparing a 2-digit-number with a 3-digit-number may lead to a wrong result when using string comparison. If strings are part of the version, a string comparison will be used at the appropriate place, i. e. previous and following numbers are compared like other numbers.
The format of the version string is described on the following website: http://www.oracle.com/technetwork/java/javase/versioning-naming-139433.html It also considers specific representations we found in different JVM implementations and versions.
Note: this class has a natural ordering that is inconsistent with equals.
While equals(Object) considers the vendor,
compareTo(JavaVersion) does not. Usually this does not matter since
the vendors use different VM version patterns so instances of
JavaVersions will also differ.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintcompareTo(JavaVersion otherVersion) Compares thisJavaVersionwith the designated one.booleanstatic JavaVersionReturns the version data of the Java VM this method is executed in based on the system propertiesjava.vendor,java.specification.version,java.versionandjava.vm.version.inthashCode()booleanisFCS()Returns whether (the version of) thisJavaVersionis a FCS (first customer shipment) version, i.e.booleanisSpecificationVersion(String specification) Gets whether the specification version of thisJavaVersionis equal to the designated specification version.booleanReturns whether the vendor of thisJavaVersionis equal to the specified vendor.booleansatisfiesMinimumSpecification(String minimumSpec) Gets whether the specification version of thisJavaVersionsatisfies at least the designated specification version.booleansatisfiesMinimumVersion(String minimumVersion) Gets whether the version of thisJavaVersionsatisfies at least the designated version.booleansatisfiesMinimumVmVersion(String minimumVmVersion) Gets whether the VM version of thisJavaVersionsatisfies at least the designated VM version.booleansatisfiesRange(String minimumVersion, String maximumVersion) Gets whether the version of thisJavaVersionlies between the specified lower and upper version limit, both boundaries included.booleansatisfiesVersion(String versionString) Gets whether the version of thisJavaVersionsatisfies the designated partial version.toString()booleanvmNameContains(String content) Gets whether the VM name contains the designated string (case-sensitive).
-
Field Details
-
SPEC_PATTERN
Pattern used to verify the specification version strings. This is a mandatory number followed by a second optional number separated by.. -
VERSION_PATTERN
Pattern used to verify the version strings. This is similar to the specification pattern followed by another optional number separated by., a further number separated by_or., optionally followed by an arbitrary string separated by-. -
VM_VERSION_PATTERN
Pattern used to verify the VM version strings. This is similar to the version pattern followed by an optional number separated by-or+. The group next to last (the arbitrary string) must not start with a digit. At the end a group starting with-is optional. This is required for Linux distributions appending their name at the end.
For OpenJ9 the complete version may start withopenj9-.
-
-
Constructor Details
-
JavaVersion
public JavaVersion(String vendor, String specification, String version, String vmVersion, String vmName) Constructs a newJavaVersionfor the given vendor, specification version, version, VM version and VM name.- Parameters:
vendor- The vendor string of a Java VM.specification- The specification version string of a Java VM.version- The version string of a Java VM.vmVersion- The VM version string of a Java VM.vmName- The name a Java VM, e. g. Oracle or OpenJDK.- Throws:
IllegalArgumentException- If one of the designated strings does not have a legal format. Check the patterns in this class for the format.
-
-
Method Details
-
isFCS
public boolean isFCS()Returns whether (the version of) thisJavaVersionis a FCS (first customer shipment) version, i.e. a final version (in contrast e.g. to a beta or early access version). An FCS version has no dash in its version string.- Returns:
- Whether this version is a FCS version.
-
isVendor
Returns whether the vendor of thisJavaVersionis equal to the specified vendor.- Parameters:
vendor- The specified vendor this vendor has to satisfy.- Returns:
- Whether this vendor is equal to the specified vendor.
-
isSpecificationVersion
Gets whether the specification version of thisJavaVersionis equal to the designated specification version.- Parameters:
specification- The string representation of the specification version the specification version of thisJavaVersionhas to satisfy.- Returns:
- Whether the specification version of this
JavaVersionis equal to the designated specification version. - Throws:
IllegalArgumentException- If the designated specification version string does not have a legal format, anIllegalArgumentExceptionwill be thrown.
-
satisfiesMinimumSpecification
Gets whether the specification version of thisJavaVersionsatisfies at least the designated specification version.- Parameters:
minimumSpec- The minimum the specification version of thisJavaVersionmust be in order to satisfy.- Returns:
- Whether the specification version of this
JavaVersionis the same as the designated specification version or higher. - Throws:
IllegalArgumentException- If the designated specification version string does not have a legal format, anIllegalArgumentExceptionwill be thrown.
-
satisfiesMinimumVersion
Gets whether the version of thisJavaVersionsatisfies at least the designated version.- Parameters:
minimumVersion- The minimum the version of thisJavaVersionmust be in order to satisfy.- Returns:
- Whether the version of this
JavaVersionis the same as the designated version or higher. - Throws:
IllegalArgumentException- If the designated version string does not have a legal format, anIllegalArgumentExceptionwill be thrown.
-
satisfiesVersion
Gets whether the version of thisJavaVersionsatisfies the designated partial version. The designated version need not be fully qualified. Only the provided numbers will be compared. If the designated version is a non-FCS version, the version of thisJavaVersionhas to be at least the designated version. This being an FCS version also satisfies the condition.
This differs fromsatisfiesMinimumVersion(String)since the partial version has to match completely. For instance1.5.0_22satisfies the minimum version1.4but it does not satisfy the version1.4.- Parameters:
versionString- The (partial) version that the version of thisJavaVersionmust be in order to satisfy.- Returns:
- Whether the version of this
JavaVersionsatisfies the designated version. - Throws:
IllegalArgumentException- If the designated version string does not have a legal format, anIllegalArgumentExceptionwill be thrown.
-
satisfiesRange
Gets whether the version of thisJavaVersionlies between the specified lower and upper version limit, both boundaries included.- Parameters:
minimumVersion- The lower limit of the range in which the version of thisJavaVersionmust lie.maximumVersion- The upper limit of the range in which the version of thisJavaVersionmust lie.- Returns:
- Whether the version of this
JavaVersionlies between the specified lower and upper version limit, both boundaries included. - Throws:
IllegalArgumentException- If one of the designated version strings does not have a legal format, anIllegalArgumentExceptionwill be thrown.
-
satisfiesMinimumVmVersion
Gets whether the VM version of thisJavaVersionsatisfies at least the designated VM version.- Parameters:
minimumVmVersion- The minimum the VM version of thisJavaVersionmust be in order to satisfy.- Returns:
- Whether the VM version of this
JavaVersionis the same as the designated VM version or higher. - Throws:
IllegalArgumentException- If the designated VM version string does not have a legal format, anIllegalArgumentExceptionwill be thrown.
-
vmNameContains
Gets whether the VM name contains the designated string (case-sensitive). This allows for instance to distinguish 32 and 64 bit VMs as well as Oracle and Open JDK.- Parameters:
content- The string which to check for whether it is part of the VM name.- Returns:
- Whether the VM name contains the designated string (case-sensitive), e. g.
32/64orHotSpot/OpenJDK.
-
compareTo
Compares thisJavaVersionwith the designated one. This compares the specification version, the version and the VM version (in this order). Note that the version considers a non-FCS version to be less than the FCS version with the same number but no appendix. Strict string comparison would lead to the opposite result.- Specified by:
compareToin interfaceComparable<JavaVersion>- Parameters:
otherVersion- TheJavaVersionto compare thisJavaVersionto.- Returns:
-
equals
-
hashCode
public int hashCode() -
toString
-
getCurrent
Returns the version data of the Java VM this method is executed in based on the system propertiesjava.vendor,java.specification.version,java.versionandjava.vm.version.- Returns:
- The version data of this Java VM.
-