What is it?
it is an auxiliary framework to parse and validate some version information.
How it works?
It has two main classes
- com.igormaznitsa.commons.version.Version to parse string representation of version, usual format is XXX-NNN.NNN.NN-ZZZZ
- com.igormaznitsa.commons.version.VersionValidator to validate version for some logical condition
Usage of version
Version parsed = new Version("idea-1.04.0015-alpha");
Version fullyFromScratch = new Version("idea",new long[]{1,4,15},"alpha");
Version onlyNumber = new Version(1,4,15);
Version changed = onlyNumber.changePrefix("idea").changePostfix("alpha").changeNumeric(0,1,2);
Usage of version validator
Validator supports AND (,) and OR (;) logical operators, where AND has higher priority.
Allowed conditions:
- = equals
- < less
- > great
- >= great or equals
- <= less or equals
- if there is no any operator then it will be recognized as =
VersionValidator validator = new VersionValidator(">idea-1.1.0,<idea-3.0.2;1.1.0,3.0.2;!=0.0.1-dev");
if (validator.isValid(someVersion)){
System.out.println("Version valid");
}
Also it is possible to implement own expression parser to parse expressions.
NB! Wrong written conditional operator will be recognized as part of the version prefix! Be careful for typo like =>
!