From a0a2c927b61359124b0c7e0c99301fb4a2a87a87 Mon Sep 17 00:00:00 2001 From: Damian Minkov Date: Wed, 21 Aug 2013 10:03:36 +0300 Subject: [PATCH] Adds comparison like numbers of nightly build id part of the version. --- .../impl/version/VersionImpl.java | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/src/net/java/sip/communicator/impl/version/VersionImpl.java b/src/net/java/sip/communicator/impl/version/VersionImpl.java index ff295467c..9117f77c3 100644 --- a/src/net/java/sip/communicator/impl/version/VersionImpl.java +++ b/src/net/java/sip/communicator/impl/version/VersionImpl.java @@ -206,9 +206,56 @@ public int compareTo(Version version) if(getVersionMinor() != version.getVersionMinor()) return getVersionMinor() - version.getVersionMinor(); + try + { + return compareNightlyBuildIDByComponents( + getNightlyBuildID(), version.getNightlyBuildID()); + } + catch(Throwable th) + { + // if parsing fails will continue with lexicographically compare + } + return getNightlyBuildID().compareTo(version.getNightlyBuildID()); } + /** + * As normally nightly.build.id is in the form of or + * . we will first try to compare them by splitting + * the id in components and compare them one by one asnumbers + * @param v1 the first version to compare + * @param v2 the second version to compare + * @return a negative integer, zero, or a positive integer as the first + * parameter v1 represents a version that is earlier, same, + * or more recent than the one referenced by the v2 parameter. + */ + private static int compareNightlyBuildIDByComponents(String v1, String v2) + { + String[] s1 = v1.split("\\."); + String[] s2 = v2.split("\\."); + + int len = Math.max(s1.length, s2.length); + for(int i = 0; i < len; i++) + { + int n1 = 0; + int n2 = 0; + + if(i < s1.length) + n1 = Integer.valueOf(s1[i]); + if(i < s2.length) + n2 = Integer.valueOf(s2[i]); + + if(n1 == n2) + continue; + else + return n1 - n2; + } + + // will happen if boths version has identical numbers in + // their components (even if one of them is longer, has more components) + return 0; + } + /** * Compares the version parameter to this version and returns true * if and only if both reference the same Jitsi version and