• list 分批导入db, 每1000条数据一批 , 从字符串中获取数字,小数, 版本号比较


    //这个有个弊端: 分组后分批导入, 是阻塞的,我没有导入完成,别人就不能导入, 这里可以优化成异步,线程池
    public static void main(String[] args) {
    Random random = new Random();
    ArrayList phoneList = new ArrayList<>();
    for (int i = 0; i < 30; i++) {
    phoneList.add(i);
    }

        for (int i = 0; i < phoneList.size(); i+=50) {
            //每50条数据一批
            List<Integer> collect = phoneList.stream().skip(i).limit(50).collect(Collectors.toList());
            System.out.println(collect.size());
            //执行入库操作
        }
    }
    

    版本号比较

    public static boolean isHigherTargetVersion(String sourceVersion, String targetVersion){
        if("".equals(sourceVersion.trim()) || null == sourceVersion){
            return Boolean.FALSE;
        }
        if("".equals(targetVersion.trim()) || null == targetVersion){
            return Boolean.TRUE;
        }
        String[] sourceVersionSplit = sourceVersion.split("\.");
        String[] targetVersionSplit = targetVersion.split("\.");
    
        int minlenhgt = sourceVersionSplit.length > targetVersionSplit.length ? targetVersionSplit.length : sourceVersionSplit.length;
    
        for(int i = 0;i < minlenhgt; i++){
            Integer sourceTempVersion = Integer.parseInt(sourceVersionSplit[i]);
            Integer targetTempVersion = Integer.parseInt(targetVersionSplit[i]);
            if(sourceTempVersion.intValue() == targetTempVersion.intValue()){
                continue;
            }
            return sourceTempVersion > targetTempVersion;
        }
        return sourceVersionSplit.length >= targetVersionSplit.length;
    }
    // 从字符串中获取数字
    public static String stringFormatNumber(String str){
        String regEx="[^0-9]";
        Pattern p = Pattern.compile(regEx);
        Matcher m = p.matcher(str);
        return m.replaceAll("").trim();
    }
    
    
    
      public static String getNumber(String str){
        // 控制正则表达式的匹配行为的参数(小数)
        Pattern p = Pattern.compile("(\d+\.\d+)");
        //Matcher类的构造方法也是私有的,不能随意创建,只能通过Pattern.matcher(CharSequence input)方法得到该类的实例.
        Matcher m = p.matcher(str);
        //m.find用来判断该字符串中是否含有与"(\d+\.\d+)"相匹配的子串
        if (m.find()) {
            //如果有相匹配的,则判断是否为null操作
            //group()中的参数:0表示匹配整个正则,1表示匹配第一个括号的正则,2表示匹配第二个正则,在这只有一个括号,即1和0是一样的
            str = m.group(1) == null ? "" : m.group(1);
        } else {
            //如果匹配不到小数,就进行整数匹配
            p = Pattern.compile("(\d+)");
            m = p.matcher(str);
            if (m.find()) {
                //如果有整数相匹配
                str = m.group(1) == null ? "" : m.group(1);
            } else {
                //如果没有小数和整数相匹配,即字符串中没有整数和小数,就设为空
                str = "";
            }
        }
        return str;
    }
    
    
    
    
    /**
     * 版本号比较
     *
     * @param v1
     * @param v2
     * @return 0代表相等,1代表左边大,-1代表右边大
     * Utils.compareVersion("1.0.358_20180820090554","1.0.358_20180820090553")=1
     */
    public static int compareVersion(String v1, String v2) {
        if (v1.equals(v2)) {
            return 0;
        }
        String[] version1Array = v1.split("[._]");
        String[] version2Array = v2.split("[._]");
        int index = 0;
        int minLen = Math.min(version1Array.length, version2Array.length);
        long diff = 0;
    
        while (index < minLen
                && (diff = Long.parseLong(version1Array[index])
                - Long.parseLong(version2Array[index])) == 0) {
            index++;
        }
        if (diff == 0) {
            for (int i = index; i < version1Array.length; i++) {
                if (Long.parseLong(version1Array[i]) > 0) {
                    return 1;
                }
            }
    
            for (int i = index; i < version2Array.length; i++) {
                if (Long.parseLong(version2Array[i]) > 0) {
                    return -1;
                }
            }
            return 0;
        } else {
            return diff > 0 ? 1 : -1;
        }
    }
  • 相关阅读:
    golang删除数组某个元素
    golang用通道实现信号量,控制并发个数
    什么是ScaleIO中的forwards rebuild和backwards rebuild?
    SQL Server中的database checkpoint
    如何将thick provision lazy zeroed的VMDK文件转换为thick provision eager zeroed?
    LoadTestAgentResultsLateException in VS2010
    SQL Server Instance无法启动了, 因为TempDB所在的分区没有了, 怎么办?
    VMware vCenter中, 如何辩认虚机上Raw Device Mapping过了的一块物理磁盘?
    SQL Server AlwaysOn Setup Step-By-Step Guide
    TPC-E在populate测试Database时需要注意的一些事项
  • 原文地址:https://www.cnblogs.com/lvcai/p/13711874.html
Copyright © 2020-2023  润新知