Package craterdog.primitives
Class VersionString
- All Implemented Interfaces:
Atomic<VersionString>
,Sequential<Integer>
,Comparable<VersionString>
,Iterable<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 Summary
ConstructorsConstructorDescriptionVersionString(int... value)
This constructor creates a version number from an arbitrary list of version numbers.VersionString(String value)
This constructor creates a version number from a string containing the version number. -
Method Summary
Modifier and TypeMethodDescriptionint
compareTo(VersionString that)
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.static VersionString
getNextVersion(VersionString version)
This function returns the next version number in the series for the specified version.int
getSize()
Integer[]
toArray()
toString()
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
Methods inherited from interface craterdog.core.Sequential
isEmpty, iterator
-
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
This constructor creates a version number from a string containing the version number.- Parameters:
value
- A string containing the version number.
-
-
Method Details
-
toString
-
compareTo
- Specified by:
compareTo
in interfaceComparable<VersionString>
- Overrides:
compareTo
in classPrimitive<VersionString>
-
createIterator
- Specified by:
createIterator
in interfaceSequential<Integer>
-
getSize
public int getSize()- Specified by:
getSize
in interfaceSequential<Integer>
-
toArray
- Specified by:
toArray
in interfaceSequential<Integer>
-
getNextVersion
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
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.
-