Package megamek

Class Version

java.lang.Object
megamek.Version
All Implemented Interfaces:
Serializable, Comparable<Version>

public final class Version extends Object implements Comparable<Version>, Serializable
This is used for versioning, and to track the current Version the suite is running at.

Versions are written as major.minor.patch[.revision][-extra]. The revision is an optional fourth component reserved for special point releases that ship on top of an existing patch release, such as 0.49.19.1. Ordinary releases have no revision at all, and both toString() and the comparison methods behave exactly as they did before the component existed.

Note that toString() pads the minor and patch components to two digits, so the release labelled v0.51.0.1 on GitHub renders here as 0.51.00.1.

See Also:
  • Field Details

    • NO_REVISION

      public static final int NO_REVISION
      The value getRevision() reports when a version carries no fourth component, which is the case for every ordinary release.

      Zero is deliberately used as the "absent" marker rather than a negative sentinel: a Version restored from an older save game or from an older client's network packet has no stored revision, and Java deserialization leaves such a field at zero. Treating zero as absent therefore keeps those versions reading exactly as they were written. It also means a hand-written 0.51.0.0 is understood as plain 0.51.0, which is the same thing.

      See Also:
    • DEFAULT_SPLASH_TAG_ROTATION

      public static final double DEFAULT_SPLASH_TAG_ROTATION
      The angle the splash tag is sprayed at when it does not ask for one: very slightly off level.
      See Also:
    • NO_NOTES_FONT_SIZE

      public static final int NO_NOTES_FONT_SIZE
      The value getBuildNotesFontSize() reports when no point size is configured, meaning the build note is drawn at whatever size the rest of the menu uses.
      See Also:
  • Constructor Details

    • Version

      public Version()
      This Constructor is not to be used outside of unit testing
    • Version

      public Version(@Nullable String text)
      Sets the version with Extra data.
      Parameters:
      text - The Version string to parse.
    • Version

      public Version(int major, int minor, int patch)
      Sets the version. The resulting version has no revision component.
      Parameters:
      major - Major Version
      minor - Minor Version
      patch - Patch Version
    • Version

      public Version(String major, String minor, String patch)
      Sets the version. The resulting version has no revision component.
      Parameters:
      major - Major Version
      minor - Minor Version
      patch - Patch Version
    • Version

      public Version(String major, String minor, String patch, @Nullable String extra)
      Sets the version with Extra data. The resulting version has no revision component.
      Parameters:
      major - Major Version
      minor - Minor Version
      patch - Patch Version
      extra - Extra would be PR or nightly with git hash.
    • Version

      public Version(String major, String minor, String patch, @Nullable String revision, @Nullable String extra)
      Sets the version with an optional revision and Extra data.

      This is the form used when rebuilding a version that was written to a file, where the revision is simply absent for anything produced by an ordinary release.

      Parameters:
      major - Major Version
      minor - Minor Version
      patch - Patch Version
      revision - Optional fourth component of a point release, or null when there is none
      extra - Extra would be PR or nightly with git hash.
  • Method Details

    • getBuildNotes

      @Nullable public static String getBuildNotes()
      Returns the free-text note this build was released with, such as a warning that it is a development build.
      Returns:
      the build note, or null when this build has none, which is the case for every ordinary release
    • hasBuildNotes

      public static boolean hasBuildNotes()
      Returns:
      true if this build was released with a note to show the player, otherwise false
    • getBuildNotesColorName

      @Nullable public static String getBuildNotesColorName()
      Returns the colour the build note asks to be drawn in, as the plain name written in Version.properties rather than as a colour object, because this class is also used well away from the user interface.
      Returns:
      the configured colour name, or null when the note did not ask for a particular colour
    • getBuildNotesFontSize

      public static int getBuildNotesFontSize()
      Returns:
      the point size the build note asks to be drawn at, or NO_NOTES_FONT_SIZE when it did not ask for a particular size
    • hasBuildNotesFontSize

      public static boolean hasBuildNotesFontSize()
      Returns:
      true if the build note asks for a particular point size, otherwise false
    • getSplashTag

      @Nullable public static String getSplashTag()
      Returns the short tag this build sprays across the MegaMek logo on the splash art, such as the name of the edition it is celebrating.

      This is separate from getBuildNotes() so that the artwork and the menu can say different things, or so that a build can have one without the other.

      Returns:
      the splash tag, or null when this build has none, which is the case for every ordinary release
    • hasSplashTag

      public static boolean hasSplashTag()
      Returns:
      true if this build has a tag to spray across the splash art, otherwise false
    • getSplashTagColorName

      @Nullable public static String getSplashTagColorName()
      Returns the colour the splash tag asks to be sprayed in, as the plain name written in Version.properties rather than as a colour object, for the same reason as getBuildNotesColorName(): this class is also used well away from the user interface.
      Returns:
      the configured colour name, or null when the tag did not ask for a particular colour
    • getSplashTagRotation

      public static double getSplashTagRotation()
      Returns the angle, in degrees, the splash tag is sprayed at.

      Zero is level. A negative angle drops the left-hand end and lifts the right-hand end; a positive angle does the opposite. This follows the screen's own sense of rotation, where the vertical axis points downwards.

      Returns:
      the configured angle, or DEFAULT_SPLASH_TAG_ROTATION when the tag did not ask for one
    • getMajor

      public int getMajor()
    • setMajor

      public void setMajor(int major)
    • getMinor

      public int getMinor()
    • setMinor

      public void setMinor(int minor)
    • getPatch

      public int getPatch()
    • setPatch

      public void setPatch(int patch)
    • getRevision

      public int getRevision()
      Returns:
      the optional fourth version component, or NO_REVISION when this version has none, which is the case for every ordinary release
    • setRevision

      public void setRevision(int revision)
      Sets the optional fourth version component.

      A value at or below NO_REVISION is stored as NO_REVISION. Without that, a version built from malformed text such as 0.51.0.-1 would render as though it had no revision while still comparing as lower than, and unequal to, the release it claims to be.

      Parameters:
      revision - the optional fourth version component, or NO_REVISION for no revision
    • hasRevision

      public boolean hasRevision()
      Returns:
      true if this version carries a fourth component, as a point release such as 0.49.19.1 does, otherwise false
    • getExtra

      public String getExtra()
    • setExtra

      public void setExtra(@Nullable String extra)
    • isHigherThan

      public boolean isHigherThan(Version other)
      Use this method to determine if the version passed is less than this Version object.
      Parameters:
      other - The version we want to see if is less than this version
      Returns:
      true if checkVersion is less than this Version object
    • isLowerThan

      public boolean isLowerThan(Version other)
      Use this method to determine if this version is lower than the version passed
      Parameters:
      other - The version we want to see if it is higher than this version.
      Returns:
      true if this is lower than checkVersion
    • isBetween

      public boolean isBetween(String lower, String upper)
      Parameters:
      lower - the lower Version bound (exclusive)
      upper - the upper Version bound (exclusive)
      Returns:
      true if the version is between lower and upper versions, both exclusive
    • isBetween

      public boolean isBetween(Version lower, Version upper)
      Parameters:
      lower - the lower Version bound (exclusive)
      upper - the upper Version bound (exclusive)
      Returns:
      true is the version is between lower and upper versions, both exclusive
    • is

      public boolean is(String other)
      Parameters:
      other - The version we want to see if it is the same as this version.
      Returns:
      true if this is same version as the other
    • is

      public boolean is(Version other)
      Parameters:
      other - The version we want to see if it is the same as this version.
      Returns:
      true if this is same version as the other
    • compareTo

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

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

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

      public void writeToXML(PrintWriter pw, int indent)
    • toString

      public String toString()
      Overrides:
      toString in class Object