Version

Represents a version in a format consisting of the following three components:

  1. Dot-separated version number of infinite length (ex. 1.0.0.0.0.1, 1.0.0, 1, etc.). Individual components must be non-negative integers and cannot contain leading zeros, except for 0 itself.

  2. Optional pre-release stage (any of snapshot, alpha, beta, rc (ignoring capitalization)), separated by a dash from the main version number and followed by an optional pre-release version number as in (1). (ex. 1.0.0-alpha, 1.0.0-beta.1.2.3)

  3. Optional metadata, separated by a plus sign from the main version number. Metadata consists of one or multiple dot-separated identifiers, which themselves are non-empty alphanumeric strings. (ex. 1.0.0+build.123, 1.0.0+build.123+build.456)

When comparing version numbers, the dot-separated components of version numbers are compared individually, such that 1.11 > 1.2 and no pre-release stage > rc > beta > alpha > snapshot. Metadata is ignored when comparing versions.

This class loosely follows the SemVer specification, but allows variable-length version numbers and restricts the pre-release stages to snapshot, alpha, beta and rc.

Constructors

Link copied to clipboard
constructor(vararg version: Int)

Creates a new release version with the given version number and no metadata.

constructor(version: String)

Creates a new version by parsing the given version string.

Properties

Link copied to clipboard

Whether this version is a full release, i.e. it has no pre-release stage (alpha, beta, rc or snapshot).

Link copied to clipboard

The metadata of the version, or null if there is none.

Functions

Link copied to clipboard
open operator override fun compareTo(other: Version): Int

fun compareTo(other: Version, ignoreIdx: Int): Int

Compares this Version to other.

Link copied to clipboard
open operator override fun equals(other: Any?): Boolean

fun equals(other: Version, ignoreIdx: Int): Boolean

Checks if this version is equal to other.

Link copied to clipboard
open override fun hashCode(): Int
Link copied to clipboard
operator fun rangeTo(other: Version): ClosedVersionRange

Creates a new ClosedVersionRange from this version to the given other version.

Link copied to clipboard
operator fun rangeUntil(other: Version): OpenEndVersionRange

Creates a new OpenEndVersionRange from this version to the given other version.

Link copied to clipboard
open override fun toString(): String

fun toString(separator: String = ".", omitZeros: Boolean = false, omitIdx: Int = -1, omitMetadata: Boolean = false): String

Converts this version to a string, using the given separator