public class JavaVersion extends java.lang.Object implements java.lang.Comparable<JavaVersion>
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.
| Modifier and Type | Field and Description |
|---|---|
static java.util.regex.Pattern |
SPEC_PATTERN
Pattern used to verify the specification version strings.
|
static java.util.regex.Pattern |
VERSION_PATTERN
Pattern used to verify the version strings.
|
static java.util.regex.Pattern |
VM_VERSION_PATTERN
Pattern used to verify the VM version strings.
|
| Constructor and Description |
|---|
JavaVersion(java.lang.String vendor,
java.lang.String specification,
java.lang.String version,
java.lang.String vmVersion,
java.lang.String vmName)
Constructs a new
JavaVersion for the given vendor, specification version, version, VM
version and VM name. |
| Modifier and Type | Method and Description |
|---|---|
int |
compareTo(JavaVersion otherVersion)
Compares this
JavaVersion with the designated one. |
boolean |
equals(java.lang.Object obj) |
static JavaVersion |
getCurrent()
Returns the version data of the Java VM this method is executed in based on
the system properties
java.vendor,
java.specification.version, java.version and
java.vm.version. |
int |
hashCode() |
boolean |
isFCS()
Returns whether (the version of) this
JavaVersion is a FCS
(first customer shipment) version, i.e. a final version (in contrast e.g. |
boolean |
isSpecificationVersion(java.lang.String specification)
Gets whether the specification version of this
JavaVersion is
equal to the designated specification version. |
boolean |
isVendor(java.lang.String vendor)
Returns whether the vendor of this
JavaVersion is equal to the
specified vendor. |
boolean |
satisfiesMinimumSpecification(java.lang.String minimumSpec)
Gets whether the specification version of this
JavaVersion
satisfies at least the designated specification version. |
boolean |
satisfiesMinimumVersion(java.lang.String minimumVersion)
Gets whether the version of this
JavaVersion satisfies at
least the designated version. |
boolean |
satisfiesMinimumVmVersion(java.lang.String minimumVmVersion)
Gets whether the VM version of this
JavaVersion satisfies at
least the designated VM version. |
boolean |
satisfiesRange(java.lang.String minimumVersion,
java.lang.String maximumVersion)
Gets whether the version of this
JavaVersion lies between the
specified lower and upper version limit, both boundaries included. |
boolean |
satisfiesVersion(java.lang.String versionString)
Gets whether the version of this
JavaVersion satisfies the
designated partial version. |
java.lang.String |
toString() |
boolean |
vmNameContains(java.lang.String content)
Gets whether the VM name contains the designated string (case-sensitive).
|
public static final java.util.regex.Pattern SPEC_PATTERN
..public static final java.util.regex.Pattern VERSION_PATTERN
., a further number separated by _, optionally
followed by an arbitrary string separated by -.public static final java.util.regex.Pattern VM_VERSION_PATTERN
-
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.public JavaVersion(java.lang.String vendor,
java.lang.String specification,
java.lang.String version,
java.lang.String vmVersion,
java.lang.String vmName)
JavaVersion for the given vendor, specification version, version, VM
version and VM name.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.java.lang.IllegalArgumentException - If one of the designated strings does not have a legal format.
Check the patterns in this class for the format.public boolean isFCS()
JavaVersion is 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.public boolean isVendor(java.lang.String vendor)
JavaVersion is equal to the
specified vendor.vendor - The specified vendor this vendor has to satisfy.public boolean isSpecificationVersion(java.lang.String specification)
JavaVersion is
equal to the designated specification version.specification - The string representation of the specification version
the specification version of this JavaVersion has to
satisfy.JavaVersion
is equal to the designated specification version.java.lang.IllegalArgumentException - If the designated specification version
string does not have a legal format, an
IllegalArgumentException will be thrown.public boolean satisfiesMinimumSpecification(java.lang.String minimumSpec)
JavaVersion
satisfies at least the designated specification version.minimumSpec - The minimum the specification version of this
JavaVersion must be in order to satisfy.JavaVersion
is the same as the designated specification version or higher.java.lang.IllegalArgumentException - If the designated specification version
string does not have a legal format, an
IllegalArgumentException will be thrown.public boolean satisfiesMinimumVersion(java.lang.String minimumVersion)
JavaVersion satisfies at
least the designated version.minimumVersion - The minimum the version of this
JavaVersion must be in order to satisfy.JavaVersion is the same as
the designated version or higher.java.lang.IllegalArgumentException - If the designated version string does not
have a legal format, an IllegalArgumentException
will be thrown.public boolean satisfiesVersion(java.lang.String versionString)
JavaVersion satisfies 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 this JavaVersion
has to be at least the designated version. This being an FCS version also
satisfies the condition. satisfiesMinimumVersion(String) since the partial
version has to match completely. For instance 1.5.0_22
satisfies the minimum version 1.4 but it does not satisfy the
version 1.4.versionString - The (partial) version that the version of this
JavaVersion must be in order to satisfy.JavaVersion satisfies the
designated version.java.lang.IllegalArgumentException - If the designated version string does not
have a legal format, an IllegalArgumentException
will be thrown.public boolean satisfiesRange(java.lang.String minimumVersion,
java.lang.String maximumVersion)
JavaVersion lies between the
specified lower and upper version limit, both boundaries included.minimumVersion - The lower limit of the range in which the version of
this JavaVersion must lie.maximumVersion - The upper limit of the range in which the version of
this JavaVersion must lie.JavaVersion lies between
the specified lower and upper version limit, both boundaries
included.java.lang.IllegalArgumentException - If one of the designated version strings
does not have a legal format, an
IllegalArgumentException will be thrown.public boolean satisfiesMinimumVmVersion(java.lang.String minimumVmVersion)
JavaVersion satisfies at
least the designated VM version.minimumVmVersion - The minimum the VM version of this
JavaVersion must be in order to satisfy.JavaVersion is the same
as the designated VM version or higher.java.lang.IllegalArgumentException - If the designated VM version string does
not have a legal format, an IllegalArgumentException
will be thrown.public boolean vmNameContains(java.lang.String content)
content - The string which to check for whether it is part of the VM name.32/64 or HotSpot/OpenJDK.public int compareTo(JavaVersion otherVersion)
JavaVersion with 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.compareTo in interface java.lang.Comparable<JavaVersion>otherVersion - The JavaVersion to compare this
JavaVersion to.public boolean equals(java.lang.Object obj)
equals in class java.lang.Objectpublic int hashCode()
hashCode in class java.lang.Objectpublic java.lang.String toString()
toString in class java.lang.Objectpublic static JavaVersion getCurrent()
java.vendor,
java.specification.version, java.version and
java.vm.version.