/** * Return true if v1 and v2 are equals. * * 1.2.0 et 1.2 ne sont pas egaux * * @param v1 version * @param v2 version * * @return {@code true} if v1 == v2 */ public static boolean versionEquals(String v1, String v2) { if (v1 == null || v2 == null) { return false; } return normalizeVersion(v1).equals(normalizeVersion(v2)); }
/** * Extract extension version from extension id. If id contains no version * this method return '0.0'. * * @param id id like MonExtension[3.0] * @return extension version. Example '3.0' */ static public String computeVersion(String id) { int b = id.lastIndexOf("["); int e = id.lastIndexOf("]"); String result = null; if (b != -1 && e != -1) { result = id.substring(b+1, e); } result = WikittyUtil.normalizeVersion(result); return result; }
/** * Return true if v1 greater than v2. * * @param v1 version * @param v2 version * @return {@code true} if v1 > v2 */ public static boolean versionGreaterThan(String v1, String v2) { if (v1 != null && v2 == null) { return true; } if (v1 == null) { return false; } String[] v1s = normalizeVersion(v1).split("\\."); String[] v2s = normalizeVersion(v2).split("\\."); int minlen = Math.min(v1s.length, v2s.length); for (int i = 0; i < minlen; i++) { if (!v1s[i].equals(v2s[i])) { return Integer.parseInt(v1s[i]) > Integer.parseInt(v2s[i]); } } // si on est ici c que tout les nombres sont v1[i] = v2[i] return v1s.length > v2s.length; }
public WikittyExtension(String name, String version, Map<String, String> tagValues, List<String> requires, LinkedHashMap<String, FieldType> fields) { if (version == null) { throw new IllegalArgumentException("Version must not be null"); } setName(name); this.version = WikittyUtil.normalizeVersion(version); setRequires(requires); setTagValues(tagValues); if (fields != null) { addField(fields); } }
/** * Test of normalizeVersion method, of class WikittyUtil. */ @Test public void testNormalizeVersion() { { String version = null; String expResult = "0.0"; String result = WikittyUtil.normalizeVersion(version); Assert.assertEquals(expResult, result); } { String version = ""; String expResult = "0.0"; String result = WikittyUtil.normalizeVersion(version); Assert.assertEquals(expResult, result); } }