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 {
* Compare fromVersion and toVersion.
* @param fromVersion the initial version
* @param toVersion the end of the version
* @return a long number
* @return an int number
*/
public static long versionCompare(String fromVersion, String toVersion) {
Long fromNum = Long.parseLong(fromVersion.replace(".", ""));
Long toNum = Long.parseLong(toVersion.replace(".", ""));
return (fromNum - toNum);
public static int versionCompare(String fromVersion, String toVersion) {
String[] fromArr = fromVersion.split("\\.");
String[] toArr = toVersion.split("\\.");
int fromFirst = Integer.parseInt(fromArr[0]);
int fromMiddle = Integer.parseInt(fromArr[1]);
int fromEnd = Integer.parseInt(fromArr[2]);
int toFirst = Integer.parseInt(toArr[0]);
int toMiddle = Integer.parseInt(toArr[1]);
int toEnd = Integer.parseInt(toArr[2]);
if (fromFirst - toFirst != 0) {
return fromFirst - toFirst;
} else if (fromMiddle - toMiddle != 0) {
return fromMiddle - toMiddle;
} else {
return fromEnd - toEnd;
}
}
}
......