Class Version
- java.lang.Object
-
- com.github.toolarium.common.version.AbstractVersion
-
- com.github.toolarium.common.version.Version
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Comparable<Version>
public class Version extends AbstractVersion implements java.lang.Comparable<Version>, java.io.Serializable
The version- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classVersion.VersionNumberElementDefines the version number element
-
Constructor Summary
Constructors Constructor Description Version(int majorNumber, int minorNumber, int patchNumber)ConstructorVersion(Version.VersionNumberElement major, Version.VersionNumberElement minor, Version.VersionNumberElement patch, VersionType versionType, java.lang.String sep)ConstructorVersion(java.lang.String version)ConstructorVersion(java.lang.String version, VersionType versionType, java.lang.String sep)ConstructorVersion(java.lang.String version, java.lang.String sep)Constructor
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.lang.String[]buildPatch(java.lang.String[] mainTokens, int idx, java.lang.String sep)Build the patchprotected intcompareMajorVersion(Version v)Compares the major version numberprotected intcompareMinorVersion(Version v)Compares the minor version numberprotected intcomparePatchVersion(Version v)Compares the patch version numberintcompareTo(Version o)protected intcompareValues(int v1, int v2)Compares two integer valuesprotected intcompareValues(java.lang.String v1, java.lang.String v2)Compares two integer valuesprotected Versioncreate(VersionType versionType, java.lang.String major, java.lang.String minor, java.lang.String patch)Prepare a versionVersionDiffdiff(Version version)Returns the greatest difference between 2 versions.VersionDiffdiff(java.lang.String version)Returns the greatest difference between 2 versions.Version.VersionNumberElementgetMajor()Get the major part of the version.intgetMajorNumber()Get the major part of the version.java.lang.StringgetMajorSuffix()Gets the additional minor suffixVersion.VersionNumberElementgetMinor()Get the minor part of the version.intgetMinorNumber()Get the minor part of the version.java.lang.StringgetMinorSuffix()Gets the additional minor suffixVersion.VersionNumberElementgetPatch()Get the patch part of the version.intgetPatchNumber()Get the patch part of the version.java.lang.StringgetPatchSuffix()Gets the additional patch suffixbooleanisEqualTo(Version version)Checks if the version equals another versionbooleanisEqualTo(java.lang.String version)Checks if the version equals another versionbooleanisGreaterThan(Version version)Checks if the version is greater than another versionbooleanisGreaterThan(java.lang.String version)Checks if the version is greater than another versionbooleanisGreaterThanOrEqualTo(Version version)Checks if the version is greater than or equal to another versionbooleanisGreaterThanOrEqualTo(java.lang.String version)Checks if the version is greater than or equal to another versionbooleanisLowerThan(Version version)Checks if the version is lower than another versionbooleanisLowerThan(java.lang.String version)Checks if the version is lower than another versionbooleanisLowerThanOrEqualTo(Version version)Checks if the version is lower than or equal to another versionbooleanisLowerThanOrEqualTo(java.lang.String version)Checks if the version is lower than or equal to another versionbooleanisStable()Determines if the current version is stable or not.VersionnextMajor()Get the next major versionVersionnextMinor()Get the next minor versionVersionnextPatch()Get the next patch versionVersionsetMajorNumber(java.lang.String majorNumber)Sets the major numberVersionsetMinorNumber(java.lang.String minorNumber)Sets the minor numberVersionsetPatchNumber(java.lang.String patchNumber)Sets the patch numberprotected Version.VersionNumberElementsplitNumberAndSuffix(java.lang.String[] data, int idx, java.lang.String errorMessageDetail)Splits the given data into number and suffixprotected static java.lang.StringtoVersion(int major, int minor, int patch, java.lang.String separator)Create a versionprotected static java.lang.StringtoVersion(Version.VersionNumberElement major, Version.VersionNumberElement minor, Version.VersionNumberElement patch, java.lang.String separator)Create a versionprotected Versionwith(java.lang.String major, java.lang.String minor, java.lang.String patch)Prepare a versionVersionwithClearedSuffix()Get the version with cleared suffixprotected VersionwithIncrement(int majorInc, int minorInc, int patchInc, boolean clearSuffix)Get version with incremented numbersVersionwithIncrementMajor()Get version with incremented major versionVersionwithIncrementMajor(int increment)Get version with incremented major versionVersionwithIncrementMinor()Get version with incremented minor versionVersionwithIncrementMinor(int increment)Get version with incremented minor versionVersionwithIncrementPatch()Get version with incremented patch versionVersionwithIncrementPatch(int increment)Get version with incremented patch version-
Methods inherited from class com.github.toolarium.common.version.AbstractVersion
equals, getOriginalVersion, getType, hashCode, parseInteger, prepareVersionString, selectVersionType, throwInvalidVersion, toString
-
-
-
-
Constructor Detail
-
Version
public Version(int majorNumber, int minorNumber, int patchNumber)Constructor- Parameters:
majorNumber- the major numberminorNumber- the minor numberpatchNumber- the patch number
-
Version
public Version(Version.VersionNumberElement major, Version.VersionNumberElement minor, Version.VersionNumberElement patch, VersionType versionType, java.lang.String sep)
Constructor- Parameters:
major- the major numberminor- the minor numberpatch- the patch numberversionType- the version typesep- the separator
-
Version
public Version(java.lang.String version)
Constructor- Parameters:
version- the version
-
Version
public Version(java.lang.String version, java.lang.String sep)Constructor- Parameters:
version- the versionsep- the separator
-
Version
public Version(java.lang.String version, VersionType versionType, java.lang.String sep)Constructor- Parameters:
version- the versionversionType- the version typesep- the separator
-
-
Method Detail
-
getMajor
public Version.VersionNumberElement getMajor()
Get the major part of the version. Example: for "1.2.3" = 1- Returns:
- the major part of the version
-
getMajorNumber
public int getMajorNumber()
Get the major part of the version. Example: for "1.2.3" = 1- Returns:
- the major part of the version
-
getMajorSuffix
public java.lang.String getMajorSuffix()
Gets the additional minor suffix- Returns:
- the additional minor suffix
-
setMajorNumber
public Version setMajorNumber(java.lang.String majorNumber)
Sets the major number- Parameters:
majorNumber- the major number to set- Returns:
- the new version
-
getMinor
public Version.VersionNumberElement getMinor()
Get the minor part of the version. Example: for "1.2.3" = 2- Returns:
- the minor part of the version
-
getMinorNumber
public int getMinorNumber()
Get the minor part of the version. Example: for "1.2.3" = 2- Returns:
- the minor part of the version
-
getMinorSuffix
public java.lang.String getMinorSuffix()
Gets the additional minor suffix- Returns:
- the additional minor suffix
-
setMinorNumber
public Version setMinorNumber(java.lang.String minorNumber)
Sets the minor number- Parameters:
minorNumber- the minor number to set- Returns:
- the new version
-
getPatch
public Version.VersionNumberElement getPatch()
Get the patch part of the version. Example: for "1.2.3" = 3- Returns:
- the patch part of the version
-
getPatchNumber
public int getPatchNumber()
Get the patch part of the version. Example: for "1.2.3" = 3- Returns:
- the patch part of the version
-
getPatchSuffix
public java.lang.String getPatchSuffix()
Gets the additional patch suffix- Returns:
- the additional patch suffix
-
setPatchNumber
public Version setPatchNumber(java.lang.String patchNumber)
Sets the patch number- Parameters:
patchNumber- the patch number to set- Returns:
- the new version
-
isGreaterThan
public boolean isGreaterThan(java.lang.String version)
Checks if the version is greater than another version- Parameters:
version- the version to compare- Returns:
- true if the current version is greater than the provided version
-
isGreaterThan
public boolean isGreaterThan(Version version)
Checks if the version is greater than another version- Parameters:
version- the version to compare- Returns:
- true if the current version is greater than the provided version
-
isGreaterThanOrEqualTo
public boolean isGreaterThanOrEqualTo(java.lang.String version)
Checks if the version is greater than or equal to another version- Parameters:
version- the version to compare- Returns:
- true if the current version is greater than or equal to the provided version
-
isGreaterThanOrEqualTo
public boolean isGreaterThanOrEqualTo(Version version)
Checks if the version is greater than or equal to another version- Parameters:
version- the version to compare- Returns:
- true if the current version is greater than or equal to the provided version
-
isLowerThan
public boolean isLowerThan(java.lang.String version)
Checks if the version is lower than another version- Parameters:
version- the version to compare- Returns:
- true if the current version is lower than the provided version
-
isLowerThan
public boolean isLowerThan(Version version)
Checks if the version is lower than another version- Parameters:
version- the version to compare- Returns:
- true if the current version is lower than the provided version
-
isLowerThanOrEqualTo
public boolean isLowerThanOrEqualTo(java.lang.String version)
Checks if the version is lower than or equal to another version- Parameters:
version- the version to compare- Returns:
- true if the current version is lower than or equal to the provided version
-
isLowerThanOrEqualTo
public boolean isLowerThanOrEqualTo(Version version)
Checks if the version is lower than or equal to another version- Parameters:
version- the version to compare- Returns:
- true if the current version is lower than or equal to the provided version
-
isEqualTo
public boolean isEqualTo(java.lang.String version)
Checks if the version equals another version- Parameters:
version- the version to compare- Returns:
- true if the current version equals the provided version
-
isEqualTo
public boolean isEqualTo(Version version)
Checks if the version equals another version- Parameters:
version- the version to compare- Returns:
- true if the current version equals the provided version
-
isStable
public boolean isStable()
Determines if the current version is stable or not. Stable version have a major version number strictly positive and no suffix tokens.- Returns:
- true if the current version is stable
-
diff
public VersionDiff diff(java.lang.String version)
Returns the greatest difference between 2 versions. For example, if the current version is "1.2.3" and compared version is "1.3.0", the biggest difference is the 'MINOR' number.- Parameters:
version- the version to compare- Returns:
- the greatest difference
-
diff
public VersionDiff diff(Version version)
Returns the greatest difference between 2 versions. For example, if the current version is "1.2.3" and compared version is "1.3.0", the biggest difference is the 'MINOR' number.- Parameters:
version- the version to compare- Returns:
- the greatest difference
-
withIncrementMajor
public Version withIncrementMajor()
Get version with incremented major version- Returns:
- the version
-
withIncrementMajor
public Version withIncrementMajor(int increment)
Get version with incremented major version- Parameters:
increment- the increment amount- Returns:
- the version
-
withIncrementMinor
public Version withIncrementMinor()
Get version with incremented minor version- Returns:
- the version
-
withIncrementMinor
public Version withIncrementMinor(int increment)
Get version with incremented minor version- Parameters:
increment- the increment amount- Returns:
- the version
-
withIncrementPatch
public Version withIncrementPatch()
Get version with incremented patch version- Returns:
- the version
-
withIncrementPatch
public Version withIncrementPatch(int increment)
Get version with incremented patch version- Parameters:
increment- the increment amount- Returns:
- the version
-
withClearedSuffix
public Version withClearedSuffix()
Get the version with cleared suffix- Returns:
- the version
-
nextMajor
public Version nextMajor()
Get the next major version- Returns:
- the next major version
-
nextMinor
public Version nextMinor()
Get the next minor version- Returns:
- the next minor version
-
nextPatch
public Version nextPatch()
Get the next patch version- Returns:
- the next patch version
-
compareTo
public int compareTo(Version o)
- Specified by:
compareToin interfacejava.lang.Comparable<Version>- See Also:
Comparable.compareTo(java.lang.Object)
-
withIncrement
protected Version withIncrement(int majorInc, int minorInc, int patchInc, boolean clearSuffix)
Get version with incremented numbers- Parameters:
majorInc- the major incrementminorInc- the minor incrementpatchInc- the patch incrementclearSuffix- true to clear the suffix- Returns:
- the version
-
with
protected Version with(java.lang.String major, java.lang.String minor, java.lang.String patch)
Prepare a version- Parameters:
major- the majorminor- the minorpatch- the patch- Returns:
- the version
-
create
protected Version create(VersionType versionType, java.lang.String major, java.lang.String minor, java.lang.String patch)
Prepare a version- Parameters:
versionType- the version typemajor- the majorminor- the minorpatch- the patch- Returns:
- the version
-
compareMajorVersion
protected int compareMajorVersion(Version v)
Compares the major version number- Parameters:
v- the version to compare- Returns:
- 0< if the object is less; 0 if the objects are equal; >0 if the object is bigger
-
compareMinorVersion
protected int compareMinorVersion(Version v)
Compares the minor version number- Parameters:
v- the version to compare- Returns:
- 0< if the object is less; 0 if the objects are equal; >0 if the object is bigger
-
comparePatchVersion
protected int comparePatchVersion(Version v)
Compares the patch version number- Parameters:
v- the version to compare- Returns:
- 0< if the object is less; 0 if the objects are equal; >0 if the object is bigger
-
compareValues
protected int compareValues(int v1, int v2)Compares two integer values- Parameters:
v1- the version to comparev2- the version to compare- Returns:
- 0< if the object is less; 0 if the objects are equal; >0 if the object is bigger
-
compareValues
protected int compareValues(java.lang.String v1, java.lang.String v2)Compares two integer values- Parameters:
v1- the version to comparev2- the version to compare- Returns:
- 0< if the object is less; 0 if the objects are equal; >0 if the object is bigger
-
splitNumberAndSuffix
protected Version.VersionNumberElement splitNumberAndSuffix(java.lang.String[] data, int idx, java.lang.String errorMessageDetail)
Splits the given data into number and suffix- Parameters:
data- the data to split upidx- the indexerrorMessageDetail- the error message detail- Returns:
- the splitted data
-
buildPatch
protected java.lang.String[] buildPatch(java.lang.String[] mainTokens, int idx, java.lang.String sep)Build the patch- Parameters:
mainTokens- the main tokensidx- the indexsep- the separator- Returns:
- the main tokens
-
toVersion
protected static java.lang.String toVersion(int major, int minor, int patch, java.lang.String separator)Create a version- Parameters:
major- the major numberminor- the minor numberpatch- the patch numberseparator- the separator- Returns:
- the version string
-
toVersion
protected static java.lang.String toVersion(Version.VersionNumberElement major, Version.VersionNumberElement minor, Version.VersionNumberElement patch, java.lang.String separator)
Create a version- Parameters:
major- the major numberminor- the minor numberpatch- the patch numberseparator- the separator- Returns:
- the version string
-
-