lishuai
Committed by Thomas Vachuska

[ONOS-2544]Monidy the bug of vsrsion utility class: ignore the

different lengths of version.

Change-Id: I9b980cb10b82cead04cacf5e1f694869d1ec11a2
...@@ -47,11 +47,23 @@ public final class VersionUtil { ...@@ -47,11 +47,23 @@ public final class VersionUtil {
47 * Compare fromVersion and toVersion. 47 * Compare fromVersion and toVersion.
48 * @param fromVersion the initial version 48 * @param fromVersion the initial version
49 * @param toVersion the end of the version 49 * @param toVersion the end of the version
50 - * @return a long number 50 + * @return an int number
51 */ 51 */
52 - public static long versionCompare(String fromVersion, String toVersion) { 52 + public static int versionCompare(String fromVersion, String toVersion) {
53 - Long fromNum = Long.parseLong(fromVersion.replace(".", "")); 53 + String[] fromArr = fromVersion.split("\\.");
54 - Long toNum = Long.parseLong(toVersion.replace(".", "")); 54 + String[] toArr = toVersion.split("\\.");
55 - return (fromNum - toNum); 55 + int fromFirst = Integer.parseInt(fromArr[0]);
56 + int fromMiddle = Integer.parseInt(fromArr[1]);
57 + int fromEnd = Integer.parseInt(fromArr[2]);
58 + int toFirst = Integer.parseInt(toArr[0]);
59 + int toMiddle = Integer.parseInt(toArr[1]);
60 + int toEnd = Integer.parseInt(toArr[2]);
61 + if (fromFirst - toFirst != 0) {
62 + return fromFirst - toFirst;
63 + } else if (fromMiddle - toMiddle != 0) {
64 + return fromMiddle - toMiddle;
65 + } else {
66 + return fromEnd - toEnd;
67 + }
56 } 68 }
57 } 69 }
......