Package nl.colorize.util
Class Version
java.lang.Object
nl.colorize.util.Version
- All Implemented Interfaces:
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 Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
Returns true ifversionString
represents a version number that can be represented by this class.int
Compares this version number toother
.int
Compares this version number toother
, considering only the first N digits.boolean
protected int
getDigit
(int position) Returns the digit at the specified position.int
hashCode()
boolean
boolean
isNewerThan
(Version other) boolean
isOlderThan
(Version other) boolean
static Version
Parses a version number from the specified version string.toString()
Returns the version string that is represented by this object.truncate
(int maxDigits) Returns a newVersion
instance that is a truncated version of this one.
-
Field Details
-
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
Compares this version number toother
. 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 interfaceComparable<Version>
- 1 if this version is newer than
-
compareTo
Compares this version number toother
, 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
- ifprecision
is 0 or less.
-
isAtLeast
-
isNewerThan
-
isOlderThan
-
truncate
Returns a newVersion
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
-
hashCode
public int hashCode() -
toString
Returns the version string that is represented by this object. -
parse
Parses a version number from the specified version string.- Throws:
IllegalArgumentException
- if the version string cannot be parsed.
-
canParse
Returns true ifversionString
represents a version number that can be represented by this class. In other words, this method indicates whetherparse(String)
will throw an exception if invoked withversionString
.
-