Package com.norconex.commons.lang.version

# Class SemanticVersion

java.lang.Object
com.norconex.commons.lang.version.SemanticVersion

All Implemented Interfaces:
  `Comparable<SemanticVersion>`

public class SemanticVersion extends Object implements Comparable<SemanticVersion>

Immutable semantic version representation, conforming to https://semver.org/ specifications.

Since:
  3.0.0
See Also:
  - `SemanticVersionParser`

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `static class`
  `SemanticVersion.SemanticVersionBuilder`

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final SemanticVersion`
  `UNVERSIONED`
  A special instance that represents a non-versioned entity.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static SemanticVersion.SemanticVersionBuilder`
  `builder()`
  `protected boolean`
  `canEqual(Object other)`
  `int`
  `compareTo(SemanticVersion o)`
  `boolean`
  `equals(Object o)`
  `String`
  `getBuildMetadata()`
  Optional metadata associated with a build.
  `int`
  `getMajor()`
  Major version number.
  `int`
  `getMinor()`
  Minor version number.
  `int`
  `getPatch()`
  Patch version number.
  `String`
  `getPreRelease()`
  Optional pre-release indicator (M1, RC1, etc.).
  `int`
  `hashCode()`
  `boolean`
  `isEquivalentTo(SemanticVersion other)`
  Gets whether this version is semantically equivalent to the other one.
  `boolean`
  `isGreaterOrEquivalentTo(SemanticVersion other)`
  Gets whether this version is semantically greater or equivalent to the other one.
  `boolean`
  `isGreaterThan(SemanticVersion other)`
  Gets whether this version is semantically greater than the other one.
  `boolean`
  `isLowerOrEquivalentTo(SemanticVersion other)`
  Gets whether this version is semantically lower or equivalent to the other one.
  `boolean`
  `isLowerThan(SemanticVersion other)`
  Gets whether this version is semantically lower than the other one.
  `boolean`
  `isVersioned()`
  Gets whether this semantic version is representing something non-versioned.
  `static SemanticVersion`
  `of(int major)`
  Create a new semantic version with the minor and patch numbers set to zero (0).
  `static SemanticVersion`
  `of(int major, int minor)`
  Create a new semantic version with the patch number set to zero (0).
  `static SemanticVersion`
  `of(int major, int minor, int patch)`
  Create a new semantic version.
  `static SemanticVersion`
  `of(int major, int minor, int patch, String preRelease)`
  Create a new semantic version.
  `static SemanticVersion`
  `of(int major, int minor, int patch, String preRelease, String buildMetadata)`
  Create a new semantic version.
  `String`
  `toString()`
  A friendly representation of this semantic version.

  ### Methods inherited from class java.lang.Object

  `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

- ## Field Details

  - ### UNVERSIONED

    public static final SemanticVersion UNVERSIONED
    A special instance that represents a non-versioned entity. This is an alternative to using a `null` value when there is no version. Sets major, minor, and patch values to -1.

- ## Method Details

  - ### of

    public static SemanticVersion of(int major)
    Create a new semantic version with the minor and patch numbers set to zero (0).
    Parameters:
      `major` - major number
    Returns:
      a semantic version

  - ### of

    public static SemanticVersion of(int major, int minor)
    Create a new semantic version with the patch number set to zero (0).
    Parameters:
      `major` - major number
      `minor` - minor number
    Returns:
      a semantic version

  - ### of

    public static SemanticVersion of(int major, int minor, int patch)
    Create a new semantic version.
    Parameters:
      `major` - major number
      `minor` - minor number
      `patch` - patch number
    Returns:
      a semantic version

  - ### of

    public static SemanticVersion of(int major, int minor, int patch, String preRelease)
    Create a new semantic version.
    Parameters:
      `major` - major number
      `minor` - minor number
      `patch` - patch number
      `preRelease` - pre-release qualifier (can be `null`)
    Returns:
      a semantic version

  - ### of

    public static SemanticVersion of(int major, int minor, int patch, String preRelease, String buildMetadata)
    Create a new semantic version.
    Parameters:
      `major` - major number
      `minor` - minor number
      `patch` - patch number
      `preRelease` - pre-release qualifier (can be `null`)
      `buildMetadata` - build metadata (can be `null`)
    Returns:
      a semantic version

  - ### isVersioned

    public boolean isVersioned()
    Gets whether this semantic version is representing something non-versioned. Creating an instance with any of major, minor, and patch values being less than zero is considered non-versioned. A non-versioned instance will always compare lower than a versioned one.
    Returns:
      `true` if versioned

  - ### compareTo

    public int compareTo(SemanticVersion o)
    Specified by:
      `compareTo` in interface `Comparable<SemanticVersion>`

  - ### isEquivalentTo

    public boolean isEquivalentTo(SemanticVersion other)
    Gets whether this version is semantically equivalent to the other one.
    Parameters:
      `other` - other version we are comparing to
    Returns:
      `true` if this version is equivalent to the other

  - ### isGreaterThan

    public boolean isGreaterThan(SemanticVersion other)
    Gets whether this version is semantically greater than the other one.
    Parameters:
      `other` - other version we are comparing to
    Returns:
      `true` if this version is greater than the other

  - ### isGreaterOrEquivalentTo

    public boolean isGreaterOrEquivalentTo(SemanticVersion other)
    Gets whether this version is semantically greater or equivalent to the other one.
    Parameters:
      `other` - other version we are comparing to
    Returns:
      `true` if this version is greater or equivalent to the other

  - ### isLowerThan

    public boolean isLowerThan(SemanticVersion other)
    Gets whether this version is semantically lower than the other one.
    Parameters:
      `other` - other version we are comparing to
    Returns:
      `true` if this version is lower than the other

  - ### isLowerOrEquivalentTo

    public boolean isLowerOrEquivalentTo(SemanticVersion other)
    Gets whether this version is semantically lower or equivalent to the other one.
    Parameters:
      `other` - other version we are comparing to
    Returns:
      `true` if this version is lower or equivalent to the other

  - ### toString

    public String toString()
    A friendly representation of this semantic version.
    Overrides:
      `toString` in class `Object`

  - ### builder

    public static SemanticVersion.SemanticVersionBuilder builder()

  - ### getMajor

    public int getMajor()
    Major version number. The first number of a semantic version.

  - ### getMinor

    public int getMinor()
    Minor version number. The second number of a semantic version.

  - ### getPatch

    public int getPatch()
    Patch version number. The third number of a semantic version.

  - ### getPreRelease

    public String getPreRelease()
    Optional pre-release indicator (M1, RC1, etc.).

  - ### getBuildMetadata

    public String getBuildMetadata()
    Optional metadata associated with a build.

  - ### equals

    public boolean equals(Object o)
    Overrides:
      `equals` in class `Object`

  - ### canEqual

    protected boolean canEqual(Object other)

  - ### hashCode

    public int hashCode()
    Overrides:
      `hashCode` in class `Object`