Skip to content
This repository has been archived by the owner on Jul 4, 2022. It is now read-only.

Utils Version Parser

Nico edited this page Sep 17, 2020 · 9 revisions

Versions utility

SimplixCore offers a class called Version for comparing version strings. This is mainly used by the builtin automatic update checker.

Usage

Parsing

SimplixCore is able to parse standard sequence version strings like "v#.#.#" or "#.#.#" with a maximum of three number levels (major, minor and patch values).

Version version = Version.parse("1.2.3");

If you are using a different versioning scheme, you can provide your own regular expression for parsing your version strings.

Version version = Version.parse("^(\\d+\\.)?(\\d+\\.)?(\\d+\\.)?(\\*|\\d+)$", "1.2.3.4");

Comparing

The Version class is implementing Comparable<Version> so it can be used in many ways for comparing versions. This class is also providing simple newerThen and olderThen methods to directly compare two versions.

Version v1 = Version.parse("1.2.3");
Version v2 = Version.parse("1.4");

if (v1.olderThen(v2)) {
  // Expected since 1.2.3 is older then 1.4
}
if (v2.newerThen(v1)) {
  // Expected since 1.4 is newer then 1.2.3
}

Restrictions

You can only compare versions against each other that are using the same versioning scheme. Otherwise an IllegalArgumentException will occur.