IndexVersion { public static int compareSoftwareVersions(String firstVersion, String secondVersion) throws IOException { int GREATER_THAN = 1; int EQUAL = 0; int LESS_THAN = -1; if (firstVersion == null) { return LESS_THAN; } if (secondVersion == null) { return GREATER_THAN; } String[] firstParts = firstVersion.split("\\."); String[] secondParts = secondVersion.split("\\."); int firstMajor = firstParts.length >= 1 ? Integer.parseInt(firstParts[0]) : 0; int firstMinor = firstParts.length >= 2 ? Integer.parseInt(firstParts[1]) : 0; int secondMajor = secondParts.length >= 1 ? Integer.parseInt(secondParts[0]) : 0; int secondMinor = secondParts.length >= 2 ? Integer.parseInt(secondParts[1]) : 0; if (firstMajor == secondMajor && firstMinor == secondMinor) { return EQUAL; } else if (firstMajor > secondMajor) { return GREATER_THAN; } else if (firstMajor < secondMajor) { return LESS_THAN; } else if (firstMinor > secondMinor) { return GREATER_THAN; } else { return LESS_THAN; } } private  IndexVersion(); static void main(String[] argv); static String getIndexVersion(String indexDirPath); static int compareSoftwareVersions(String firstVersion, String secondVersion); static String getLatestVersion();  }
@Test public void testCompareSoftwareVersions() throws Exception { assertEquals(-1, IndexVersion.compareSoftwareVersions("5", "6")); assertEquals(-1, IndexVersion.compareSoftwareVersions("4.1", "6")); assertEquals(-1, IndexVersion.compareSoftwareVersions("4.1", "4.4")); assertEquals(-1, IndexVersion.compareSoftwareVersions("4.1", "4.10")); assertEquals(-1, IndexVersion.compareSoftwareVersions("4.4", "4.10")); assertEquals(-1, IndexVersion.compareSoftwareVersions("4.4", "5.1")); assertEquals(1, IndexVersion.compareSoftwareVersions("6", "5")); assertEquals(1, IndexVersion.compareSoftwareVersions("6.10", "6.4")); assertEquals(1, IndexVersion.compareSoftwareVersions("6.10", "6.1")); assertEquals(1, IndexVersion.compareSoftwareVersions("5.3", "2.4")); assertEquals(0, IndexVersion.compareSoftwareVersions("5", "5.0")); assertEquals(0, IndexVersion.compareSoftwareVersions("6", "6")); assertEquals(0, IndexVersion.compareSoftwareVersions("4.2", "4.2")); assertEquals(0, IndexVersion.compareSoftwareVersions("4.2.1", "4.2")); }