From a101d74da6f4f4ea44a29885d55bfe21c7bd5377 Mon Sep 17 00:00:00 2001 From: Dave Parker Date: Wed, 1 Nov 2006 09:32:48 +0000 Subject: [PATCH] Added facility to compare version strings. git-svn-id: https://www.prismmodelchecker.org/svn/prism/prism/trunk@93 bbc10eb1-c90d-0410-af57-cb519fbb1720 --- prism/src/prism/Prism.java | 70 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/prism/src/prism/Prism.java b/prism/src/prism/Prism.java index 9bdc1ca7..431ade4a 100644 --- a/prism/src/prism/Prism.java +++ b/prism/src/prism/Prism.java @@ -450,6 +450,76 @@ public class Prism implements PrismSettingsListener } } + // Compare two version numbers of PRISM (strings) + // Returns: 1 if v1>v2, -1 if v1 s2) ? 1 : -1; + } + else return -1; + } + if (ss2[i].matches("beta.*")) return 1; + // 2 < 2.1, etc. + if (ss1[i].equals("")) { if (ss2[i].equals("")) return 0; else return -1; } + if (ss2[i].equals("")) return 1; + // 2.1 < 2.1.dev, etc. + if (ss1[i].matches("dev.*")) { + if (ss2[i].matches("dev.*")) { + // 2.1.dev < 2.1.dev2 < 2.1.dev3, etc. + try { if (ss1[i].length() == 3) s1 = 0; else s1 = Integer.parseInt(ss1[i].substring(3)); } catch (NumberFormatException e) { return 0; } + try { if (ss2[i].length() == 3) s2 = 0; else s2 = Integer.parseInt(ss2[i].substring(3)); } catch (NumberFormatException e) { return 0; } + if (s1 == s2) return 0; else return (s1 > s2) ? 1 : -1; + } + else return -1; + } + if (ss2[i].matches("dev.*")) return 1; + // See if strings are integers + try { s1num = true; s1 = Integer.parseInt(ss1[i]); } catch (NumberFormatException e) { s1num = false; } + try { s2num = true; s2 = Integer.parseInt(ss2[i]); } catch (NumberFormatException e) { s2num = false; } + // 2.5 < 3.1, etc. + if (s1num && s2num) { + if (s1 < s2) return -1; + if (s1 > s2) return 1; + if (s1 == s2) continue; + } + } + + return 0; + } + // initialise public void initialise() throws PrismException