Package com.helger.commons.version
Class Version
- java.lang.Object
-
- com.helger.commons.version.Version
-
- All Implemented Interfaces:
IComparable<Version>,Comparable<Version>
@Immutable public final class Version extends Object implements IComparable<Version>
This class represents a single version object. It supports 4 elements: major version (integer), minor version (integer), micro version (integer) and a qualifier (string).- Author:
- Philip Helger
-
-
Field Summary
Fields Modifier and Type Field Description static booleanDEFAULT_PRINT_ZERO_ELEMENTSDefault value for printing zero elements in getAsStringstatic VersionDEFAULT_VERSIONstatic StringDEFAULT_VERSION_STRINGdefault version if nothing is specified.
-
Constructor Summary
Constructors Constructor Description Version(int nMajor)Create a new version with major version only.Version(int nMajor, int nMinor)Create a new version with major and minor version only.Version(int nMajor, int nMinor, int nMicro)Create a new version with major, minor and micro version number.Version(int nMajor, int nMinor, int nMicro, String sQualifier)Create a new version with 3 integer values and a qualifier.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description intcompareTo(Version rhs)Compares two Version objects.booleanequals(Object o)StringgetAsString()StringgetAsString(boolean bPrintZeroElements)Get the string representation of the version number.StringgetAsString(boolean bPrintZeroElements, boolean bPrintAtLeastMajorAndMinor)Get the string representation of the version number.StringgetAsStringMajorMinor()Get the string representation of the version number but only major and minor version number.StringgetAsStringMajorMinorMicro()Get the string representation of the version number but only major and minor and micro version number.intgetMajor()intgetMicro()intgetMinor()StringgetQualifier()inthashCode()booleanhasQualifier()static Versionparse(String sVersionString)Construct a version object from a string.
EBNF:
version ::= major( '.' minor ( '.' micro ( ( '.' | '-' ) qualifier )?static VersionparseDotOnly(String sVersionString)Construct a version object from a string.
EBNF:
version ::= major( '.' minor ( '.' micro ( '.' qualifier )?StringtoString()
-
-
-
Field Detail
-
DEFAULT_VERSION_STRING
public static final String DEFAULT_VERSION_STRING
default version if nothing is specified.- See Also:
- Constant Field Values
-
DEFAULT_VERSION
public static final Version DEFAULT_VERSION
-
DEFAULT_PRINT_ZERO_ELEMENTS
public static final boolean DEFAULT_PRINT_ZERO_ELEMENTS
Default value for printing zero elements in getAsString- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Version
public Version(@Nonnegative int nMajor)
Create a new version with major version only.- Parameters:
nMajor- major version- Throws:
IllegalArgumentException- if the parameter is < 0
-
Version
public Version(@Nonnegative int nMajor, @Nonnegative int nMinor)
Create a new version with major and minor version only.- Parameters:
nMajor- major versionnMinor- minor version- Throws:
IllegalArgumentException- if any of the parameters is < 0
-
Version
public Version(@Nonnegative int nMajor, @Nonnegative int nMinor, @Nonnegative int nMicro)
Create a new version with major, minor and micro version number. The qualifier remains null.- Parameters:
nMajor- major versionnMinor- minor versionnMicro- micro version- Throws:
IllegalArgumentException- if any of the parameters is < 0
-
Version
public Version(@Nonnegative int nMajor, @Nonnegative int nMinor, @Nonnegative int nMicro, @Nullable String sQualifier)
Create a new version with 3 integer values and a qualifier.- Parameters:
nMajor- major versionnMinor- minor versionnMicro- micro versionsQualifier- the version qualifier - may be null. If a qualifier is supplied, it may neither contain the "." or the "," character since they are used to determine the fields of a version and to separate 2 versions in a VersionRange.- Throws:
IllegalArgumentException- if any of the numeric parameters is < 0 or if the qualifier contains a forbidden character
-
-
Method Detail
-
getMajor
@Nonnegative public int getMajor()
-
getMinor
@Nonnegative public int getMinor()
-
getMicro
@Nonnegative public int getMicro()
-
hasQualifier
public boolean hasQualifier()
-
compareTo
public int compareTo(@Nonnull Version rhs)
Compares two Version objects.- Specified by:
compareToin interfaceComparable<Version>- Parameters:
rhs- the version to compare to- Returns:
- < 0 if this is less than rhs; > 0 if this is greater than rhs, and 0 if they are equal.
- Throws:
IllegalArgumentException- if the parameter is null
-
getAsString
@Nonnull public String getAsString(boolean bPrintZeroElements)
Get the string representation of the version number.- Parameters:
bPrintZeroElements- Iftruethan trailing zeroes are printed, otherwise printed zeroes are not printed.- Returns:
- Never
null.
-
getAsString
@Nonnull public String getAsString(boolean bPrintZeroElements, boolean bPrintAtLeastMajorAndMinor)
Get the string representation of the version number.- Parameters:
bPrintZeroElements- Iftruethan trailing zeroes are printed, otherwise printed zeroes are not printed.bPrintAtLeastMajorAndMinor-trueif major and minor part should always be printed, independent of their value- Returns:
- Never
null.
-
getAsStringMajorMinor
@Nonnull @Nonempty public String getAsStringMajorMinor()
Get the string representation of the version number but only major and minor version number.- Returns:
- Never
null.
-
getAsStringMajorMinorMicro
@Nonnull @Nonempty public String getAsStringMajorMinorMicro()
Get the string representation of the version number but only major and minor and micro version number.- Returns:
- Never
null.
-
parse
@Nonnull public static Version parse(@Nullable String sVersionString)
Construct a version object from a string.
EBNF:
version ::= major( '.' minor ( '.' micro ( ( '.' | '-' ) qualifier )? )? )?
major ::= number
minor ::= number
micro ::= number
qualifier ::= .+- Parameters:
sVersionString- the version string to be interpreted as a version- Returns:
- The parsed
Versionobject. - Throws:
IllegalArgumentException- if any of the parameters is < 0
-
parseDotOnly
@Nonnull public static Version parseDotOnly(@Nullable String sVersionString)
Construct a version object from a string.
EBNF:
version ::= major( '.' minor ( '.' micro ( '.' qualifier )? )? )?
major ::= number
minor ::= number
micro ::= number
qualifier ::= .+- Parameters:
sVersionString- the version string to be interpreted as a version- Returns:
- The parsed
Versionobject. - Throws:
IllegalArgumentException- if any of the parameters is < 0- Since:
- v10.0.1
-
-