org.nuiton.util
Class Version

java.lang.Object
  extended by org.nuiton.util.Version
All Implemented Interfaces:
Serializable, Comparable<Version>

public class Version
extends Object
implements Comparable<Version>, Serializable

A class to represent an application version with possible classifier.

Replace previously org.nuiton.util.VersionNumber class.

Simple version number is defined like this :

 1.0.0 or 1
 

A version can be more complex, with a classifier like this :

 1.0.0-alpha-1, 1.0.0-beta-2, 1.0.0-rc-1
 

A classifier (alpha, beta, rc, ...) must be follwed by a classifier number.

Note :

- initial value is 0

- the equals order is defined on getVersion() property.

- the class is comparable, using the natural version order :

0 < 0.1 < 1 < 1.0 < 1.1-alpha-0 < 1.1-alpha-1 < 1.1-beta-0 <
        1.1-rc-1 < 1.1 

- the class is immutable, you should not instanciate directly a Version, but prefer use the factory static methods VersionUtil.valueOf(...) instead.

Since:
1.1.0
Author:
tchemit
See Also:
Serialized Form

Field Summary
protected  String classifier
          optional classifier
protected  Integer classifierNumber
          optional classifier number (if no classifier should be null)
protected  boolean classifierNumberAttached
          A flag to attach or not the classifier with his number.
protected  int[] numbers
          main numbers of the version
protected  boolean snapshot
          boolean to define if version is a snapshot (if so a -SNAPSHOT is added at the end of the textual representation of the version).
protected  String version
          representation textuelle de la version (celle utilisee dans le toString().
static Version VZERO
          Version V0
 
Constructor Summary
Version()
          Constructeur par defaut, definit la version par defaut, i.e 0
Version(int... numbers)
          Constructeur d'une version simple (sans classifier).
Version(String version)
          Constructeur de version a partir de sa representation textuelle
Version(String classifier, Integer classiferNumber, boolean snapshot, int... numbers)
          Constructeur d'une version (simple ou avec classifier)
Version(String classifier, Integer classiferNumber, int... numbers)
          Constructeur d'une version (simple ou avec classifier)
 
Method Summary
 boolean after(Version o)
           
 boolean before(Version o)
           
 int compareTo(Version o)
           
 boolean equals(Object obj)
           
 String getClassifier()
           
 Integer getClassifierNumber()
           
 int getNbComponents()
           
 int getNumber(int level)
           
 int[] getNumbers()
           
 String getValidName()
          Convertit la representation textuelle de la version en identifiant java valide : - en java : "." interdit - en mysql, h2 ... : "." interdit
 String getVersion()
           
 boolean hasClassifier()
           
 int hashCode()
           
 boolean isClassifierNumberAttached()
           
 boolean isSnapshot()
           
 void setClassifierNumberAttached(boolean classifierNumberAttached)
          Change the internal state classifierNumberAttached.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

VZERO

public static final Version VZERO
Version V0


classifier

protected final String classifier
optional classifier


classifierNumber

protected final Integer classifierNumber
optional classifier number (if no classifier should be null)


numbers

protected final int[] numbers
main numbers of the version


snapshot

protected final boolean snapshot
boolean to define if version is a snapshot (if so a -SNAPSHOT is added at the end of the textual representation of the version).

Since:
2.4.3

classifierNumberAttached

protected boolean classifierNumberAttached
A flag to attach or not the classifier with his number.

If set to false (the default cas then a - will be used to separe them).

Even if the Version class is immutable, this state can be change since it is only used to build the string representation of a version.

Notes that this state is NOT used to test equality of two version, neither for the comparaison.

Since:
2.4.3

version

protected transient String version
representation textuelle de la version (celle utilisee dans le toString().

Constructor Detail

Version

public Version()
Constructeur par defaut, definit la version par defaut, i.e 0


Version

public Version(int... numbers)
Constructeur d'une version simple (sans classifier).

Parameters:
numbers - les nombres de la version

Version

public Version(String classifier,
               Integer classiferNumber,
               int... numbers)
Constructeur d'une version (simple ou avec classifier)

Parameters:
classifier - le classifier (peut-ĂȘtre null)
classiferNumber - la version du classifier (doit etre null si le classifier est null)
numbers - les nombres de la version

Version

public Version(String classifier,
               Integer classiferNumber,
               boolean snapshot,
               int... numbers)
Constructeur d'une version (simple ou avec classifier)

Parameters:
classifier - le classifier (peut-ĂȘtre null)
classiferNumber - la version du classifier (doit etre null si le classifier est null)
snapshot - boolean pour renseigner le champ snapshot.
numbers - les nombres de la version
Since:
2.4.3

Version

public Version(String version)
        throws IllegalArgumentException
Constructeur de version a partir de sa representation textuelle

Parameters:
version - la represention de la version a instancier
Throws:
IllegalArgumentException - si la version n'est pas valide
Method Detail

getNumbers

public int[] getNumbers()

getClassifier

public String getClassifier()

hasClassifier

public boolean hasClassifier()

getClassifierNumber

public Integer getClassifierNumber()

isSnapshot

public boolean isSnapshot()

getNbComponents

public int getNbComponents()

isClassifierNumberAttached

public boolean isClassifierNumberAttached()

getNumber

public int getNumber(int level)

getVersion

public String getVersion()

getValidName

public String getValidName()
Convertit la representation textuelle de la version en identifiant java valide : - en java : "." interdit - en mysql, h2 ... : "." interdit

Returns:
la valeur ou les carateres interdits sont remplaces par '_'

setClassifierNumberAttached

public void setClassifierNumberAttached(boolean classifierNumberAttached)
Change the internal state classifierNumberAttached.

Parameters:
classifierNumberAttached - the new value of the classifierNumberAttached state

toString

public String toString()
Overrides:
toString in class Object

compareTo

public int compareTo(Version o)
Specified by:
compareTo in interface Comparable<Version>

before

public boolean before(Version o)
Parameters:
o - the other version to test
Returns:
true if current version is before 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

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object


Copyright © 2004-2012 CodeLutin. All Rights Reserved.