Top Description Fields Constructors Methods
org.graalvm.home

public final Class Version

extends Object
implements Comparable<Version>
Class Inheritance
All Implemented Interfaces
java.lang.Comparable
Imports
java.util.Arrays, .Objects

A version utility to canonicalize and compare GraalVM versions. The GraalVM version string is not standardized and may change without notice. This class is designed to evolve with GraalVM to cover all used version formats in use. It allows to create, validate and compare GraalVM versions. Do not rely on the format of the raw version string or the result of toString(), only use it to produce output for humans.

To create version instances of a particular version use the create(int...) factory method. Use getCurrent() to lookup the current GraalVM version or parse(String) to parse it from a raw string.

Usage example:

This code example compares the current GraalVM version to be at least 19.3 and fails if it is not.
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.

Since
19.3
See Also
HomeFinder#getVersion()

Field Summary

Modifier and TypeField and Description
private static final int
private final boolean
private static final String
private static final String
private final String
private final int[]

Constructor Summary

AccessConstructor and Description
pack-priv
Version(int... versions)

pack-priv

Method Summary

Modifier and TypeMethod and Description
public int
compareTo(Version
the object to be compared.
o
)

Implements java.lang.Comparable.compareTo.

Compares this object with the specified object for order.

public int
compareTo(int...
the object to be compared.
compareVersions
)

Implements java.lang.Comparable.compareTo.

Compares this version to another GraalVM version.

public static Version
create(int... versions)

Constructs a new GraalVM version from a list of version numbers.

public boolean
equals(Object
the reference object with which to compare.
obj
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

public String
format(String format)

Format the GraalVM version with a custom format string.

public static Version
getCurrent()

Returns the current GraalVM version of the installed component.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

private static IllegalArgumentException
public boolean
isRelease()

Returns true if this is a supported release build of GraalVM else false.

public boolean
isSnapshot()

Returns true if this is an unsupported snapshot build of GraalVM else false.

public static Version
parse(String versionString)

Parses a GraalVM version from its String raw format.

private String
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

private static int[]
trimTrailingZeros(int[] intVersions)

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

MIN_VERSION_DIGITSback to summary
private static final int MIN_VERSION_DIGITS
snapshotback to summary
private final boolean snapshot
SNAPSHOT_STRINGback to summary
private static final String SNAPSHOT_STRING
SNAPSHOT_SUFFIXback to summary
private static final String SNAPSHOT_SUFFIX
suffixback to summary
private final String suffix
versionsback to summary
private final int[] versions

Constructor Detail

Versionback to summary
pack-priv Version(int... versions)
Versionback to summary
pack-priv Version(String v)

Method Detail

compareToback to summary
public int compareTo(Version o)

Implements java.lang.Comparable.compareTo.

Doc from java.lang.Comparable.compareTo.

Compares this object with the specified object for order. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

The implementor must ensure signum(x.compareTo(y)) == -signum(y.compareTo(x)) for all x and y. (This implies that x.compareTo(y) must throw an exception if and only if y.compareTo(x) throws an exception.)

The implementor must also ensure that the relation is transitive: (x.compareTo(y) > 0 && y.compareTo(z) > 0) implies x.compareTo(z) > 0.

Finally, the implementor must ensure that x.compareTo(y)==0 implies that signum(x.compareTo(z)) == signum(y.compareTo(z)), for all z.

Parameters
o:Version

the object to be compared.

Returns:int

a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

Annotations
@Override
Since
19.3
compareToback to summary
public int compareTo(int... compareVersions)

Implements java.lang.Comparable.compareTo.

Compares this version to another GraalVM version. This is equivalent to using: compareTo(Version.create(compareVersions)) .

Parameters
compareVersions:int[]

Doc from java.lang.Comparable.compareTo.

the object to be compared.

Returns:int

Doc from java.lang.Comparable.compareTo.

a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

Since
19.3
createback to summary
public static Version create(int... versions) throws IllegalArgumentException

Constructs a new GraalVM version from a list of version numbers. The versions must not be null and none of the version numbers must be negative. At least one version number must be non-zero.

Since
19.3
See Also
compareTo(int...)
equalsback to summary
public boolean equals(Object obj)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
obj:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
Since
19.3
formatback to summary
public String format(String format)

Format the GraalVM version with a custom format string.

The format string can contain any of the standard conversions of java.util.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 isRelease
  • "%[S...]" includes a given part only if isSnapshot
  • "%[<digit>...]" includes a given part only if the version contains at least <digit> non-zero version components (<digit> can be 0 to 9)

Examples:

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 ""
Since
23.0
getCurrentback to summary
public static Version getCurrent()

Returns the current GraalVM version of the installed component. Never null.

Since
19.3
See Also
HomeFinder#getVersion()
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object

Annotations
@Override
Since
19.3
invalidback to summary
private static IllegalArgumentException invalid(String v)
isReleaseback to summary
public boolean isRelease()

Returns 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.

Since
19.3
See Also
isSnapshot()
isSnapshotback to summary
public boolean isSnapshot()

Returns 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.

Since
19.3
See Also
isSnapshot()
parseback to summary
public static Version parse(String versionString) throws IllegalArgumentException

Parses a GraalVM version from its String raw format. Throws IllegalArgumentException if the passed string is not a valid GraalVM version.

Since
19.3
processFormatback to summary
private String processFormat(String format)
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override
Since
19.3
trimTrailingZerosback to summary
private static int[] trimTrailingZeros(int[] intVersions)