Package org.nuiton.version
Class Version
java.lang.Object
org.nuiton.version.Version
- All Implemented Interfaces:
java.io.Serializable,java.lang.Comparable<Version>
public class Version extends java.lang.Object implements java.lang.Comparable<Version>, java.io.Serializable
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:
VersionBuilder,VersionComparator, Serialized Form
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classVersion.NumberVersionComponantstatic classVersion.StringVersionComponantstatic interfaceVersion.VersionComponant<C extends java.lang.Comparable<C>,V extends Version.VersionComponant> -
Field Summary
Fields Modifier and Type Field Description protected java.util.List<Version.VersionComponant>componantsList of componants of the version.protected java.util.List<java.lang.String>componantSeparatorsList of separators of the version.static charDEFAULT_JOIN_COMPONANT_SEPARATORprotected booleansnapshotflag to define if version is a snapshot (if so a -SNAPSHOT is added at the end of the textual representation of the version).static java.lang.StringSNAPSHOT_SUFFIXSuffix of aSNAPSHOTversion in the text representation.protected java.lang.Stringversionstring represention of the version.protected static VersionComparatorVERSION_COMPARATORComparator of version used internaly to fulfill the compoarator contract.static VersionVZEROVersion V0. -
Constructor Summary
Constructors Modifier Constructor Description protectedVersion(java.util.List<Version.VersionComponant> componants, java.util.List<java.lang.String> componantSeparators, boolean snapshot) -
Method Summary
Modifier and Type Method Description booleanafter(Version o)booleanafterOrEquals(Version o)booleanbefore(Version o)booleanbeforeOrequals(Version o)intcompareTo(Version o)Versiondecrements(int componantPosition)Deprecated.useVersions.decrements(Version, int)insteadbooleanequals(java.lang.Object o)Version.VersionComponantgetComponant(int level)intgetComponantCount()java.util.List<Version.VersionComponant>getComponants()java.util.List<java.lang.String>getComponantSeparators()protected Version.VersionComponantgetLastComponant()intgetNumberComponant(int componantPosition)java.lang.StringgetTextComponant(int componantPosition)java.lang.StringgetValidName()Convert the string representation to a java identifier compliant.java.lang.StringgetVersion()inthashCode()Versionincrements()Deprecated.use insteadVersions.increments(Version)Versionincrements(char componantSeperator)Deprecated.use insteadVersions.increments(Version, char)Versionincrements(int componantPosition)Deprecated.use insteadVersions.increments(Version, int)booleanisSnapshot()java.lang.StringtoString()
-
Field Details
-
SNAPSHOT_SUFFIX
public static final java.lang.String SNAPSHOT_SUFFIXSuffix of aSNAPSHOTversion in the text representation.- See Also:
- Constant Field Values
-
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:
- Constant Field Values
-
componants
List of componants of the version. -
componantSeparators
protected final java.util.List<java.lang.String> componantSeparatorsList of separators of the version. -
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
protected transient java.lang.String versionstring represention of the version.
-
-
Constructor Details
-
Version
protected Version(java.util.List<Version.VersionComponant> componants, java.util.List<java.lang.String> componantSeparators, boolean snapshot)
-
-
Method Details
-
getComponants
-
getComponantSeparators
public java.util.List<java.lang.String> getComponantSeparators() -
isSnapshot
public boolean isSnapshot() -
getComponantCount
public int getComponantCount() -
getNumberComponant
public int getNumberComponant(int componantPosition) -
getTextComponant
public java.lang.String getTextComponant(int componantPosition) -
getComponant
-
getVersion
public java.lang.String getVersion()- Returns:
- the string represention value of the version
-
getValidName
public java.lang.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.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 interfacejava.lang.Comparable<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
public java.lang.String toString()- Overrides:
toStringin classjava.lang.Object
-
equals
public boolean equals(java.lang.Object o)- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()- Overrides:
hashCodein classjava.lang.Object
-
getLastComponant
-