Class VersionString

All Implemented Interfaces:
Atomic<VersionString>, Sequential<Integer>, Comparable<VersionString>, Iterable<Integer>

public final class VersionString extends Primitive<VersionString> implements Sequential<Integer>
This class defines a primitive type that captures a version string. Version numbers use dot notation and can be arbitrarily deep (e.g. 1, 1.3, 24.7.5, etc.). A version number can never have a zero in it (e.g. 0.3, 1.0, 4.0.7, etc.).
Author:
Derk Norton
  • Constructor Details

    • VersionString

      public VersionString(int... value)
      This constructor creates a version number from an arbitrary list of version numbers.
      Parameters:
      value - The list of version numbers (can't be empty and each must be greater than zero).
    • VersionString

      public VersionString(String value)
      This constructor creates a version number from a string containing the version number.
      Parameters:
      value - A string containing the version number.
  • Method Details

    • toString

      public String toString()
      Overrides:
      toString in class Object
    • compareTo

      public int compareTo(VersionString that)
      Specified by:
      compareTo in interface Comparable<VersionString>
      Overrides:
      compareTo in class Primitive<VersionString>
    • createIterator

      public Iterator<Integer> createIterator()
      Specified by:
      createIterator in interface Sequential<Integer>
    • getSize

      public int getSize()
      Specified by:
      getSize in interface Sequential<Integer>
    • toArray

      public Integer[] toArray()
      Specified by:
      toArray in interface Sequential<Integer>
    • getNextVersion

      public static VersionString getNextVersion(VersionString version)
      This function returns the next version number in the series for the specified version. If the specified version is "1", the next version would be "2". If the specified version is "2.5.7", the next version would be "2.5.8".
      Parameters:
      version - The current version.
      Returns:
      The next version in the series.
    • getNewVersion

      public static VersionString getNewVersion(VersionString version, int depth)
      This method returns a new version number in the series by incrementing the version at the specified depth and truncating the rest of the version numbers. If the current version is "2.5.7" and the depth is 2, the next version would be "2.6". If the current version is "1.22" and the depth is 3, the next version would be "1.22.1".
      Parameters:
      version - The current version.
      depth - The depth of the version number to be incremented.
      Returns:
      The new version number.