Class Version

java.lang.Object
nl.colorize.util.Version
All Implemented Interfaces:
Comparable<Version>

public final class Version extends Object implements Comparable<Version>
Represents a version number with arbitrary precision. Examples of version numbers that can be represented by this class are "1.0" and "1.6.0b31".
  • Field Details

    • UNKNOWN

      public static final Version UNKNOWN
  • Method Details

    • getDigit

      protected int getDigit(int position)
      Returns the digit at the specified position. If no digit exists at that position this will return 0.
    • compareTo

      public int compareTo(Version other)
      Compares this version number to other. This will return one of the following values:
      • 1 if this version is newer than other
      • -1 if this version is older than other
      • 0 if both versions are equal
      Specified by:
      compareTo in interface Comparable<Version>
    • compareTo

      public int compareTo(Version other, int precision)
      Compares this version number to other, considering only the first N digits. For example, comparing "1.0.0" and "1.0.2" will return 1 with a precision of 3 digits, but 0 with a precision of 2 digits.
      Throws:
      IllegalArgumentException - if precision is 0 or less.
    • isAtLeast

      public boolean isAtLeast(Version other)
    • isNewerThan

      public boolean isNewerThan(Version other)
    • isOlderThan

      public boolean isOlderThan(Version other)
    • truncate

      public Version truncate(int maxDigits)
      Returns a new Version instance that is a truncated version of this one. For example, truncating the version number 1.2.3 to 2 digits will return 1.2. Truncating a version number that contains textual suffixes will remove those suffixes.
      Throws:
      IllegalArgumentException - if there is not at least 1 digit left.
    • isUnknown

      public boolean isUnknown()
    • equals

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

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

      public String toString()
      Returns the version string that is represented by this object.
      Overrides:
      toString in class Object
    • parse

      public static Version parse(String versionString)
      Parses a version number from the specified version string.
      Throws:
      IllegalArgumentException - if the version string cannot be parsed.
    • canParse

      public static boolean canParse(String versionString)
      Returns true if versionString represents a version number that can be represented by this class. In other words, this method indicates whether parse(String) will throw an exception if invoked with versionString.