APIdia Launch Partner
Top Description Fields Constructors Methods
jdk.internal.util

public final Record OSVersion

extends Record
implements Comparable<OSVersion>
Class Inheritance
All Implemented Interfaces
java.lang.Comparable
Record Components
major:int
major version
minor:int
minor version
micro:int
micro version

A software Version with major, minor, and micro components.

Field Summary

Modifier and TypeField and Description
private static final OSVersion
private final int
major

Record Component accessed by major().

major version
private final int
micro

Record Component accessed by micro().

micro version
private final int
minor

Record Component accessed by minor().

minor version

Constructor Summary

AccessConstructor and Description
public
OSVersion(int
major version
major
,
int
minor version
minor
)

Returns a Version for major, minor versions.

public
OSVersion(int major, int minor, int micro)

Method Summary

Modifier and TypeMethod and Description
public int

Returns:

Compare this version with another version
compareTo
(OSVersion
the object to be compared
other
)

Implements java.lang.Comparable.compareTo.

Returns Compare this version with another version.

public static OSVersion

Returns:

the current operating system version
current
()

Returns the current operating system version.

public final boolean
equals(Object o)

Implements abstract java.lang.Record.equals.

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

public final int
hashCode()

Implements abstract java.lang.Record.hashCode.

Returns a hash code value for the record.

private static OSVersion
public int
major()

Record Component getter of major.

Record Component major version

public int
micro()

Record Component getter of micro.

Record Component micro version

public int
minor()

Record Component getter of minor.

Record Component minor version

public static OSVersion

Returns:

A Version parsed from a version string split on "." characters
parse
(String
a version string
str
)

Returns A Version parsed from a version string split on "." characters.

private static int

Returns:

The index of the first non-digit from start
skipDigits
(String s, int start)

Returns The index of the first non-digit from start.

public String
toString()

Implements abstract java.lang.Record.toString.

Returns a string representation of the record.

Field Detail

CURRENT_OSVERSIONback to summary
private static final OSVersion CURRENT_OSVERSION
majorback to summary
private final int major

Record Component accessed by major().

major version

microback to summary
private final int micro

Record Component accessed by micro().

micro version

minorback to summary
private final int minor

Record Component accessed by minor().

minor version

Constructor Detail

OSVersionback to summary
public OSVersion(int major, int minor)

Returns a Version for major, minor versions.

Parameters
major:int

major version

minor:int

minor version

OSVersionback to summary
public OSVersion(int major, int minor, int micro)

Method Detail

compareToback to summary
public int compareTo(OSVersion other)

Implements java.lang.Comparable.compareTo.

Returns Compare this version with another version.

Parameters
other:OSVersion

the object to be compared

Returns:int

Compare this version with another version

Annotations
@Override
currentback to summary
public static OSVersion current()

Returns the current operating system version.

Returns:OSVersion

the current operating system version

equalsback to summary
public final boolean equals(Object o)

Implements abstract java.lang.Record.equals.

Doc from java.lang.Record.equals.

Indicates whether some other object is "equal to" this one. In addition to the general contract of Object.equals, record classes must further obey the invariant that when a record instance is "copied" by passing the result of the record component accessor methods to the canonical constructor, as follows:

    R copy = new R(r.c1(), r.c2(), ..., r.cn());
then it must be the case that r.equals(copy).
hashCodeback to summary
public final int hashCode()

Implements abstract java.lang.Record.hashCode.

Doc from java.lang.Record.hashCode.

Returns a hash code value for the record. Obeys the general contract of Object.hashCode. For records, hashing behavior is constrained by the refined contract of Record.equals, so that any two records created from the same components must have the same hash code.

initVersionback to summary
private static OSVersion initVersion()
majorback to summary
public int major()

Record Component getter of major.

Record Component
major version
microback to summary
public int micro()

Record Component getter of micro.

Record Component
micro version
minorback to summary
public int minor()

Record Component getter of minor.

Record Component
minor version
parseback to summary
public static OSVersion parse(String str) throws IllegalArgumentException

Returns A Version parsed from a version string split on "." characters. Only major, minor, and micro version numbers are parsed, finer detail is ignored. Missing values for minor and micro are replaced with zero. The string must start with a number, if there is a '.' it must be followed by a number.

Parsed by hand because it is called before RegEx can be initialized safely.

Parameters
str:String

a version string

Returns:OSVersion

A Version parsed from a version string split on "." characters

Exceptions
IllegalArgumentException:
if the string does not start with digits or digits do not follow '.'
skipDigitsback to summary
private static int skipDigits(String s, int start)

Returns The index of the first non-digit from start.

Returns:int

The index of the first non-digit from start

Exceptions
IllegalArgumentException:
if there are no digits
toStringback to summary
public String toString()

Implements abstract java.lang.Record.toString.

Doc from java.lang.Record.toString.

Returns a string representation of the record. In accordance with the general contract of Object#toString(), the toString method returns a string that "textually represents" this record. The result should be a concise but informative representation that is easy for a person to read.

In addition to this general contract, record classes must further participate in the invariant that any two records which are equal must produce equal strings. This invariant is necessarily relaxed in the rare case where corresponding equal component values might fail to produce equal strings for themselves.

Annotations
@Override