Top Description Fields Constructors Methods
org.eclipse.persistence.internal.helper

public final Class JavaVersion

extends Object
Class Inheritance
Imports
java.lang.reflect.Method, java.util.regex.Matcher, .Pattern, org.eclipse.persistence.internal.security.PrivilegedAccessHelper

Java version storage class. Used for version numbers retrieved from Java specification version string. Stored version is in <major>.<minor> format.
Author
Tomas Kraus, Peter Benedikovic

Field Summary

Modifier and TypeField and Description
private final int
major

Major version number.

private final int
minor

Minor version number.

public static final char
PATCH_SEPARATOR

JavaEE platform patch version element separator character.

private static final String
RUNTIME_VERSION_METHOD_NAME

JDK 9+ java.lang.Runtime static version() method name.

public static final char
SEPARATOR

JavaEE platform version elements separator character.

private static final String
VERSION_CLASS_NAME

JDK 9+ java.lang.Runtime.Version class name.

private static final int
VM_MIN_VERSION_TOKENS

Number of Matcher groups (REGEX tokens) expected in Java VM version output.

private static final Pattern
VM_VERSION_PATTERN

Compiled regular expression pattern to read individual version number components.

public static final String
VM_VERSION_PROPERTY

Java VM version system property name.

Constructor Summary

AccessConstructor and Description
public
JavaVersion(final int
Major version number.
major
,
final int
Minor version number.
minor
)

Constructs an instance of Java specification version number.

Method Summary

Modifier and TypeMethod and Description
public int

Returns:

Compare result:
  • Value 1 if this value is greater than supplied version value.
  • Value -1 if this value is lesser than supplied version value.
  • Value 0 if both this value and supplied version values are equal.
comapreTo
(final JavaVersion
JavaVersion object to compare with this object.
version
)

Compares this JavaVersion object against another one.

public int

Returns:

Major version number.
getMajor
()

Get major version number.

public int

Returns:

Minor version number.
getMinor
()

Get minor version number.

private static Integer
getRuntimeVersionNumber(final Object
Runtime.Version class instance containing JDK version information.
vObj
,
final String
name of Runtime.Version instance method to invoke.
name
)

Invoke Runtime.Version method with given name (major or minor) to retrieve version numbers.

private static JavaVersion

Returns:

Current JDK version for any JDK from system property.
propertyVersion
()

Retrieve Java specification version from JDK system property.

private static JavaVersion

Returns:

Current JDK version for any JDK from system property.
propertyVersionParser
(final String version)

Parse Java specification version from JDK system property provided as an argument.

private static JavaVersion

Returns:

Current JDK version for JDK 9 and later or null otherwise or when any problem with version retrieval happened.
runtimeVersion
()

Retrieve JDK version numbers from Runtime.Version instance returned by Runtime#version() method.

private static Object

Returns:

Runtime.Version instance for JDK 9 and later or null otherwise.
runtimeVersionObject
()

Invoke Runtime#version() method to retrieve Runtime.Version instance.

public JavaSEPlatform

Returns:

JavaSEPlatform matching this Java SE specification version or JavaSEPlatform.DEFAULT as default when platform matching fails.
toPlatform
()

Return JavaSEPlatform matching this Java SE specification version.

public String

Returns:

Java VM version string.
toString
()

Overrides java.lang.Object.toString.

Return String representation of Java VM version object.
public static JavaVersion
vmVersion()

Java specification version detector.

public static String

Returns:

Java specification version String from JDK system property.
vmVersionString
()

Retrieves Java specification version String from JDK system property.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

majorback to summary
private final int major

Major version number.

minorback to summary
private final int minor

Minor version number.

PATCH_SEPARATORback to summary
public static final char PATCH_SEPARATOR

JavaEE platform patch version element separator character.

RUNTIME_VERSION_METHOD_NAMEback to summary
private static final String RUNTIME_VERSION_METHOD_NAME

JDK 9+ java.lang.Runtime static version() method name.

SEPARATORback to summary
public static final char SEPARATOR

JavaEE platform version elements separator character.

VERSION_CLASS_NAMEback to summary
private static final String VERSION_CLASS_NAME

JDK 9+ java.lang.Runtime.Version class name.

VM_MIN_VERSION_TOKENSback to summary
private static final int VM_MIN_VERSION_TOKENS

Number of Matcher groups (REGEX tokens) expected in Java VM version output.

VM_VERSION_PATTERNback to summary
private static final Pattern VM_VERSION_PATTERN

Compiled regular expression pattern to read individual version number components. Expected input is string like java version "1.6" or 9.

VM_VERSION_PROPERTYback to summary
public static final String VM_VERSION_PROPERTY

Java VM version system property name.

Constructor Detail

JavaVersionback to summary
public JavaVersion(final int major, final int minor)

Constructs an instance of Java specification version number.

Parameters
major:int

Major version number.

minor:int

Minor version number.

Method Detail

comapreToback to summary
public int comapreTo(final JavaVersion version)

Compares this JavaVersion object against another one.

Parameters
version:JavaVersion

JavaVersion object to compare with this object.

Returns:int

Compare result:

  • Value 1 if this value is greater than supplied version value.
  • Value -1 if this value is lesser than supplied version value.
  • Value 0 if both this value and supplied version values are equal.
getMajorback to summary
public int getMajor()

Get major version number.

Returns:int

Major version number.

getMinorback to summary
public int getMinor()

Get minor version number.

Returns:int

Minor version number.

getRuntimeVersionNumberback to summary
private static Integer getRuntimeVersionNumber(final Object vObj, final String name)

Invoke Runtime.Version method with given name (major or minor) to retrieve version numbers.

Parameters
vObj:Object

Runtime.Version class instance containing JDK version information.

name:String

name of Runtime.Version instance method to invoke.

propertyVersionback to summary
private static JavaVersion propertyVersion()

Retrieve Java specification version from JDK system property.

Returns:JavaVersion

Current JDK version for any JDK from system property.

propertyVersionParserback to summary
private static JavaVersion propertyVersionParser(final String version)

Parse Java specification version from JDK system property provided as an argument. Version string should look like:

  • "MA.MI"
Where
  • MA is major version number,
  • MI is minor version number
Label java version is parsed as non case sensitive.
Returns:JavaVersion

Current JDK version for any JDK from system property.

runtimeVersionback to summary
private static JavaVersion runtimeVersion()

Retrieve JDK version numbers from Runtime.Version instance returned by Runtime#version() method. This works only for JDK 9 and later.

Returns:JavaVersion

Current JDK version for JDK 9 and later or null otherwise or when any problem with version retrieval happened.

runtimeVersionObjectback to summary
private static Object runtimeVersionObject()

Invoke Runtime#version() method to retrieve Runtime.Version instance.

Returns:Object

Runtime.Version instance for JDK 9 and later or null otherwise.

toPlatformback to summary
public JavaSEPlatform toPlatform()

Return JavaSEPlatform matching this Java SE specification version.

Returns:JavaSEPlatform

JavaSEPlatform matching this Java SE specification version or JavaSEPlatform.DEFAULT as default when platform matching fails.

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Return String representation of Java VM version object.

Returns:String

Java VM version string.

Annotations
@Override
vmVersionback to summary
public static JavaVersion vmVersion()

Java specification version detector.

vmVersionStringback to summary
public static String vmVersionString()

Retrieves Java specification version String from JDK system property.

Returns:String

Java specification version String from JDK system property.