Package org.openjdk.jmc.common.version
Class JavaVersion
- java.lang.Object
-
- org.openjdk.jmc.common.version.JavaVersion
-
public class JavaVersion extends java.lang.Object
Parses thejava.version
property and extracts the components to able to compare versions. Handles Java 9 version9.1.3.0-ea
(spec.feature.security.patch[-prebuildinfo]
). Handles old Java versions1.8.0_40-ea
(major.minor.micro_update[-prebuildinfo]
). Does not do any interpretation of the numbers. Does not handle comparison between9.1.0
and1.9.2.0
(a version which should never exist).
-
-
Field Summary
Fields Modifier and Type Field Description private boolean
isEarlyAccess
static int
UNKNOWN
Constant denoting an unparsable number.private int[]
versionNumbers
-
Constructor Summary
Constructors Constructor Description JavaVersion(boolean isEarlyAccess, int... versionNumbers)
Create an instance based on version numbers.JavaVersion(int... versionNumbers)
Create an instance based on version numbers.JavaVersion(java.lang.String version)
Create an instance based on a Java version string as reported by a Java runtime.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(java.lang.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.private int
parseNumber(int index, java.lang.String[] numbers)
java.lang.String
toString()
-
-
-
Field Detail
-
versionNumbers
private final int[] versionNumbers
-
isEarlyAccess
private final boolean isEarlyAccess
-
UNKNOWN
public static final int UNKNOWN
Constant denoting an unparsable number.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
JavaVersion
public JavaVersion(java.lang.String version)
Create an instance based on a Java version string as reported by a Java runtime.- Parameters:
version
- Java version string
-
JavaVersion
public JavaVersion(int... versionNumbers)
Create an instance based on version numbers.- Parameters:
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.
-
JavaVersion
public JavaVersion(boolean isEarlyAccess, int... versionNumbers)
Create an instance based on version numbers.- Parameters:
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.
-
-
Method Detail
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
isGreaterOrEqualThan
public boolean isGreaterOrEqualThan(JavaVersion otherVersion)
Compare another version instance with this instance.- Parameters:
otherVersion
- version to compare with- Returns:
true
if this instance is greater than or equal tootherVersion
-
isSameMajorVersion
public boolean isSameMajorVersion(JavaVersion otherVersion)
Check if another version instance has the same major version as this instance.- Parameters:
otherVersion
- version to compare with- Returns:
true
if this instance has the same major version number asotherVersion
-
getMajorVersion
public int getMajorVersion()
- Returns:
- the major version number
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
isEarlyAccess
public boolean isEarlyAccess()
- Returns:
true
if this instance indicates an early access release
-
parseNumber
private int parseNumber(int index, java.lang.String[] numbers)
-
-