美文网首页
java 版本号递增

java 版本号递增

作者: JuneGe2017 | 来源:发表于2020-12-02 09:54 被阅读0次
    @Slf4j
    public class VsersionUtil {
    
        public static String upgradeVersion(String version)
        {
            String upgradeVsersion;
            if (StringUtils.isEmpty(version))
            {
                version = "1.0.0.0";
            }
            //将版本号拆解成整数数组
            List<String> strArr = Splitter.on(".").splitToList(version);
            Integer[] ints = new Integer[strArr.size()];
            for(int i=0 ;i<strArr.size(); i++) {
                ints[i] = Integer.parseInt(strArr.get(i));
            }
            //递归调用
            upgradeVersion(ints, ints.length - 1);
    
            //数组转字符串
            upgradeVsersion = Joiner.on(".").join(ints);
    
            return upgradeVsersion;
        }
        private static void upgradeVersion(Integer[] ints, int index)
        {
            if (index == 0) {
                ints[0] = ints[0] + 1;
            } else {
                int value = ints[index] + 1;
                if (value < 10) {
                    ints[index] = value;
                } else {
                    ints[index] = 0;
                    upgradeVersion(ints, index - 1);
                }
            }
        }
    
        public static void main(String[] args) {
            log.info("version:1.0.0.0|"+upgradeVersion("1.0.0.0"));
            log.info("version:1.0.0.9|"+upgradeVersion("1.0.0.9"));
            log.info("version:1.0.1.9|"+upgradeVersion("1.0.1.9"));
            log.info("version:1.0.9.9|"+upgradeVersion("1.0.9.9"));
            log.info("version:1.9.9.9|"+upgradeVersion("1.9.9.9"));
        }
    }

    相关文章

      网友评论

          本文标题:java 版本号递增

          本文链接:https://www.haomeiwen.com/subject/hhjywktx.html