Class Version

java.lang.Object
io.spring.initializr.generator.version.Version
All Implemented Interfaces:
Serializable, Comparable<Version>

public final class Version extends Object implements Serializable, Comparable<Version>
Define a version. A typical version is represented as MAJOR.MINOR.PATCH[QUALIFIER] where the qualifier is optional and can have an extra version.

For example: 1.2.0.RC1 is the first release candidate of 1.2.0 and 1.5.0-M4 is the fourth milestone of 1.5.0. The special RELEASE qualifier indicates a final release (a.k.a. GA).

Two formats are currently supported, Version.Format.V1 that uses a dot to separate the qualifier from the version itself and Version.Format.V2 that is SemVer compliant (and therefore uses a dash to separate the qualifier).

The main purpose of parsing a version is to compare it with another version.

Author:
Stephane Nicoll
See Also:
  • Constructor Details

  • Method Details

    • format

      public Version format(Version.Format format)
      Format this version to the specified Version.Format.
      Parameters:
      format - the format to use
      Returns:
      a version compliant with the specified format.
    • getMajor

      public @Nullable Integer getMajor()
    • getMinor

      public @Nullable Integer getMinor()
    • getPatch

      public @Nullable Integer getPatch()
    • getQualifier

      public @Nullable Version.Qualifier getQualifier()
    • getFormat

      public Version.Format getFormat()
    • isGeneralAvailability

      public boolean isGeneralAvailability()
      Specify if this version is a general availability (GA) release, that is a version with no qualifier or with the special RELEASE qualifier.
      Returns:
      true if this version is a GA release
    • parse

      public static Version parse(String text)
      Parse the string representation of a Version. Throws an InvalidVersionException if the version could not be parsed.
      Parameters:
      text - the version text
      Returns:
      a Version instance for the specified version text
      Throws:
      InvalidVersionException - if the version text could not be parsed
      See Also:
    • safeParse

      public static @Nullable Version safeParse(@Nullable String text)
      Parse safely the specified string representation of a Version.

      Return null if the text represents an invalid version.

      Parameters:
      text - the version text
      Returns:
      a Version instance for the specified version text
      See Also:
    • compareTo

      public int compareTo(@Nullable Version other)
      Specified by:
      compareTo in interface Comparable<Version>
    • equals

      public boolean equals(@Nullable Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object