@Test public void testVersionEquals() { assertEquals(0, Updater.isVersionNewerThan("2.10.0", "RecipeManager v2.10.0")); assertEquals(0, Updater.isVersionNewerThan("2.10.0 alpha", "RecipeManager v2.10.0 alpha")); assertEquals(0, Updater.isVersionNewerThan("2.10.0 beta", "v2.10.0 beta")); }
public static int isVersionNewerThan(String version, String check) { if (version.startsWith("RecipeManager")) { version = version.substring("RecipeManager".length()).trim(); } if (check.startsWith("RecipeManager")) { check = check.substring("RecipeManager".length()).trim(); } if (version.startsWith("v")) { version = version.substring(1).trim(); } if (check.startsWith("v")) { check = check.substring(1).trim(); } if (version.equals(check)) { return 0; } String[] versionSplit = version.split("[ -]"); String[] checkSplit = check.split("[ -]"); int compare = -2; String[] currentArray = versionSplit[0].split("\\."); String[] latestArray = checkSplit[0].split("\\."); int shortest = currentArray.length; int latestLength = latestArray.length; if (latestLength < shortest) { shortest = latestLength; } for (int i = 0; i < shortest; i++) { int c = Integer.parseInt(currentArray[i]); int l = Integer.parseInt(latestArray[i]); if (c > l) { compare = 1; break; } else if (l > c) { compare = -1; break; } } if (compare == -2) { boolean versionHasBeta = versionSplit.length > 1; boolean checkHasBeta = checkSplit.length > 1; if (versionHasBeta && checkHasBeta) { String versionBeta = versionSplit[1]; versionBeta = versionBeta.replace("dev", "0."); versionBeta = versionBeta.replace("alpha", "1."); versionBeta = versionBeta.replace("beta", "2."); String checkBeta = checkSplit[1]; checkBeta = checkBeta.replace("dev", "0."); checkBeta = checkBeta.replace("alpha", "1."); checkBeta = checkBeta.replace("beta", "2."); try { double versionDouble = Double.parseDouble(versionBeta); double checkDouble = Double.parseDouble(checkBeta); if (versionDouble > checkDouble) { compare = 1; } else if (versionDouble < checkDouble) { compare = -1; } } catch (NumberFormatException e) { } } else if (versionHasBeta) { compare = 1; } else if (checkHasBeta) { compare = -1; } } return compare; }
Updater { public static int isVersionNewerThan(String version, String check) { if (version.startsWith("RecipeManager")) { version = version.substring("RecipeManager".length()).trim(); } if (check.startsWith("RecipeManager")) { check = check.substring("RecipeManager".length()).trim(); } if (version.startsWith("v")) { version = version.substring(1).trim(); } if (check.startsWith("v")) { check = check.substring(1).trim(); } if (version.equals(check)) { return 0; } String[] versionSplit = version.split("[ -]"); String[] checkSplit = check.split("[ -]"); int compare = -2; String[] currentArray = versionSplit[0].split("\\."); String[] latestArray = checkSplit[0].split("\\."); int shortest = currentArray.length; int latestLength = latestArray.length; if (latestLength < shortest) { shortest = latestLength; } for (int i = 0; i < shortest; i++) { int c = Integer.parseInt(currentArray[i]); int l = Integer.parseInt(latestArray[i]); if (c > l) { compare = 1; break; } else if (l > c) { compare = -1; break; } } if (compare == -2) { boolean versionHasBeta = versionSplit.length > 1; boolean checkHasBeta = checkSplit.length > 1; if (versionHasBeta && checkHasBeta) { String versionBeta = versionSplit[1]; versionBeta = versionBeta.replace("dev", "0."); versionBeta = versionBeta.replace("alpha", "1."); versionBeta = versionBeta.replace("beta", "2."); String checkBeta = checkSplit[1]; checkBeta = checkBeta.replace("dev", "0."); checkBeta = checkBeta.replace("alpha", "1."); checkBeta = checkBeta.replace("beta", "2."); try { double versionDouble = Double.parseDouble(versionBeta); double checkDouble = Double.parseDouble(checkBeta); if (versionDouble > checkDouble) { compare = 1; } else if (versionDouble < checkDouble) { compare = -1; } } catch (NumberFormatException e) { } } else if (versionHasBeta) { compare = 1; } else if (checkHasBeta) { compare = -1; } } return compare; } }
Updater { public static int isVersionNewerThan(String version, String check) { if (version.startsWith("RecipeManager")) { version = version.substring("RecipeManager".length()).trim(); } if (check.startsWith("RecipeManager")) { check = check.substring("RecipeManager".length()).trim(); } if (version.startsWith("v")) { version = version.substring(1).trim(); } if (check.startsWith("v")) { check = check.substring(1).trim(); } if (version.equals(check)) { return 0; } String[] versionSplit = version.split("[ -]"); String[] checkSplit = check.split("[ -]"); int compare = -2; String[] currentArray = versionSplit[0].split("\\."); String[] latestArray = checkSplit[0].split("\\."); int shortest = currentArray.length; int latestLength = latestArray.length; if (latestLength < shortest) { shortest = latestLength; } for (int i = 0; i < shortest; i++) { int c = Integer.parseInt(currentArray[i]); int l = Integer.parseInt(latestArray[i]); if (c > l) { compare = 1; break; } else if (l > c) { compare = -1; break; } } if (compare == -2) { boolean versionHasBeta = versionSplit.length > 1; boolean checkHasBeta = checkSplit.length > 1; if (versionHasBeta && checkHasBeta) { String versionBeta = versionSplit[1]; versionBeta = versionBeta.replace("dev", "0."); versionBeta = versionBeta.replace("alpha", "1."); versionBeta = versionBeta.replace("beta", "2."); String checkBeta = checkSplit[1]; checkBeta = checkBeta.replace("dev", "0."); checkBeta = checkBeta.replace("alpha", "1."); checkBeta = checkBeta.replace("beta", "2."); try { double versionDouble = Double.parseDouble(versionBeta); double checkDouble = Double.parseDouble(checkBeta); if (versionDouble > checkDouble) { compare = 1; } else if (versionDouble < checkDouble) { compare = -1; } } catch (NumberFormatException e) { } } else if (versionHasBeta) { compare = 1; } else if (checkHasBeta) { compare = -1; } } return compare; } private  Updater(); }
Updater { public static int isVersionNewerThan(String version, String check) { if (version.startsWith("RecipeManager")) { version = version.substring("RecipeManager".length()).trim(); } if (check.startsWith("RecipeManager")) { check = check.substring("RecipeManager".length()).trim(); } if (version.startsWith("v")) { version = version.substring(1).trim(); } if (check.startsWith("v")) { check = check.substring(1).trim(); } if (version.equals(check)) { return 0; } String[] versionSplit = version.split("[ -]"); String[] checkSplit = check.split("[ -]"); int compare = -2; String[] currentArray = versionSplit[0].split("\\."); String[] latestArray = checkSplit[0].split("\\."); int shortest = currentArray.length; int latestLength = latestArray.length; if (latestLength < shortest) { shortest = latestLength; } for (int i = 0; i < shortest; i++) { int c = Integer.parseInt(currentArray[i]); int l = Integer.parseInt(latestArray[i]); if (c > l) { compare = 1; break; } else if (l > c) { compare = -1; break; } } if (compare == -2) { boolean versionHasBeta = versionSplit.length > 1; boolean checkHasBeta = checkSplit.length > 1; if (versionHasBeta && checkHasBeta) { String versionBeta = versionSplit[1]; versionBeta = versionBeta.replace("dev", "0."); versionBeta = versionBeta.replace("alpha", "1."); versionBeta = versionBeta.replace("beta", "2."); String checkBeta = checkSplit[1]; checkBeta = checkBeta.replace("dev", "0."); checkBeta = checkBeta.replace("alpha", "1."); checkBeta = checkBeta.replace("beta", "2."); try { double versionDouble = Double.parseDouble(versionBeta); double checkDouble = Double.parseDouble(checkBeta); if (versionDouble > checkDouble) { compare = 1; } else if (versionDouble < checkDouble) { compare = -1; } } catch (NumberFormatException e) { } } else if (versionHasBeta) { compare = 1; } else if (checkHasBeta) { compare = -1; } } return compare; } private  Updater(); static void init(RecipeManager newPlugin, int newProjectID, String newApiKey); static void updateOnce(final CommandSender sender); static void stop(); static String getCurrentVersion(); static String getLatestVersion(); static int isVersionNewerThan(String version, String check); static int isVersionOlderThan(String version, String check); static String getLatestLink(); static void query(CommandSender sender); }
Updater { public static int isVersionNewerThan(String version, String check) { if (version.startsWith("RecipeManager")) { version = version.substring("RecipeManager".length()).trim(); } if (check.startsWith("RecipeManager")) { check = check.substring("RecipeManager".length()).trim(); } if (version.startsWith("v")) { version = version.substring(1).trim(); } if (check.startsWith("v")) { check = check.substring(1).trim(); } if (version.equals(check)) { return 0; } String[] versionSplit = version.split("[ -]"); String[] checkSplit = check.split("[ -]"); int compare = -2; String[] currentArray = versionSplit[0].split("\\."); String[] latestArray = checkSplit[0].split("\\."); int shortest = currentArray.length; int latestLength = latestArray.length; if (latestLength < shortest) { shortest = latestLength; } for (int i = 0; i < shortest; i++) { int c = Integer.parseInt(currentArray[i]); int l = Integer.parseInt(latestArray[i]); if (c > l) { compare = 1; break; } else if (l > c) { compare = -1; break; } } if (compare == -2) { boolean versionHasBeta = versionSplit.length > 1; boolean checkHasBeta = checkSplit.length > 1; if (versionHasBeta && checkHasBeta) { String versionBeta = versionSplit[1]; versionBeta = versionBeta.replace("dev", "0."); versionBeta = versionBeta.replace("alpha", "1."); versionBeta = versionBeta.replace("beta", "2."); String checkBeta = checkSplit[1]; checkBeta = checkBeta.replace("dev", "0."); checkBeta = checkBeta.replace("alpha", "1."); checkBeta = checkBeta.replace("beta", "2."); try { double versionDouble = Double.parseDouble(versionBeta); double checkDouble = Double.parseDouble(checkBeta); if (versionDouble > checkDouble) { compare = 1; } else if (versionDouble < checkDouble) { compare = -1; } } catch (NumberFormatException e) { } } else if (versionHasBeta) { compare = 1; } else if (checkHasBeta) { compare = -1; } } return compare; } private  Updater(); static void init(RecipeManager newPlugin, int newProjectID, String newApiKey); static void updateOnce(final CommandSender sender); static void stop(); static String getCurrentVersion(); static String getLatestVersion(); static int isVersionNewerThan(String version, String check); static int isVersionOlderThan(String version, String check); static String getLatestLink(); static void query(CommandSender sender);  }