@Test(expected = VersionException.class) public void testCompareInvalidVersion() { VersionUtils.compare("0.1", "0.2"); }
public static int compare(String version1, String version2) { String[] ver1 = version1.split("\\."); String[] ver2 = version2.split("\\."); if (ver1.length != 3 && ver2.length != 3) { throw new VersionException( "Version must be in the format of <major>.<minor>.<subminor>"); } int majorVer1 = Integer.parseInt(ver1[0]); int majorVer2 = Integer.parseInt(ver2[0]); if (majorVer1 < majorVer2) { return -1; } else if (majorVer1 > majorVer2) { return 1; } else { int minorVer1 = Integer.parseInt(ver1[1]); int minorVer2 = Integer.parseInt(ver2[1]); if (minorVer1 < minorVer2) { return -1; } else if (minorVer1 > minorVer2) { return 1; } else { int subminorVer1 = Integer.parseInt(ver1[2]); int subminorVer2 = Integer.parseInt(ver2[2]); if (subminorVer1 < subminorVer2) { return -1; } else if (subminorVer1 > subminorVer2) { return 1; } else { return 0; } } } }
VersionUtils { public static int compare(String version1, String version2) { String[] ver1 = version1.split("\\."); String[] ver2 = version2.split("\\."); if (ver1.length != 3 && ver2.length != 3) { throw new VersionException( "Version must be in the format of <major>.<minor>.<subminor>"); } int majorVer1 = Integer.parseInt(ver1[0]); int majorVer2 = Integer.parseInt(ver2[0]); if (majorVer1 < majorVer2) { return -1; } else if (majorVer1 > majorVer2) { return 1; } else { int minorVer1 = Integer.parseInt(ver1[1]); int minorVer2 = Integer.parseInt(ver2[1]); if (minorVer1 < minorVer2) { return -1; } else if (minorVer1 > minorVer2) { return 1; } else { int subminorVer1 = Integer.parseInt(ver1[2]); int subminorVer2 = Integer.parseInt(ver2[2]); if (subminorVer1 < subminorVer2) { return -1; } else if (subminorVer1 > subminorVer2) { return 1; } else { return 0; } } } } }
VersionUtils { public static int compare(String version1, String version2) { String[] ver1 = version1.split("\\."); String[] ver2 = version2.split("\\."); if (ver1.length != 3 && ver2.length != 3) { throw new VersionException( "Version must be in the format of <major>.<minor>.<subminor>"); } int majorVer1 = Integer.parseInt(ver1[0]); int majorVer2 = Integer.parseInt(ver2[0]); if (majorVer1 < majorVer2) { return -1; } else if (majorVer1 > majorVer2) { return 1; } else { int minorVer1 = Integer.parseInt(ver1[1]); int minorVer2 = Integer.parseInt(ver2[1]); if (minorVer1 < minorVer2) { return -1; } else if (minorVer1 > minorVer2) { return 1; } else { int subminorVer1 = Integer.parseInt(ver1[2]); int subminorVer2 = Integer.parseInt(ver2[2]); if (subminorVer1 < subminorVer2) { return -1; } else if (subminorVer1 > subminorVer2) { return 1; } else { return 0; } } } } private  VersionUtils(); }
VersionUtils { public static int compare(String version1, String version2) { String[] ver1 = version1.split("\\."); String[] ver2 = version2.split("\\."); if (ver1.length != 3 && ver2.length != 3) { throw new VersionException( "Version must be in the format of <major>.<minor>.<subminor>"); } int majorVer1 = Integer.parseInt(ver1[0]); int majorVer2 = Integer.parseInt(ver2[0]); if (majorVer1 < majorVer2) { return -1; } else if (majorVer1 > majorVer2) { return 1; } else { int minorVer1 = Integer.parseInt(ver1[1]); int minorVer2 = Integer.parseInt(ver2[1]); if (minorVer1 < minorVer2) { return -1; } else if (minorVer1 > minorVer2) { return 1; } else { int subminorVer1 = Integer.parseInt(ver1[2]); int subminorVer2 = Integer.parseInt(ver2[2]); if (subminorVer1 < subminorVer2) { return -1; } else if (subminorVer1 > subminorVer2) { return 1; } else { return 0; } } } } private  VersionUtils(); static String getLatestVersion(); static int compare(String version1, String version2); }
VersionUtils { public static int compare(String version1, String version2) { String[] ver1 = version1.split("\\."); String[] ver2 = version2.split("\\."); if (ver1.length != 3 && ver2.length != 3) { throw new VersionException( "Version must be in the format of <major>.<minor>.<subminor>"); } int majorVer1 = Integer.parseInt(ver1[0]); int majorVer2 = Integer.parseInt(ver2[0]); if (majorVer1 < majorVer2) { return -1; } else if (majorVer1 > majorVer2) { return 1; } else { int minorVer1 = Integer.parseInt(ver1[1]); int minorVer2 = Integer.parseInt(ver2[1]); if (minorVer1 < minorVer2) { return -1; } else if (minorVer1 > minorVer2) { return 1; } else { int subminorVer1 = Integer.parseInt(ver1[2]); int subminorVer2 = Integer.parseInt(ver2[2]); if (subminorVer1 < subminorVer2) { return -1; } else if (subminorVer1 > subminorVer2) { return 1; } else { return 0; } } } } private  VersionUtils(); static String getLatestVersion(); static int compare(String version1, String version2);  }