Version { public static int compare(String srcVersion, String destVersion) { DefaultArtifactVersion srcArtifactVersion = new DefaultArtifactVersion(srcVersion); DefaultArtifactVersion destArtifactVersion = new DefaultArtifactVersion(destVersion); int[] srcVersionArray = {srcArtifactVersion.getMajorVersion(), srcArtifactVersion.getMinorVersion(), srcArtifactVersion.getIncrementalVersion()}; int[] destVersionArray = {destArtifactVersion.getMajorVersion(), destArtifactVersion.getMinorVersion(), destArtifactVersion.getIncrementalVersion()}; for (int i = 0; i < srcVersionArray.length; i++) { if (i >= destVersionArray.length) { return compare(destVersionArray, srcVersionArray, 1); } if (srcVersionArray[i] > destVersionArray[i]) { return 1; } else if (srcVersionArray[i] < destVersionArray[i]) { return -1; } } if (destVersionArray.length > srcVersionArray.length) { return compare(srcVersionArray, destVersionArray, -1); } return 0; }  static int compare(String srcVersion, String destVersion); static int compare(int[] srcVersionArray, int[] destVersionArray,
         int type);  }
@Test public void testCompare() { Assert.assertTrue(Version.compare("5.0.2-1.cdh5.0.2.p0.13", "5.0.1") > 0); Assert.assertTrue(Version.compare("6", "5") > 0); Assert.assertTrue(Version.compare("6", "5.9") > 0); Assert.assertTrue(Version.compare("5.1", "5") > 0); Assert.assertTrue(Version.compare("5.1", "5.0") > 0); Assert.assertTrue(Version.compare("5.1", "5.0.9") > 0); Assert.assertTrue(Version.compare("5.1.1", "5.1.0") > 0); Assert.assertTrue(Version.compare("5", "5") == 0); Assert.assertTrue(Version.compare("5.0", "5") == 0); Assert.assertTrue(Version.compare("5", "5.0") == 0); Assert.assertTrue(Version.compare("5.0.0", "5") == 0); Assert.assertTrue(Version.compare("5.0.0", "5.0") == 0); Assert.assertTrue(Version.compare("5.0.0", "5.0.0") == 0); Assert.assertTrue(Version.compare("5", "6") < 0); Assert.assertTrue(Version.compare("5", "5.1") < 0); Assert.assertTrue(Version.compare("5.0", "5.1") < 0); Assert.assertTrue(Version.compare("5.1", "5.1.1") < 0); Assert.assertTrue(Version.compare("5.1.0", "5.1.1") < 0); Assert.assertTrue(Version.compare("5.1.0", "5.2") < 0); Assert.assertTrue(Version.compare("5.1.0", "5.2") < 0); }