zoukankan      html  css  js  c++  java
  • java通过key-list构造对象

    java通过key-list构造对象

    给定一组key组成的list,和它对应的value,凭空构造出一个对象

    Object buildObject(final List<String> paths, final Object object) {
            if (null == paths) {
                throw DataMException.asDataMException(
                        "Path不能为null,该异常代表系统编程错误, 请联系DataX开发团队 !");
            }
    
            if (1 == paths.size() && StringUtils.isBlank(paths.get(0))) {
                return object;
            }
    
            Object child = object;
            for (int i = paths.size() - 1; i >= 0; i--) {
                String path = paths.get(i);
    
                if (isPathMap(path)) {
                    Map<String, Object> mapping = new HashMap<String, Object>();
                    mapping.put(path, child);
                    child = mapping;
                    continue;
                }
    
                if (isPathList(path)) {
                    List<Object> lists = new ArrayList<Object>(
                            this.getIndex(path) + 1);
                    expand(lists, this.getIndex(path) + 1);
                    lists.set(this.getIndex(path), child);
                    child = lists;
                    continue;
                }
    
                throw DataMException.asDataMException("路径[%s]出现非法值类型[%s],该异常代表系统编程错误, 请联系DataX开发团队! .");
            }
    
            return child;
        }
  • 相关阅读:
    函数
    关联子查询
    子查询
    视图(VIEW)
    顺时针打印矩阵
    二叉树的镜像
    树的子结构
    将两个有序链表合并
    反转链表
    输出链表中倒数第k个结点
  • 原文地址:https://www.cnblogs.com/wangbin2188/p/14188495.html
Copyright © 2011-2022 走看看