Class Version
- All Implemented Interfaces:
Serializable,Comparable<Version>
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 Summary
FieldsModifier and TypeFieldDescriptionstatic final doubleThe angle the splash tag is sprayed at when it does not ask for one: very slightly off level.static final intThe valuegetBuildNotesFontSize()reports when no point size is configured, meaning the build note is drawn at whatever size the rest of the menu uses.static final intThe valuegetRevision()reports when a version carries no fourth component, which is the case for every ordinary release. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintbooleanstatic StringReturns the free-text note this build was released with, such as a warning that it is a development build.static StringReturns the colour the build note asks to be drawn in, as the plain name written inVersion.propertiesrather than as a colour object, because this class is also used well away from the user interface.static intgetExtra()intgetMajor()intgetMinor()intgetPatch()intstatic StringReturns the short tag this build sprays across the MegaMek logo on the splash art, such as the name of the edition it is celebrating.static StringReturns the colour the splash tag asks to be sprayed in, as the plain name written inVersion.propertiesrather than as a colour object, for the same reason asgetBuildNotesColorName(): this class is also used well away from the user interface.static doubleReturns the angle, in degrees, the splash tag is sprayed at.static booleanstatic booleaninthashCode()booleanstatic booleanbooleanbooleanbooleanbooleanbooleanisHigherThan(Version other) Use this method to determine if the version passed is less than this Version object.booleanisLowerThan(Version other) Use this method to determine if this version is lower than the version passedvoidvoidsetMajor(int major) voidsetMinor(int minor) voidsetPatch(int patch) voidsetRevision(int revision) Sets the optional fourth version component.toString()voidwriteToXML(PrintWriter pw, int indent)
-
Field Details
-
NO_REVISION
public static final int NO_REVISIONThe valuegetRevision()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
Versionrestored 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-written0.51.0.0is understood as plain0.51.0, which is the same thing.- See Also:
-
DEFAULT_SPLASH_TAG_ROTATION
public static final double DEFAULT_SPLASH_TAG_ROTATIONThe 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_SIZEThe valuegetBuildNotesFontSize()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
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 Versionminor- Minor Versionpatch- Patch Version
-
Version
Sets the version. The resulting version has no revision component.- Parameters:
major- Major Versionminor- Minor Versionpatch- Patch Version
-
Version
Sets the version with Extra data. The resulting version has no revision component.- Parameters:
major- Major Versionminor- Minor Versionpatch- Patch Versionextra- 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 Versionminor- Minor Versionpatch- Patch Versionrevision- Optional fourth component of a point release, ornullwhen there is noneextra- Extra would be PR or nightly with git hash.
-
-
Method Details
-
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
nullwhen this build has none, which is the case for every ordinary release
-
hasBuildNotes
public static boolean hasBuildNotes()- Returns:
trueif this build was released with a note to show the player, otherwisefalse
-
getBuildNotesColorName
Returns the colour the build note asks to be drawn in, as the plain name written inVersion.propertiesrather than as a colour object, because this class is also used well away from the user interface.- Returns:
- the configured colour name, or
nullwhen 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_SIZEwhen it did not ask for a particular size
-
hasBuildNotesFontSize
public static boolean hasBuildNotesFontSize()- Returns:
trueif the build note asks for a particular point size, otherwisefalse
-
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
nullwhen this build has none, which is the case for every ordinary release
-
hasSplashTag
public static boolean hasSplashTag()- Returns:
trueif this build has a tag to spray across the splash art, otherwisefalse
-
getSplashTagColorName
Returns the colour the splash tag asks to be sprayed in, as the plain name written inVersion.propertiesrather than as a colour object, for the same reason asgetBuildNotesColorName(): this class is also used well away from the user interface.- Returns:
- the configured colour name, or
nullwhen 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_ROTATIONwhen 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_REVISIONwhen 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_REVISIONis stored asNO_REVISION. Without that, a version built from malformed text such as0.51.0.-1would 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, orNO_REVISIONfor no revision
-
hasRevision
public boolean hasRevision()- Returns:
trueif this version carries a fourth component, as a point release such as0.49.19.1does, otherwisefalse
-
getExtra
-
setExtra
-
isHigherThan
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
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
- 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
- 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
- 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
- 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
- Specified by:
compareToin interfaceComparable<Version>
-
equals
-
hashCode
public int hashCode() -
writeToXML
-
toString
-