Package com.helger.base.version
Class Version
java.lang.Object
com.helger.base.version.Version
- All Implemented Interfaces:
IComparable<Version>,Comparable<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 -
Constructor Summary
ConstructorsConstructorDescriptionVersion(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.Create a new version with 3 integer values and a qualifier. -
Method Summary
Modifier and TypeMethodDescriptionintCompares two Version objects.boolean@NonNull StringGet the string representation of the version number using the default setting for printing zero elements.@NonNull StringgetAsString(boolean bPrintZeroElements) Get the string representation of the version number.@NonNull StringgetAsString(boolean bPrintZeroElements, boolean bPrintAtLeastMajorAndMinor) Get the string representation of the version number.@NonNull @Nonempty StringGet the string representation of the version number but only major and minor version number.@NonNull @Nonempty StringGet the string representation of the version number but only major and minor and micro version number.final intgetMajor()final intgetMicro()final intgetMinor()final @Nullable StringinthashCode()final booleanstatic @NonNull VersionConstruct a version object from a string.
EBNF:
version ::= major( '.' minor ( '.' micro ( ( '.' | '-' ) qualifier )?static @NonNull VersionparseDotOnly(@Nullable String sVersionString) Construct a version object from a string.
EBNF:
version ::= major( '.' minor ( '.' micro ( '.' qualifier )?toString()
-
Field Details
-
DEFAULT_VERSION_STRING
default version if nothing is specified.- See Also:
-
DEFAULT_VERSION
-
DEFAULT_PRINT_ZERO_ELEMENTS
public static final boolean DEFAULT_PRINT_ZERO_ELEMENTSDefault value for printing zero elements in getAsString- See Also:
-
-
Constructor Details
-
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 Details
-
getMajor
@Nonnegative public final int getMajor()- Returns:
- The major version number. Always ≥ 0.
-
getMinor
@Nonnegative public final int getMinor()- Returns:
- The minor version number. Always ≥ 0.
-
getMicro
@Nonnegative public final int getMicro()- Returns:
- The micro version number. Always ≥ 0.
-
getQualifier
- Returns:
- The version qualifier string. May be
null.
-
hasQualifier
public final boolean hasQualifier()- Returns:
trueif a qualifier is present,falseotherwise.
-
compareTo
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
Get the string representation of the version number using the default setting for printing zero elements.- Returns:
- Never
null.
-
getAsString
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
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
Get the string representation of the version number but only major and minor version number.- Returns:
- Never
null.
-
getAsStringMajorMinorMicro
Get the string representation of the version number but only major and minor and micro version number.- Returns:
- Never
null.
-
equals
-
hashCode
public int hashCode() -
toString
-
parse
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
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
-