I have an application that communicates with the firmware of a device. As there are changes to the firmware, it is versioned with the format {major}.{minor}.{revision}[beta[{beta}]]. To give you a few examples, the current version is 0.4.7beta which will be followed by 0.4.7beta2 and occasionally 0.4.7, followed by 0.4.8beta. The versioning format of the firmware is unfortunately not under my control, so I can not change it.
I need a way of comparing firmwares with each other. Basically, I need a function
boolean isFirmwareNewer(String testFW, String baseFW);
What I did so far was to convert this format to a simple int. So 0.4.7beta2 will become 00040702 (2 digits for each level). The problem is, that
- My code is difficult to read (>40 lines and 3 methods)
- I am sure, there is a elegant solution to this (maybe using regex?)
- I want to have a wildcard
0.0.0which is newer by definition - This handles the beta versions incorrect (
0.4.7beta2is not newer than0.4.7). That is easy to account for (if (testFW.contains("beta")) testFWValue -= 100;, but it's not really elegant as well.
How do you guys do this normally (or how would you do it)?
If you want, I can attach the code I am currently working with, but as I said, it's >40 lines of code and not really readable (which is the reason why I am looking for a better way to do this).