public final class Version extends Object implements Comparable<Version>
Version.toString()
, only use it to produce output for humans.
To create version instances of a particular version use the Version.create(int...)
factory
method. Use Version.getCurrent()
to lookup the current GraalVM version or Version.parse(String)
to parse it from a raw string.
if (Version.getCurrent().compareTo(19, 3) < 0) { throw new IllegalStateException("Invalid GraalVM version. Must be at least 19.3."); }
Note: this class has a natural ordering that is inconsistent with equals.
HomeFinder.getVersion()
Modifier and Type | Method and Description |
---|---|
int |
compareTo(int... compareVersions)
Compares this version to another GraalVM version.
|
int |
compareTo(Version o) |
static Version |
create(int... versions)
Constructs a new GraalVM version from a list of version numbers.
|
boolean |
equals(Object obj) |
String |
format(String format)
Format the GraalVM version with a custom format string.
|
static Version |
getCurrent()
Returns the current GraalVM version of the installed component.
|
int |
hashCode() |
boolean |
isRelease()
Returns
true if this is a supported release build of GraalVM else
false . |
boolean |
isSnapshot()
Returns
true if this is an unsupported snapshot build of GraalVM else
false . |
static Version |
parse(String versionString)
Parses a GraalVM version from its String raw format.
|
String |
toString() |
public boolean isRelease()
true
if this is a supported release build of GraalVM else
false
. Use this for implementation assertions that verify that only releases are
deployed to production.Version.isSnapshot()
public boolean isSnapshot()
true
if this is an unsupported snapshot build of GraalVM else
false
. Use this for implementation assertions that verify that only releases are
deployed to production.Version.isSnapshot()
public int compareTo(Version o)
compareTo
in interface Comparable<Version>
public int compareTo(int... compareVersions)
compareTo(Version.create(compareVersions))
.public String format(String format)
The format string can contain any of the standard conversions of Formatter
.
At least four version components (possibly zero) are available as formatter arguments.
In addition to the standard conversions, these special conversions are available:
"%[R...]"
includes a given part only if Version.isRelease()
"%[S...]"
includes a given part only if Version.isSnapshot()
"%[<digit>...]"
includes a given part only if the version contains at least
<digit>
non-zero version components (<digit>
can be 0 to 9)
Version.parse("22.3.0.1").format("%d.%d"); // returns "22.3" Version.parse("22.3.0.1").format("%4$d"); // returns "1" Version.parse("22.3.0.1").format("%[R%d.%d]%[Sdev]"); // returns "22.3" Version.parse("22.3.0.1").format("%[2XX]"); // returns "XX" Version.parse("23.0-dev").format("%3$d"); // returns "0" Version.parse("23.0-dev").format("%[R%d.%d]%[Sdev]"); // returns "dev" Version.parse("23.0-dev").format("%[2XX]"); // returns ""
public static Version parse(String versionString) throws IllegalArgumentException
IllegalArgumentException
if the passed string is not a valid GraalVM version.IllegalArgumentException
public static Version create(int... versions) throws IllegalArgumentException
null
and none of the version numbers must be negative. At least one version
number must be non-zero.IllegalArgumentException
Version.compareTo(int...)
public static Version getCurrent()
null
.HomeFinder.getVersion()