Class 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 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 Detail

      • SNAPSHOT_SUFFIX

        public static final String SNAPSHOT_SUFFIX
        Suffix of a SNAPSHOT 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
      • 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.
    • Method Detail

      • getComponantSeparators

        public List<String> getComponantSeparators()
      • isSnapshot

        public boolean isSnapshot()
      • getComponantCount

        public int getComponantCount()
      • getNumberComponant

        public int getNumberComponant​(int componantPosition)
      • getTextComponant

        public String getTextComponant​(int componantPosition)
      • 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
        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
      • 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
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object