Class Version.Builder

java.lang.Object
com.github.zafarkhaja.semver.Version.Builder
Enclosing class:
Version

public static class Version.Builder extends Object
A mutable builder for the immutable Version class
  • Constructor Details

    • Builder

      public Builder()
      Default constructor, initializes fields with default values (0.0.0)
    • Builder

      @Deprecated public Builder(String normal)
      Deprecated.
      forRemoval since 0.10.0
      Parameters:
      normal - a string representing a normal version, non-null
      Throws:
      IllegalArgumentException - if (@code normal) is null
  • Method Details

    • setVersionCore

      public Version.Builder setVersionCore(long major)
      Sets the major version; the minor and patch versions are assigned 0.
      Parameters:
      major - a major version number, non-negative
      Returns:
      this Builder instance
      Throws:
      IllegalArgumentException - if major is negative
      Since:
      0.10.0
    • setVersionCore

      public Version.Builder setVersionCore(long major, long minor)
      Sets the major and minor versions; the patch version is assigned 0.
      Parameters:
      major - a major version number, non-negative
      minor - a minor version number, non-negative
      Returns:
      this Builder instance
      Throws:
      IllegalArgumentException - if any of the arguments is negative
      Since:
      0.10.0
    • setVersionCore

      public Version.Builder setVersionCore(long major, long minor, long patch)
      Sets major, minor and patch versions.
      Parameters:
      major - a major version number, non-negative
      minor - a minor version number, non-negative
      patch - a patch version number, non-negative
      Returns:
      this Builder instance
      Throws:
      IllegalArgumentException - if any of the arguments is negative
      Since:
      0.10.0
    • setMajorVersion

      public Version.Builder setMajorVersion(long major)
      Sets the major version.
      Parameters:
      major - a major version number, non-negative
      Returns:
      this Builder instance
      Throws:
      IllegalArgumentException - if major is negative
      Since:
      0.10.0
    • setMinorVersion

      public Version.Builder setMinorVersion(long minor)
      Sets the minor version.
      Parameters:
      minor - a minor version number, non-negative
      Returns:
      this Builder instance
      Throws:
      IllegalArgumentException - if minor is negative
      Since:
      0.10.0
    • setPatchVersion

      public Version.Builder setPatchVersion(long patch)
      Sets the patch version.
      Parameters:
      patch - a patch version number, non-negative
      Returns:
      this Builder instance
      Throws:
      IllegalArgumentException - if patch is negative
      Since:
      0.10.0
    • setPreReleaseVersion

      public Version.Builder setPreReleaseVersion(String... ids)
      Sets the pre-release version.

      Multiple identifiers can be specified in a single argument joined with dots, or in separate arguments, or both.

      Parameters:
      ids - one or more pre-release identifiers, non-null
      Returns:
      this Builder instance
      Throws:
      IllegalArgumentException - if ids is null/empty or contains null
    • addPreReleaseIdentifiers

      public Version.Builder addPreReleaseIdentifiers(String... ids)
      Appends (additional) pre-release identifier(s).

      If no pre-release identifiers have been previously set, the method works as setPreReleaseVersion(String...).

      Multiple identifiers can be specified in a single argument joined with dots, or in separate arguments, or both.

      Parameters:
      ids - one or more pre-release identifiers, non-null
      Returns:
      this Builder instance
      Throws:
      IllegalArgumentException - if ids is null/empty or contains null
      Since:
      0.10.0
      See Also:
    • unsetPreReleaseVersion

      public Version.Builder unsetPreReleaseVersion()
      Unsets the pre-release version.
      Returns:
      this Builder instance
      Since:
      0.10.0
    • setBuildMetadata

      public Version.Builder setBuildMetadata(String... ids)
      Sets the build metadata.

      Multiple identifiers can be specified in a single argument joined with dots, or in separate arguments, or both.

      Parameters:
      ids - one or more build identifiers, non-null
      Returns:
      this Builder instance
      Throws:
      IllegalArgumentException - if ids is null/empty or contains null
    • addBuildIdentifiers

      public Version.Builder addBuildIdentifiers(String... ids)
      Appends (additional) build identifier(s).

      If no build identifiers have been previously set, the method works as setBuildMetadata(String...).

      Multiple identifiers can be specified in a single argument joined with dots, or in separate arguments, or both.

      Parameters:
      ids - one or more build identifiers, non-null
      Returns:
      this Builder instance
      Throws:
      IllegalArgumentException - if ids is null/empty or contains null
      Since:
      0.10.0
      See Also:
    • unsetBuildMetadata

      public Version.Builder unsetBuildMetadata()
      Unsets the build metadata.
      Returns:
      this Builder instance
      Since:
      0.10.0
    • build

      public Version build()
      Obtains a Version instance with previously set values.
      Returns:
      a Version instance
      Throws:
      ParseException - if any of the previously set identifiers can't be parsed
      See Also:
    • setNormalVersion

      @Deprecated public Version.Builder setNormalVersion(String normal)
      Deprecated.
      forRemoval since 0.10.0
      Parameters:
      normal - a string representing a normal version, non-null
      Returns:
      this Builder instance
      Throws:
      IllegalArgumentException - if (@code normal) is null