Class Runtime.Version
- All Implemented Interfaces:
Comparable<Runtime.Version>
- Enclosing class:
Runtime
Version numbers
Aversion number,$VNUM, is a non-empty sequence ofelements separated by period characters (U+002E). An element is eitherzero, or an unsigned integer numeral without leading zeros. The finalelement in a version number must not be zero. When an element isincremented, all subsequent elements are removed. The format is:
[1-9][0-9]*((\.0)*\.[1-9][0-9]*)*
The sequence may be of arbitrary length but the first four elementsare assigned specific meanings, as follows:
$FEATURE.$INTERIM.$UPDATE.$PATCH
$FEATURE— Thefeature-release counter, incremented for every feature releaseregardless of release content. Features may be added in a featurerelease; they may also be removed, if advance notice was given at leastone feature release ahead of time. Incompatible changes may be madewhen justified.$INTERIM— Theinterim-release counter, incremented for non-feature releases thatcontain compatible bug fixes and enhancements but no incompatiblechanges, no feature removals, and no changes to standard APIs.$UPDATE— The update-releasecounter, incremented for compatible update releases that fix securityissues, regressions, and bugs in newer features.$PATCH— The emergencypatch-release counter, incremented only when it's necessary to producean emergency release to fix a critical issue.
The fifth and later elements of a version number are free for use byplatform implementors, to identify implementor-specific patchreleases.
A version number never has trailing zero elements. If an elementand all those that follow it logically have the value zero then all ofthem are omitted.
The sequence of numerals in a version number is compared to anothersuch sequence in numerical, pointwise fashion;e.g.,10.0.4 is less than10.1.2. If one sequence is shorter thananother then the missing elements of the shorter sequence are consideredto be less than the corresponding elements of the longer sequence;e.g.,10.0.2 is less than10.0.2.1.
Version strings
Aversion string,$VSTR, is a version number$VNUM, as described above, optionally followed by pre-release and buildinformation, in one of the following formats:
$VNUM(-$PRE)?\+$BUILD(-$OPT)? $VNUM-$PRE(-$OPT)? $VNUM(\+-$OPT)?
where:
$PRE, matching([a-zA-Z0-9]+)— A pre-release identifier. Typicallyea, for apotentially unstable early-access release under active development, orinternal, for an internal developer build.$BUILD, matching(0|[1-9][0-9]*)— The build number, incremented for each promotedbuild.$BUILDis reset to1when any portion of$VNUMis incremented.$OPT, matching([-a-zA-Z0-9.]+)— Additional build information, if desired. In the case of aninternalbuild this will often contain the date and time of thebuild.
A version string10-ea matches$VNUM = "10" and$PRE = "ea". The version string10+-ea matches$VNUM = "10" and$OPT = "ea".
When comparing two version strings, the value of$OPT, ifpresent, may or may not be significant depending on the chosencomparison method. The comparison methodscompareTo() andcompareToIgnoreOptional() should be used consistently with thecorresponding methodsequals() andequalsIgnoreOptional().
Ashort version string,$SVSTR, often useful inless formal contexts, is a version number optionally followed by apre-release identifier:
$VNUM(-$PRE)?
This is avalue-basedclass; programmers should treat instances that areequal as interchangeable and should notuse instances for synchronization, or unpredictable behavior mayoccur. For example, in a future release, synchronization may fail.
- Since:
- 9
Method Summary
Modifier and TypeMethodDescriptionbuild()Returns thebuild number.intcompareTo(Runtime.Version obj) Compares this version to another.intCompares this version to another disregarding optional buildinformation.booleanDetermines whether thisVersionis equal to another object.booleanDetermines whether thisVersionis equal to anotherdisregarding optional build information.intfeature()Returns the value of thefeature element ofthe version number.inthashCode()Returns the hash code of this version.intinterim()Returns the value of theinterim element ofthe version number, or zero if it is absent.intmajor()Deprecated.As of Java SE 10, the first element of a versionnumber is not the major-release number but the feature-releasecounter, incremented for every time-based release.intminor()Deprecated.As of Java SE 10, the second element of a versionnumber is not the minor-release number but the interim-releasecounter, incremented for every interim release.optional()Returnsoptional additional identifying buildinformation.staticRuntime.VersionParses the given string as a validversion string containing aversion number followed by pre-release andbuild information.intpatch()Returns the value of thepatch element of theversion number, or zero if it is absent.pre()Returns the optionalpre-release information.intsecurity()Deprecated.As of Java SE 10, the third element of a versionnumber is not the security level but the update-release counter,incremented for every update release.toString()Returns a string representation of this version.intupdate()Returns the value of theupdate element of theversion number, or zero if it is absent.version()Returns an unmodifiableListof the integersrepresented in theversion number.
Method Details
parse
Parses the given string as a validversion string containing aversion number followed by pre-release andbuild information.- Parameters:
s- A string to interpret as a version- Returns:
- The Version of the given string
- Throws:
IllegalArgumentException- If the given string cannot be interpreted as a valid versionNullPointerException- If the given string isnullNumberFormatException- If an element of the version number or the build number cannot be represented as anInteger
feature
public int feature()Returns the value of thefeature element ofthe version number.- Returns:
- The value of the feature element
- Since:
- 10
interim
public int interim()Returns the value of theinterim element ofthe version number, or zero if it is absent.- Returns:
- The value of the interim element, or zero
- Since:
- 10
update
public int update()Returns the value of theupdate element of theversion number, or zero if it is absent.- Returns:
- The value of the update element, or zero
- Since:
- 10
patch
public int patch()Returns the value of thepatch element of theversion number, or zero if it is absent.- Returns:
- The value of the patch element, or zero
- Since:
- 10
major
Deprecated.Returns the value of the major element of the version number.- Returns:
- The value of the feature element
minor
Deprecated.As of Java SE 10, the second element of a versionnumber is not the minor-release number but the interim-releasecounter, incremented for every interim release. Use theinterim()method in preference to this method. For compatibility,this method returns the value of theinterimelement, or zero if it is absent.Returns the value of the minor element of the version number, orzero if it is absent.- Returns:
- The value of the interim element, or zero
security
Deprecated.Returns the value of the security element of the version number, orzero if it is absent.- Returns:
- The value of the update element, or zero
version
Returns an unmodifiableListof the integersrepresented in theversion number.TheListalways contains at least one element corresponding tothefeature version number.- Returns:
- An unmodifiable list of the integers represented in the version number
pre
Returns the optionalpre-release information.- Returns:
- The optional pre-release information as a String
build
optional
compareTo
Compares this version to another.Each of the components in theversion iscompared in the following order of precedence: version numbers,pre-release identifiers, build numbers, optional build information.
Comparison begins by examining the sequence of version numbers.If one sequence is shorter than another, then the missing elementsof the shorter sequence are considered to be less than thecorresponding elements of the longer sequence.
A version with a pre-release identifier is always considered tobe less than a version without one. Pre-release identifiers arecompared numerically when they consist only of digits, andlexicographically otherwise. Numeric identifiers are considered tobe less than non-numeric identifiers.
A version without a build number is always less than one with abuild number; otherwise build numbers are compared numerically.
The optional build information is compared lexicographically.During this comparison, a version with optional build information isconsidered to be greater than a version without one.
- Specified by:
compareToin interfaceComparable<Runtime.Version>- Parameters:
obj- The object to be compared- Returns:
- A negative integer, zero, or a positive integer if this
Versionis less than, equal to, or greater than the givenVersion - Throws:
NullPointerException- If the given object isnull
compareToIgnoreOptional
Compares this version to another disregarding optional buildinformation.Two versions are compared by examining the version string asdescribed in
compareTo(Version)with the exception that theoptional build information is always ignored.This method provides ordering which is consistent with
equalsIgnoreOptional().- Parameters:
obj- The object to be compared- Returns:
- A negative integer, zero, or a positive integer if this
Versionis less than, equal to, or greater than the givenVersion - Throws:
NullPointerException- If the given object isnull
toString
equals
Determines whether thisVersionis equal to another object.Two
Versions are equal if and only if they represent thesame version string.equalsIgnoreOptional
Determines whether thisVersionis equal to anotherdisregarding optional build information.Two
Versions are equal if and only if they represent thesame version string disregarding the optional build information.- Parameters:
obj- The object to which thisVersionis to be compared- Returns:
trueif, and only if, the given object is aVersionthat is identical to thisVersionignoring the optional build information
hashCode