Class Versions

java.lang.Object
org.nuiton.version.Versions

public class Versions
extends java.lang.Object
Useful class around Version.

Created on 8/23/14.

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

    Constructors 
    Constructor Description
    Versions()  
  • Method Summary

    Modifier and Type Method Description
    static Version addSnapshot​(Version version)
    Create a version from the given one and set to it the snapshot state to true.
    static Version decrements​(Version version, int componantPosition)
    Creates a new version from this one with the number componant decremented at the given position.
    static boolean equals​(java.lang.String version0, java.lang.String version1)
    Tests if two versions are equals.
    static Version extractVersion​(Version version, int component)
    Create a new version containing a single component from a given version.
    static Version extractVersion​(Version version, int firstComponent, int lastComponent)
    Create a new version containing a sub set of component from a given version.
    static boolean greaterThan​(java.lang.String version0, java.lang.String version1)
    Tests if the first version is greater than the second version.
    static Version increments​(Version version)
    Creates a new version from this one incremented.
    static Version increments​(Version version, char componantSeperator)
    Creates a new version from this one incremented.
    static Version increments​(Version version, int componantPosition)
    Creates a new version from this one with the number componant incremented at the given position.
    static Version removeSnapshot​(Version version)
    Create a version from the given one and set to it the snapshot state to false.
    static boolean smallerThan​(java.lang.String version0, java.lang.String version1)
    Tests if the first version is smaller than the second version.
    static Version valueOf​(java.lang.String version)
    Shortcut method to get a version from his string representation.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

  • Method Details

    • valueOf

      public static Version valueOf​(java.lang.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​(java.lang.String version0, java.lang.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​(java.lang.String version0, java.lang.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​(java.lang.String version0, java.lang.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:
      java.lang.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:
      java.lang.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