package com.sptg.common.core.util;

/**
 * @author WFT
 * @date 2020/6/20
 * description:
 */
public class VersionUtil {

    /**
     * 版本号比较
     * @param version1 旧的版本号
     * @param version2 新的版本号
     * @return true:新版本大于旧版本,false:新版本小于或等于旧版本
     */
    public static boolean compareTo(String version1,String version2){
        String[] arr1 = version1.split("\\.");
        String[] arr2 = version2.split("\\.");

        int len;
        if (arr1.length == arr2.length){
            len = arr1.length;
        } else {
            len = arr1.length > arr2.length ? arr2.length : arr1.length;
        }

        for (int i = 0; i < len; i++){
            int flag = arr1[i].length() - arr2[i].length();
            if (flag == 0){
                flag = arr1[i].compareTo(arr2[i]);
                if (flag == 0){
                    continue;
                }
            }
            return flag < 0;
        }
        return false;
    }

}
