Class Versions


  • public class Versions
    extends Object
    Useful class around Version.

    Created on 8/23/14.

    Since:
    1.0
    Author:
    Tony Chemit - chemit@codelutin.com
    • Constructor Detail

      • Versions

        public Versions()
    • Method Detail

      • valueOf

        public static Version valueOf​(String version)
        Shortcut method to get a version from his string representation.
        Parameters:
        version - string representation of the version
        Returns:
        converted version from the string representation
      • equals

        public static boolean equals​(String version0,
                                     String version1)
        Tests if two versions are equals.
        Parameters:
        version0 - the first version
        version1 - the second version
        Returns:
        true if versions are equals, false otherwise.
      • smallerThan

        public static boolean smallerThan​(String version0,
                                          String version1)
        Tests if the first version is smaller than the second version.
        Parameters:
        version0 - the first version
        version1 - the second version
        Returns:
        true if version0 is before version1, false otherwise.
      • greaterThan

        public static boolean greaterThan​(String version0,
                                          String version1)
        Tests if the first version is greater than the second version.
        Parameters:
        version0 - the first version
        version1 - the second version
        Returns:
        true if version0 is after version1, false otherwise.
      • addSnapshot

        public static Version addSnapshot​(Version version)
        Create a version from the given one and set to it the snapshot state to true.
        Parameters:
        version - version to clone
        Returns:
        the cloned version with the snapshot state to true
        Throws:
        IllegalArgumentException - if snapshot state is already set to true on the given version.
      • removeSnapshot

        public static Version removeSnapshot​(Version version)
        Create a version from the given one and set to it the snapshot state to false.
        Parameters:
        version - version to clone
        Returns:
        the cloned version with the snapshot state to true
        Throws:
        IllegalArgumentException - if snapshot state is already set to false on the given version
      • extractVersion

        public static Version extractVersion​(Version version,
                                             int component)
        Create a new version containing a single component from a given version.
        Parameters:
        version - original version
        component - component index to extract
        Returns:
        new Version with a single component
      • extractVersion

        public static Version extractVersion​(Version version,
                                             int firstComponent,
                                             int lastComponent)
        Create a new version containing a sub set of component from a given version.
        Parameters:
        version - original version
        firstComponent - first component index
        lastComponent - last component index
        Returns:
        new Version with a components sub set
      • increments

        public static Version increments​(Version 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
        Parameters:
        version - FIXME
        Returns:
        the incremented version
      • increments

        public static Version increments​(Version version,
                                         char componantSeperator)
        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:
        version - FIXME
        componantSeperator - the componant separator to use the last componant is a classifier
        Returns:
        the incremented version
      • increments

        public static Version increments​(Version version,
                                         int componantPosition)
        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:
        version - FIXME
        componantPosition - position of the version componant to increment
        Returns:
        the incremented version
      • decrements

        public static Version decrements​(Version version,
                                         int componantPosition)
        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:
        version - FIXME
        componantPosition - position of the version componant to increment
        Returns:
        the decremented version