/** * Compares two version strings. * @param v1 The first version string. * @param v2 The second version string. * @return a negative integer, zero, or a positive integer as the * first argument is less than, equal to, or greater than the * second. */ public static int compare(final String v1, final String v2) { final String[] t1 = splitDots(v1), t2 = splitDots(v2); final int count = Math.min(t1.length, t2.length); for (int t=0; t<count; t++) { final int c = compareToken(t1[t], t2[t]); if (c != 0) return c; } if (t1.length == t2.length) return 0; // NB: Token count differs. More tokens means newer -- e.g. 1.5 < 1.5.1. return t1.length < t2.length ? -1 : 1; }
/** * Compares two version strings. * @param v1 The first version string. * @param v2 The second version string. * @return a negative integer, zero, or a positive integer as the * first argument is less than, equal to, or greater than the * second. */ public static int compare(final String v1, final String v2) { final String[] t1 = splitDots(v1), t2 = splitDots(v2); final int count = Math.min(t1.length, t2.length); for (int t=0; t<count; t++) { final int c = compareToken(t1[t], t2[t]); if (c != 0) return c; } if (t1.length == t2.length) return 0; // NB: Token count differs. More tokens means newer -- e.g. 1.5 < 1.5.1. return t1.length < t2.length ? -1 : 1; }