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 n componants 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 a SNAPSHOT (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 see VersionComparator.

Immutability

The version is immutable, to create or modify a version, use the VersionBuilder API or shortcut methods in Versions.
Since:
1.0
Author:
Tony Chemit - chemit@codelutin.com
See Also:
VersionBuilder, VersionComparator, Serialized Form
  • Field Details

  • Constructor Details

    • Version

      protected Version​(java.util.List<Version.VersionComponant> componants, java.util.List<java.lang.String> componantSeparators, boolean snapshot)
  • Method Details

    • getComponants

      public java.util.List<Version.VersionComponant> 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

      public Version.VersionComponant getComponant​(int level)
    • 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
      Forbidden values are replaced by _ character.
      Returns:
      the java compilant string representation of the version
    • increments

      @Deprecated public Version increments()
      Deprecated.
      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.
      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.
      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.
      Creates 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 interface java.lang.Comparable<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
    • toString

      public java.lang.String toString()
      Overrides:
      toString in class java.lang.Object
    • equals

      public boolean equals​(java.lang.Object o)
      Overrides:
      equals in class java.lang.Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class java.lang.Object
    • getLastComponant

      protected Version.VersionComponant getLastComponant()