Package org.nuiton.version
Class Version
- java.lang.Object
-
- org.nuiton.version.Version
-
- All Implemented Interfaces:
Serializable
,Comparable<Version>
public class Version extends Object implements Comparable<Version>, Serializable
A class to represent a version.
Replace previously
org.nuiton.util.Version
class.Definition
A version is defined of ncomponants
separated bycomponantSeparator
.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
and3
.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 inVersions
.- Since:
- 1.0
- Author:
- Tony Chemit - chemit@codelutin.com
- See Also:
VersionBuilder
,VersionComparator
, Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Version.NumberVersionComponant
static class
Version.StringVersionComponant
static interface
Version.VersionComponant<C extends Comparable<C>,V extends Version.VersionComponant>
-
Field Summary
Fields Modifier and Type Field Description protected List<Version.VersionComponant>
componants
List of componants of the version.protected List<String>
componantSeparators
List of separators of the version.static char
DEFAULT_JOIN_COMPONANT_SEPARATOR
protected boolean
snapshot
flag to define if version is a snapshot (if so a -SNAPSHOT is added at the end of the textual representation of the version).static String
SNAPSHOT_SUFFIX
Suffix of aSNAPSHOT
version in the text representation.protected String
version
string represention of the version.protected static VersionComparator
VERSION_COMPARATOR
Comparator of version used internaly to fulfill the compoarator contract.static Version
VZERO
Version V0.
-
Constructor Summary
Constructors Modifier Constructor Description protected
Version(List<Version.VersionComponant> componants, List<String> componantSeparators, boolean snapshot)
-
Method Summary
-
-
-
Field Detail
-
SNAPSHOT_SUFFIX
public static final String SNAPSHOT_SUFFIX
Suffix of aSNAPSHOT
version in the text representation.- See Also:
- Constant Field Values
-
VZERO
public static final Version VZERO
Version V0.
-
VERSION_COMPARATOR
protected static final VersionComparator 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:
- Constant Field Values
-
componants
protected final List<Version.VersionComponant> componants
List of componants of the version.
-
componantSeparators
protected final List<String> componantSeparators
List of separators of the version.
-
snapshot
protected final boolean snapshot
flag to define if version is a snapshot (if so a -SNAPSHOT is added at the end of the textual representation of the version).
-
version
protected transient String version
string represention of the version.
-
-
Constructor Detail
-
Version
protected Version(List<Version.VersionComponant> componants, List<String> componantSeparators, boolean snapshot)
-
-
Method Detail
-
getComponants
public List<Version.VersionComponant> getComponants()
-
isSnapshot
public boolean isSnapshot()
-
getComponantCount
public int getComponantCount()
-
getNumberComponant
public int getNumberComponant(int componantPosition)
-
getTextComponant
public String getTextComponant(int componantPosition)
-
getComponant
public Version.VersionComponant getComponant(int level)
-
getVersion
public String getVersion()
- Returns:
- the string represention value of the version
-
getValidName
public String 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 public Version 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 public Version increments(char componantSeperator)
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 public Version increments(int componantPosition)
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 public Version decrements(int componantPosition)
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
public int compareTo(Version o)
- Specified by:
compareTo
in interfaceComparable<Version>
-
beforeOrequals
public boolean beforeOrequals(Version o)
- Parameters:
o
- the other version to test- Returns:
true
if current version is before or equals the given one
-
before
public boolean before(Version o)
- Parameters:
o
- the other version to test- Returns:
true
if current version is before the given one
-
afterOrEquals
public boolean afterOrEquals(Version o)
- Parameters:
o
- the other version to test- Returns:
true
if current version is after or equals the given one
-
after
public boolean after(Version o)
- Parameters:
o
- the other version to test- Returns:
true
if current version is after the given one
-
getLastComponant
protected Version.VersionComponant getLastComponant()
-
-