Class Version
- All Implemented Interfaces:
Serializable, Comparable<Version>
A class to represent a version.
Replace previously org.nuiton.util.Version class.
Definition
A version is defined of ncomponants separated by componantSeparator.
Componants
Componants can be of two types:- Number componant: a strict positive integer value
- String componant: a sequence of characters which can't be either number nor componant separators
Componant separators
Componant separator are characters which can't be alphanumeric and can be empty character.
Componant separators are optional and componants will be detected as soon as a character changed from a numeric string sequence to a alpha (none numeric!) sequence.
For example, version 1a2 is composed of three componants: {code 1}, a and 3.
Snapshot flag
Additionnaly version can be qualifed as aSNAPSHOT (see below section about ordering).
Examples
0 (one componant 0) 0-SNAPSHOT (one componant 0 + SNAPSHOT flag) 1.0 (two componants 1,0) 1.1 (two componants 1,1) 1.1-alpha-1 (four componants 1,1,alpha,1) 1.1-beta (three componants 1,1,beta) 1.1-rc-1 (four componants 1,1,rc,1) 1.1-a (three componants 1,1,a) 1.1-a12-4.45_6432 (seven componants 1,1,a,12,4,45,643)
Ordering
A version is comparable, to have all the detail of order seeVersionComparator.
Immutability
The version is immutable, to create or modify a version, use theVersionBuilder API
or shortcut methods in Versions.- Since:
- 1.0
- Author:
- Tony Chemit - chemit@codelutin.com
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic classstatic interfaceVersion.VersionComponant<C extends Comparable<C>, V extends Version.VersionComponant> -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final List<Version.VersionComponant> List of componants of the version.List of separators of the version.static final charprotected final booleanflag to define if version is a snapshot (if so a -SNAPSHOT is added at the end of the textual representation of the version).static final StringSuffix of aSNAPSHOTversion in the text representation.protected Stringstring represention of the version.protected static final VersionComparatorComparator of version used internaly to fulfill the compoarator contract.static final VersionVersion V0. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedVersion(List<Version.VersionComponant> componants, List<String> componantSeparators, boolean snapshot) -
Method Summary
Modifier and TypeMethodDescriptionbooleanbooleanbooleanbooleanintdecrements(int componantPosition) Deprecated.booleangetComponant(int level) intprotected Version.VersionComponantintgetNumberComponant(int componantPosition) getTextComponant(int componantPosition) Convert the string representation to a java identifier compliant.inthashCode()Deprecated.use insteadVersions.increments(Version)increments(char componantSeperator) Deprecated.use insteadVersions.increments(Version, char)increments(int componantPosition) Deprecated.use insteadVersions.increments(Version, int)booleantoString()
-
Field Details
-
SNAPSHOT_SUFFIX
Suffix of aSNAPSHOTversion in the text representation.- See Also:
-
VZERO
Version V0. -
VERSION_COMPARATOR
Comparator of version used internaly to fulfill the compoarator contract. -
DEFAULT_JOIN_COMPONANT_SEPARATOR
public static final char DEFAULT_JOIN_COMPONANT_SEPARATOR- See Also:
-
componants
List of componants of the version. -
componantSeparators
-
snapshot
protected final boolean snapshotflag to define if version is a snapshot (if so a -SNAPSHOT is added at the end of the textual representation of the version). -
version
string represention of the version.
-
-
Constructor Details
-
Version
protected Version(List<Version.VersionComponant> componants, List<String> componantSeparators, boolean snapshot)
-
-
Method Details
-
getComponants
-
getComponantSeparators
-
isSnapshot
public boolean isSnapshot() -
getComponantCount
public int getComponantCount() -
getNumberComponant
public int getNumberComponant(int componantPosition) -
getTextComponant
-
getComponant
-
getVersion
- Returns:
- the string represention value of the version
-
getValidName
Convert the string representation to a java identifier compliant.- in java:
.is forbidden - in database (mysql, h2 ...):
.is forbidden
_character.- Returns:
- the java compilant string representation of the version
- in java:
-
increments
Deprecated.use insteadVersions.increments(Version)Creates a new version from this one incremented.If the last componant is a number, then just increments this number; otherwise add a new number componant with value 1.
Example:
- 1 → 2
- 1-a → 1-a.1
- Returns:
- the incremented version
-
increments
Deprecated.use insteadVersions.increments(Version, char)Creates a new version from this one incremented.If the last componant is a number, then just increments this number; otherwise add a new number componant with value 1.
Example:
- 1 → 2
- 1-a → 1-a.1
- Parameters:
componantSeperator- the componant separator to use the last componant is a classifier- Returns:
- the incremented version
-
increments
Deprecated.use insteadVersions.increments(Version, int)Creates a new version from this one with the number componant incremented at the given position.Note: Will fail if the componant at the required position is not a number.
- Parameters:
componantPosition- position of the version componant to increment- Returns:
- the incremented version
-
decrements
Deprecated.useVersions.decrements(Version, int)insteadCreates a new version from this one with the number componant decremented at the given position.Note: Will fail if the componant at the required position is not a number, or his value is 0.
- Parameters:
componantPosition- position of the version componant to increment- Returns:
- the decremented version
-
compareTo
- Specified by:
compareToin interfaceComparable<Version>
-
beforeOrequals
- Parameters:
o- the other version to test- Returns:
trueif current version is before or equals the given one
-
before
- Parameters:
o- the other version to test- Returns:
trueif current version is before the given one
-
afterOrEquals
- Parameters:
o- the other version to test- Returns:
trueif current version is after or equals the given one
-
after
- Parameters:
o- the other version to test- Returns:
trueif current version is after the given one
-
toString
-
equals
-
hashCode
-
getLastComponant
-
Versions.decrements(Version, int)instead