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 Details

  • Constructor Details

    • 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 -1
      zeroPaddingWidth - the width of zero-padding, or 0 if the version is not zero-padded
  • Method Details

    • 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
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

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

      public int compareTo(VersionNum o)
      Specified by:
      compareTo in interface Comparable<VersionNum>