Class Version

java.lang.Object
org.savantbuild.domain.Version
All Implemented Interfaces:
Comparable<Version>

public class Version extends Object implements Comparable<Version>
This class models a simple three number version as well as any free form version String. It has two modes of operation, strict and relaxed.

When this class is constructed in it tries everything in its power to figure out what the heck a version string is and will only fail if the version string has two delimiters next to each other or begins/ends with a delimiter.

For the most part, this class correctly implements the Semantic Versioning system. This can be found here:

http://semver.org

The only notable except to this scheme is that Savant supports integration builds, which are not released versions, but are local versions to a single developer or a team. Integration builds are always denoted by an additional version specifier of -{integration}. For example, 1.0.0-{integration} denotes an integration build.

  • Field Details

    • INTEGRATION

      public static final String INTEGRATION
      See Also:
    • major

      public final int major
    • metaData

      public final String metaData
    • minor

      public final int minor
    • patch

      public final int patch
    • preRelease

      public final Version.PreRelease preRelease
  • Constructor Details

    • Version

      public Version()
    • Version

      public Version(int major, int minor, int patch, Version.PreRelease preRelease, String metaData)
      Constructs a version with the given major, minor and patch version numbers.
      Parameters:
      major - The major version number.
      minor - The minor version number.
      patch - The patch version number.
      preRelease - The pre-release object.
      metaData - The build meta data string.
    • Version

      public Version(String version)
      Constructs a version by parsing the given String.
      Parameters:
      version - The version String to parse.
      Throws:
      VersionException - If the string is incorrectly formatted and does not conform to the semantic versioning scheme (starts with a delimiter (. or -), contains two delimiters in a row, doesn't have proper pre-release or meta-data information).
  • Method Details

    • compareTo

      public int compareTo(Version other)
      Returns the value of the comparison between this Version and the given Object. This throws an exception if the object given is not a Version.
      Specified by:
      compareTo in interface Comparable<Version>
      Parameters:
      other - The other Object to compare against.
      Returns:
      A positive integer if this Version is larger than the given version. Zero if the given Version is the exact same as this Version. A negative integer is this Version is smaller that the given Version.
    • equals

      public boolean equals(Object o)
      Compares the given Object with this Version for equality.
      Overrides:
      equals in class Object
      Parameters:
      o - The object to compare with this Version for equality.
      Returns:
      True if they are both Versions and equal, false otherwise.
    • getMajor

      public int getMajor()
    • getMetaData

      public String getMetaData()
    • getMinor

      public int getMinor()
    • getPatch

      public int getPatch()
    • getPreRelease

      public Version.PreRelease getPreRelease()
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
      Returns:
      A valid hashcode for the Version.
    • isCompatibleWith

      public boolean isCompatibleWith(Version other)
      Performs semantic version compatibility checking. If this version is on the 0.x line, than the other version has to be on the same minor line (e.g. 0.3 is not compatible with 0.4). Otherwise, the two versions have to be on the same major line (e.g. 1.0 is not compatible with 2.0).
      Parameters:
      other - The other version to check against.
      Returns:
      True if the versions are compatible, false if they aren't.
    • isIntegration

      public boolean isIntegration()
      Returns:
      True if this Version is an integration, false for all other types of versions.
    • isMajor

      public boolean isMajor()
      Returns:
      True if this Version is a major, false for all other types of versions.
    • isMinor

      public boolean isMinor()
      Returns:
      True if this Version is a minor, false for all other types of versions.
    • isPatch

      public boolean isPatch()
      Returns:
      True if this Version is a patch, false for all other types of versions.
    • isPreRelease

      public boolean isPreRelease()
      Returns:
      True if this Version is a snapshot, false for all other types of versions.
    • toIntegrationVersion

      public Version toIntegrationVersion()
    • toString

      public String toString()
      Converts the version number to a string suitable for debugging.
      Overrides:
      toString in class Object
      Returns:
      A String of the version number.