Package io.ocfl.api.model
Class VersionNum
- java.lang.Object
-
- io.ocfl.api.model.VersionNum
-
- All Implemented Interfaces:
Comparable<VersionNum>
public class VersionNum extends Object implements Comparable<VersionNum>
Represents an OCFL version number. It is able to handle zero-padded version numbers.
-
-
Field Summary
Fields Modifier and Type Field Description static VersionNum
V1
-
Constructor Summary
Constructors Constructor Description VersionNum(long versionNumber)
Creates a new VersionNum.VersionNum(long versionNumber, int zeroPaddingWidth)
Creates a new VersionNum
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description int
compareTo(VersionNum o)
boolean
equals(Object o)
static VersionNum
fromInt(int versionNumber)
Creates a new VersionNum from an integer.static VersionNum
fromString(String value)
Creates a new VersionNum from a version string in the format of "vN" where "N" is an integer greater than -1.long
getVersionNum()
int
getZeroPaddingWidth()
int
hashCode()
VersionNum
nextVersionNum()
Returns a new VersionNum that is one more than this.VersionNum
previousVersionNum()
Returns a new VersionNum that is one less than this.String
toString()
-
-
-
Field Detail
-
V1
public static final VersionNum V1
-
-
Constructor Detail
-
VersionNum
public VersionNum(long versionNumber)
Creates a new VersionNum. Zero-padding is not used.- Parameters:
versionNumber
- the version number, must be greater than -1
-
VersionNum
public VersionNum(long versionNumber, int zeroPaddingWidth)
Creates a new VersionNum- Parameters:
versionNumber
- the version number, must be greater than -1zeroPaddingWidth
- the width of zero-padding, or 0 if the version is not zero-padded
-
-
Method Detail
-
fromString
public static VersionNum fromString(String value)
Creates a new VersionNum from a version string in the format of "vN" where "N" is an integer greater than -1. Zero-padded values are supported.- Parameters:
value
- version string- Returns:
- version number
-
fromInt
public static VersionNum fromInt(int versionNumber)
Creates a new VersionNum from an integer.- Parameters:
versionNumber
- the version number, must be greater than -1- Returns:
- version number
-
nextVersionNum
public VersionNum nextVersionNum()
Returns a new VersionNum that is one more than this. If the version number is zero-padded, versions higher than the max number are now allowed.- Returns:
- a new VersionNum with an incremented version number
- Throws:
InvalidVersionException
- if the next version is higher than the max allowed value
-
previousVersionNum
public VersionNum previousVersionNum()
Returns a new VersionNum that is one less than this. Version numbers lower than 0 are not allowed.- Returns:
- a new VersionNum with a decremented version number
- Throws:
InvalidVersionException
- if the previous version is lower than 1
-
getZeroPaddingWidth
public int getZeroPaddingWidth()
- Returns:
- the zero-padding width, 0 when not padded
-
getVersionNum
public long getVersionNum()
- Returns:
- the numeric version number
-
compareTo
public int compareTo(VersionNum o)
- Specified by:
compareTo
in interfaceComparable<VersionNum>
-
-