• 解析小结—自用


    解析流程

    1 拿到文件

    // RedisUtils 见详情
    byte[] o = (byte[]) redisUtils.get("128.0.1.13_5005:TCC:50:46:1618883189519");
    
    • 1
    • 2

    RedisUtils

    2 转化进制

    // ByteToObjectUtils 见详情
     String binaryStr = ByteToObjectUtils.bytes16toBinaryStr(o);
    
    • 1
    • 2

    进入解析流程

    1.解析XML

    2.获取XML标签内容(解xml文件成想要的数据格式)

    getChildNode()
    
    • 1

    知识点

    基于java Files类和Paths类的用法(详解)

    Path用于来表示文件路径和文件。可以有多种方法来构造一个Path对象来表示一个文件路径,或者一个文件

    files.lines()方法以 :Stream流的形式读取文件的所有行

    Pattern.compile()Pattern.compile函数提取字符串中指定的字符

    replaceAll() 方法使用给定的参数 replacement 替换字符串所有匹配给定的正则表达式的子字符串

    substring() substring() 方法用于提取字符串中介于两个指定下标之间的字符。

    Character.isUpperCase()

    Java反射技术详解

    XML解析

    BigInteger bigInteger = new BigInteger(substring,2);转化超大二进制

    Document对象

    代码

    package com.xx.project.common.utils;
    
    
    import com.alibaba.fastjson.JSON;
    import com.alibaba.fastjson.JSONArray;
    
    import com.alibaba.fastjson.JSONObject;
    import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
    import com.xx.project.common.XmlConstant;
    import lombok.extern.slf4j.Slf4j;
    
    import org.apache.commons.collections4.MapUtils;
    import org.apache.commons.lang3.StringUtils;
    import org.springframework.core.io.ClassPathResource;
    import org.w3c.dom.*;
    
    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;
    import java.io.InputStream;
    import java.math.BigInteger;
    import java.util.*;
    import java.util.stream.Collectors;
    ;
    
    @Slf4j
    public class XmlToData {
        public static Object getXmlFile(String resourcePath, String binaryStr) {
            if (StringUtils.isBlank(binaryStr)) {
                return null;
            }
            JSONArray childNode = new JSONArray();
            // 解析xml文件
            // 1、获取InputStream输入流
            try (InputStream in = new ClassPathResource(resourcePath).getInputStream()) {
                // 2、获取DocumentBuilderFactory实例
                DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
                // 3、获取DocumentBuilder实例
                DocumentBuilder docBuilder = factory.newDocumentBuilder();
                // 4、将docBuilder转换为Document
                Document doc = docBuilder.parse(in);
                // 5、获取节点并循环输出节点值  根节点
                Element element = doc.getDocumentElement();
                //将xml标签从对象中取出  子节点
                NodeList childNodes = element.getChildNodes();
                if (childNodes != null) {
                    //递归读取节点列表中子节点包括内容数据
                    childNode = getChildNode(childNodes);
                }
            } catch (Exception e) {
                log.error("loadXmlFile is error", e);
            }
            int bigSet = 0;
            // 公共包头解析
            JSONArray titleArray = getTitleArray("title.xml");
            Map<String, Object> headerData = getStationData(titleArray, binaryStr, bigSet);
            if (Objects.nonNull(headerData.get("bigSet"))) {
                bigSet = Integer.parseInt(headerData.get("bigSet").toString());
            }
            if (Objects.isNull(headerData.get("Herder"))) {
                return null;
            }
            Object header = headerData.get("Herder");
            JSONObject object = JSONObject.parseObject(JSON.toJSONString(header));
            if (Objects.isNull(object.get("length")) || object.getIntValue("length") == 0) {
                return null;
            }
            Map<String, Object> stationData = null;
            Map<String, Object> queryMap = new HashMap<>();
            switch (object.getIntValue("Type")) {
                case XmlConstant.BP:
                    stationData = getStationData(childNode, binaryStr, bigSet);
                    System.out.println(stationData);
                    break;
                case XmlConstant.W:
                    stationData = getStationData(childNode, binaryStr, bigSet);
                    break;
                default:
                    queryMap = getData(childNode, queryMap, null, binaryStr, bigSet, null, false);
                    break;
            }
            if (MapUtils.isNotEmpty(queryMap)) {
                return queryMap;
            } else {
                return stationData;
            }
    
        }
    
        private static JSONArray getTitleArray(String resourcePath) {
            JSONArray childNode = new JSONArray();
            // 解析xml文件
            // 1、获取InputStream输入流
            try (InputStream in = new ClassPathResource(resourcePath).getInputStream()) {
                // 2、获取DocumentBuilderFactory实例
                DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
                // 3、获取DocumentBuilder实例
                DocumentBuilder docBuilder = factory.newDocumentBuilder();
                // 4、将docBuilder转换为Document
                Document doc = docBuilder.parse(in);
                // 5、获取节点并循环输出节点值
                Element element = doc.getDocumentElement();
                //将xml标签从对象中取出
                NodeList childNodes = element.getChildNodes();
                if (childNodes != null) {
                    //递归读取节点列表中子节点包括内容数据
                    childNode = getChildNode(childNodes);
                }
    
            } catch (Exception e) {
                log.error("loadXmlFile is error", e);
            }
            return childNode;
        }
    
        private static JSONArray getChildNode(NodeList childNodes) {
            JSONArray resArray = new JSONArray();
            try {
                for (int i = 0; i < childNodes.getLength(); i++) {
                    JSONObject resObj = new JSONObject();
                    /**
                     * 返回节点列表中指定索引号的节点。
                     *  https://www.w3cschool.cn/xmldom/dom-nodelist.html(nodeList)
                     *  https://www.runoob.com/dom/dom-node.html(node)
                     */
                    Node node = childNodes.item(i);
                    /**
                     * NamedNodeMap
                     * getNamedItem(name)	返回nodeName属性等于name的节点
                     */
                    NamedNodeMap attributes = node.getAttributes();
                    if (attributes != null) {
                        /**
                         * 当前节点名字
                         *
                         * 
                         * ...
                         */
                        switch (node.getNodeName()) {
                            /**
                             * 当前节点下的内容放在PUT中
                             */
                            case "category":
                                if (attributes.getNamedItem("name_CN") != null) {
                                    /**
                                     * name_CN 的内容
                                     */
                                    resObj.put("name", attributes.getNamedItem("name_CN").getTextContent());
                                }
                                resObj.put("label", "category");
                                if (attributes.getNamedItem("type") != null) {
                                    resObj.put("type", attributes.getNamedItem("type").getTextContent());
                                }
                                if (attributes.getNamedItem("name_EN") != null) {
                                    resObj.put("name_e", attributes.getNamedItem("name_EN").getTextContent());
                                }
                                /**
                                 * 得到getChildNodes()每一个节点的子节点
                                 */
                                NodeList categoryNodes = node.getChildNodes();
    
                                if (categoryNodes != null) {
                                    //递归调用
                                    JSONArray child = getChildNode(categoryNodes);
                                    if (child.size() > 0) {
                                        resObj.put("categoryChild", child);
                                    }
                                    break;
                                }
                            case "segment":
                                if (attributes.getNamedItem("name_CN") != null) {
                                    resObj.put("name", attributes.getNamedItem("name_CN").getTextContent());
                                }
                                if (attributes.getNamedItem("name_EN") != null) {
                                    resObj.put("name_e", attributes.getNamedItem("name_EN").getTextContent());
                                }
                                if (attributes.getNamedItem("length") != null) {
                                    resObj.put("length", attributes.getNamedItem("length").getTextContent());
                                } else if (attributes.getNamedItem("length") != null && attributes.getNamedItem("name_CN") != null) {
                                    resObj.put("name", "预留");
                                }
                                if (!resObj.isEmpty()) {
                                    resObj.put("label", "segment");
                                }
                                if (attributes.getNamedItem("relateloop") != null) {
                                    resObj.put("relateloop", attributes.getNamedItem("relateloop").getTextContent());
                                    resObj.put("name", "loopRelation");
                                }
                                NodeList resNodes = node.getChildNodes();
                                if (resNodes != null) {
                                    JSONArray child = getChildNode(resNodes);
                                    if (child.size() > 0) {
                                        resObj.put("segmentChild", child);
                                    }
                                }
                                break;
                            case "group":
                                if (attributes.getNamedItem("name_CN") != null) {
                                    resObj.put("name", attributes.getNamedItem("name_CN").getTextContent());
                                }
                                if (attributes.getNamedItem("name_EN") != null) {
                                    resObj.put("name_e", attributes.getNamedItem("name_EN").getTextContent());
                                }
                                resObj.put("label", "group");
                                if (attributes.getNamedItem("length") != null) {
                                    resObj.put("length", attributes.getNamedItem("length").getTextContent());
                                }
                                NodeList groupNodes = node.getChildNodes();
                                if (groupNodes != null) {
                                    JSONArray child = getChildNode(groupNodes);
                                    if (child.size() > 0) {
                                        resObj.put("groupChild", child);
                                    }
                                }
                                break;
                            case "branch":
                                if (attributes.getNamedItem("name_CN") != null) {
                                    resObj.put("name", attributes.getNamedItem("name_CN").getTextContent());
                                }
                                if (attributes.getNamedItem("name_EN") != null) {
                                    resObj.put("name_e", attributes.getNamedItem("name_EN").getTextContent());
                                }
                                resObj.put("label", "branch");
                                if (attributes.getNamedItem("position") != null) {
                                    resObj.put("position", attributes.getNamedItem("position").getTextContent());
                                }
                                NodeList branchNodes = node.getChildNodes();
                                if (branchNodes != null) {
                                    //递归调用
                                    JSONArray child = getChildNode(branchNodes);
                                    if (child.size() > 0) {
                                        resObj.put("branchChild", child);
                                    }
                                }
                                break;
                            case "loop":
                                resObj.put("label", "loop");
                                if (attributes.getNamedItem("looptime") != null) {
                                    resObj.put("looptime", attributes.getNamedItem("looptime").getTextContent());
                                }
                                if (attributes.getNamedItem("relateloop") != null) {
                                    resObj.put("relateloop", attributes.getNamedItem("relateloop").getTextContent());
                                }
                                if (attributes.getNamedItem("name_CN") != null) {
                                    resObj.put("name", attributes.getNamedItem("name_CN").getTextContent());
                                }
                                //是否需要排序
                                if (attributes.getNamedItem("order") != null) {
                                    resObj.put("order", attributes.getNamedItem("order").getTextContent());
                                }
                                //是否需要除以单位
                                if (attributes.getNamedItem("isRemoved") != null) {
                                    resObj.put("isRemoved", attributes.getNamedItem("isRemoved").getTextContent());
                                }
                                if (attributes.getNamedItem("name_EN") != null) {
                                    resObj.put("name_e", attributes.getNamedItem("name_EN").getTextContent());
                                }
                                //是否需要索引
                                if (attributes.getNamedItem("isIndex") != null) {
                                    resObj.put("isIndex", attributes.getNamedItem("isIndex").getTextContent());
                                }
    
                                NodeList loopNodes = node.getChildNodes();
                                if (loopNodes != null) {
                                    //递归调用
                                    JSONArray child = getChildNode(loopNodes);
                                    if (child.size() > 0) {
                                        resObj.put("loopChild", child);
                                    }
                                }
                                break;
                            case "value":
                                //提取xml文件中type内容 需要什么值直接在这里添加就ok
                                //只需要xml添加的字段和 下面的key一样就可以
                                resObj.put("label", "value");
                                if (attributes.getNamedItem("name_CN") != null) {
                                    resObj.put("name", attributes.getNamedItem("name_CN").getTextContent());
                                }
                                if (attributes.getNamedItem("name_EN") != null) {
                                    resObj.put("name_e", attributes.getNamedItem("name_EN").getTextContent());
                                }
                                if (attributes.getNamedItem("number") != null) {
                                    resObj.put("number", attributes.getNamedItem("number").getTextContent());
                                }
                                if (attributes.getNamedItem("other") != null) {
                                    resObj.put("number", attributes.getNamedItem("other").getTextContent());
                                }
                                if (attributes.getNamedItem("isUnit") != null) {
                                    resObj.put("isUnit", attributes.getNamedItem("isUnit").getTextContent());
                                }
                                if (attributes.getNamedItem("unit") != null) {
                                    resObj.put("unit", attributes.getNamedItem("unit").getTextContent());
                                }
                                NodeList valueNodes = node.getChildNodes();
                                if (valueNodes != null) {
                                    //递归调用
                                    JSONArray child = getChildNode(valueNodes);
                                    if (child.size() > 0) {
                                        resObj.put("valueChild", child);
                                    }
                                }
                                break;
                            default:
                        }
    
                    }
    
                }
            } catch (Exception e) {
                log.error("loadXmlFile: getChildNode is error", e);
                throw e;
            }
    
            return resArray;
        }
    
        private static Map<String, Object> getStationData(JSONArray childNode, String binaryStr, int bigSet) {
            Map<String, Object> queryMap = new HashMap<>();
            for (int j = 0; j < childNode.size(); j++) {
                /**
                 * JSON.toJSONString(childNode.get(j)) 转 String
                 * JSONObject.parseObject(String str)转对象
                 */
                JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(childNode.get(j)));
                if (StringUtils.isEmpty(jsonObject.getString("name_e"))) {
                    continue;
                }
                String enName = jsonObject.getString("name_e");
                String length = "";
                if (Objects.nonNull(jsonObject.getString("length"))) {
                    length = jsonObject.getString("length");
                }
                if (Objects.nonNull(jsonObject.get("label")) && CollectionUtils.isNotEmpty(jsonObject.getJSONArray(jsonObject.getString("label") + "Child"))) {
                    StringBuilder value = new StringBuilder("");
                    // 子标签集合内容
                    JSONArray childList = jsonObject.getJSONArray(jsonObject.getString("label") + "Child");
                    if (jsonObject.getString("label").equals("group")) {
                        String[] groupSp;
                        /**
                         * 条件过滤
                         */
                        List<Object> collect = childList.stream().filter(s -> Objects.nonNull(JSONObject.parseObject(JSON.toJSONString(s)).get("position")) &&
                                JSONObject.parseObject(JSON.toJSONString(s)).get("position").equals("true")).collect(Collectors.toList());
                        boolean flag = true;
                        /**
                         * 循环子节点
                         */
                        for (Object item : childList) {
                            JSONObject branchObject = JSONObject.parseObject(JSON.toJSONString(item));
                            groupSp = length.split(",");
                            if (CollectionUtils.isNotEmpty(collect) && flag) {
                                /**
                                 * 字符串连接
                                 */
                                value.append(branchObject.getString("name"));
                                flag = false;
                            } else if (CollectionUtils.isNotEmpty(collect) && Integer.parseInt(JSONObject.parseObject(JSON.toJSONString(item)).getString("position")) > 1) {
                                int branchLength = Integer.parseInt(groupSp[branchObject.getInteger("position") - 2]);
                                if (bigSet >= binaryStr.length()) {
                                    return queryMap;
                                }
                                /**
                                 * 第一个int为开始的索引,对应String数字中的开始位置,
                                 * 第二个是截止的索引位置,对应String中的结束位置
                                 */
                                String substring = binaryStr.substring(bigSet, bigSet + branchLength);
                                /**
                                 * 转化进制
                                 */
                                BigInteger num = new BigInteger(substring, 2);
                                value.append(num).append(branchObject.getString("name"));
                                bigSet += branchLength;
                            } else {
                                int branchLength = Integer.parseInt(groupSp[branchObject.getInteger("position") - 1]);
                                if (bigSet >= binaryStr.length()) {
                                    return queryMap;
                                }
                                String substring = binaryStr.substring(bigSet, bigSet + branchLength);
                                BigInteger num = new BigInteger(substring, 2);
                                value.append(num).append(branchObject.getString("name"));
                                bigSet += branchLength;
                            }
                        }
                        queryMap.put("bigSet", bigSet);
                        queryMap.put(enName, value.toString());
    
                    } else if (jsonObject.getString("label").equals("segment")) {
                        int longLength = Integer.parseInt(length);
                        if (bigSet >= binaryStr.length()) {
                            return queryMap;
                        }
                        String substring = binaryStr.substring(bigSet, bigSet + longLength);
                        for (Object segmentObj : childList) {
                            JSONObject valueObject = JSONObject.parseObject(JSON.toJSONString(segmentObj));
                            String number = valueObject.getString("number");
                            if (number.contains("0x")) {
                                number = number.replace("0x", "");
                                BigInteger tenValue = new BigInteger(number, 16);
                                BigInteger twoToTen = new BigInteger(substring, 2);
                                if (tenValue.equals(twoToTen)) {
                                    if (StringUtils.isBlank(value)) {
                                        value.append(tenValue);
                                    }
                                }
                            }
                        }
                        if (StringUtils.isBlank(value.toString())) {
                            List<Object> collect = childList.stream().filter(s -> Objects.nonNull(JSONObject.parseObject(JSON.toJSONString(s)).get("number")) && JSONObject.parseObject(JSON.toJSONString(s)).get("number").equals("true")).collect(Collectors.toList());
                            if (CollectionUtils.isNotEmpty(collect)) {
                                value = new StringBuilder(JSONObject.parseObject(JSON.toJSONString(collect.get(0))).getString("name"));
                            }
                        }
    
                        if (StringUtils.isNotEmpty(jsonObject.getString("relateloop"))) {
                            int loopNum = Integer.parseInt(substring, 2);
                            queryMap.put("relateNum", loopNum);
                            queryMap.put("relateName", jsonObject.getString("relateloop"));
                        }
                        bigSet += longLength;
                        queryMap.put(enName, value);
                        queryMap.put("bigSet", bigSet);
                    } else if (jsonObject.getString("label").equals("loop")) {
                        Integer loopTime = 0;
                        if (Objects.nonNull(jsonObject.get("relateloop")) && jsonObject.getString("relateloop").equals("true")) {
                            if (Objects.nonNull(queryMap.get("relateName")) && Objects.nonNull(queryMap.get("relateName"))) {
                                loopTime = Integer.valueOf(queryMap.get("relateNum").toString());
                            }
                        } else {
                            loopTime = jsonObject.getInteger("looptime");
                        }
                        if (Objects.nonNull(jsonObject.get("isRemoved"))) {
                            Integer isRemoved = jsonObject.getInteger("isRemoved");
                            loopTime = loopTime / isRemoved;
                        }
                        List<Map<String, Object>> dataList = new ArrayList<>();
                        for (int i = 0; i < loopTime; i++) {
                            Map<String, Object> stationData = getStationData(childList, binaryStr, bigSet);
                            if (Objects.nonNull(stationData.get("bigSet"))) {
                                bigSet = Integer.parseInt(stationData.get("bigSet").toString());
                            }
                            stationData.remove("relateNum");
                            stationData.remove("relateName");
                            dataList.add(stationData);
                        }
                        queryMap.put(enName, dataList);
                        queryMap.put("bigSet", bigSet);
                    } else {
                        // 迭代
                        Map<String, Object> label = getStationData(jsonObject.getJSONArray(jsonObject.getString("label") + "Child"), binaryStr, bigSet);
                        if (Objects.nonNull(label.get("bigSet"))) {
                            bigSet = Integer.parseInt(label.get("bigSet").toString());
                        }
                        label.remove("relateNum");
                        label.remove("relateName");
                        queryMap.put(enName, label);
                        queryMap.put("bigSet", bigSet);
                    }
                } else {
                    if (bigSet >= binaryStr.length()) {
                        return queryMap;
                    }
                    int longLength = Integer.parseInt(length);
                    String substring = binaryStr.substring(bigSet, bigSet + longLength);
                    bigSet += longLength;
                    BigInteger bigInteger = new BigInteger(substring, 2);
                    if (StringUtils.isNotEmpty(jsonObject.getString("relateloop"))) {
                        queryMap.put("relateNum", bigInteger);
                        queryMap.put("relateName", jsonObject.getString("relateloop"));
                    }
                    queryMap.put(enName, bigInteger);
                    queryMap.put("bigSet", bigSet);
                }
            }
            queryMap.remove("relateNum");
            queryMap.remove("relateName");
            return queryMap;
        }
    
        /**
         * byte数组->xml对应解析
         *
         * @param childNode
         * @param queryMap
         * @param numList
         * @return
         */
        private static Map<String, Object> getData(JSONArray childNode, Map<String, Object> queryMap, List<Integer> numList, String binaryStr, int bigSet, String order, boolean idIndex) {
            List<String> suffixList = new LinkedList<>();
            if (CollectionUtils.isNotEmpty(numList)) {
                if (numList.size() == 1) {
                    suffixList.add(String.valueOf(numList.get(0)));
                } else {
                    for (Integer num : numList) {
                        suffixList.add(String.valueOf(num));
                    }
                }
            }
            for (int j = 0; j < childNode.size(); j++) {
                JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(childNode.get(j)));
                String length = "";
                if (Objects.nonNull(jsonObject.getString("length"))) {
                    length = jsonObject.getString("length");
                }
                if (StringUtils.isEmpty(jsonObject.getString("name")) && StringUtils.isNotBlank(length)) {
                    bigSet += Integer.parseInt(length);
                    continue;
                }
                String englishName = "";
                if ((CollectionUtils.isNotEmpty(suffixList) && idIndex) && childNode.size() == suffixList.size()) {
                    englishName = jsonObject.getString("name_e") + suffixList.get(j);
                } else {
                    englishName = jsonObject.getString("name_e");
                }
                if (CollectionUtils.isNotEmpty(jsonObject.getJSONArray(jsonObject.getString("label") + "Child"))) {
                    JSONArray groupList = jsonObject.getJSONArray(jsonObject.getString("label") + "Child");
                    StringBuilder value = new StringBuilder();
                    if (jsonObject.getString("label").equals("group")) {
                        String[] groupSp;
                        List<Object> collect = groupList.stream().filter(s -> Objects.nonNull(JSONObject.parseObject(JSON.toJSONString(s)).get("position")) && JSONObject.parseObject(JSON.toJSONString(s)).get("position").equals("true")).collect(Collectors.toList());
                        boolean flag = true;
                        for (Object item : groupList) {
                            JSONObject branchObject = JSONObject.parseObject(JSON.toJSONString(item));
                            groupSp = length.split(",");
                            if (CollectionUtils.isNotEmpty(collect) && flag) {
                                value = new StringBuilder(branchObject.getString("name"));
                                flag = false;
                            } else if (CollectionUtils.isNotEmpty(collect) && Integer.parseInt(JSONObject.parseObject(JSON.toJSONString(item)).getString("position")) > 1) {
                                int branchLength = Integer.parseInt(groupSp[branchObject.getInteger("position") - 2]);
                                if (bigSet >= binaryStr.length()) {
                                    return queryMap;
                                }
                                String substring = binaryStr.substring(bigSet, bigSet + branchLength);
                                BigInteger num = new BigInteger(substring, 2);
                                value.append(num).append(branchObject.getString("name"));
                                bigSet += branchLength;
                            } else {
                                int branchLength = Integer.parseInt(groupSp[branchObject.getInteger("position") - 1]);
                                if (bigSet >= binaryStr.length()) {
                                    return queryMap;
                                }
                                String substring = binaryStr.substring(bigSet, bigSet + branchLength);
                                BigInteger num = new BigInteger(substring, 2);
                                value.append(num).append(branchObject.getString("name"));
                                bigSet += branchLength;
                            }
                        }
                        queryMap.put(englishName, value.toString());
                    } else if (jsonObject.getString("label").equals("segment")) {
                        int longLength = Integer.parseInt(length);
                        if (bigSet >= binaryStr.length()) {
                            return queryMap;
                        }
                        String substring = binaryStr.substring(bigSet, bigSet + longLength);
                        for (Object segmentObj : groupList) {
                            JSONObject valueObject = JSONObject.parseObject(JSON.toJSONString(segmentObj));
                            String number = valueObject.getString("number");
                            if (number.contains("0x")) {
                                number = number.replace("0x", "");
                                BigInteger tenValue = new BigInteger(number, 16);
                                BigInteger twoToTen = new BigInteger(substring, 2);
                                if (tenValue.equals(twoToTen)) {
                                    value.append(valueObject.getString("name"));
                                }
                            }
                        }
                        if (StringUtils.isBlank(value.toString())) {
                            List<Object> collect = groupList.stream().filter(s -> Objects.nonNull(JSONObject.parseObject(JSON.toJSONString(s)).get("number")) && JSONObject.parseObject(JSON.toJSONString(s)).get("number").equals("true")).collect(Collectors.toList());
                            if (CollectionUtils.isNotEmpty(collect)) {
                                value.append(JSONObject.parseObject(JSON.toJSONString(collect.get(0))).getString("name"));
                            }
                        }
                        queryMap.put(englishName, value);
                        if (StringUtils.isNotEmpty(jsonObject.getString("relateloop"))) {
                            BigInteger loopNum = new BigInteger(substring, 2);
                            queryMap.put("relateNum", loopNum);
                            queryMap.put("relateName", jsonObject.getString("relateloop"));
                        }
                        bigSet += longLength;
                    } else if (jsonObject.getString("label").equals("loop")) {
                        Integer loopTime = 0;
                        if (Objects.nonNull(jsonObject.get("relateloop")) && jsonObject.getString("relateloop").equals("true")) {
                            Object name = queryMap.get(jsonObject.getString("name"));
                            if (Objects.nonNull(name)) {
                                loopTime = Integer.valueOf(queryMap.get("relateNum").toString());
                            }
                        } else {
                            loopTime = jsonObject.getInteger("looptime");
                        }
                        if (Objects.nonNull(jsonObject.get("isRemoved"))) {
                            Integer isRemoved = jsonObject.getInteger("isRemoved");
                            loopTime = loopTime / isRemoved;
                        }
                        boolean isIndex = false;
                        if (Objects.nonNull(jsonObject.get("isIndex"))) {
                            isIndex = jsonObject.getBoolean("isIndex");
                        }
                        int count = 1;
                        JSONArray label = jsonObject.getJSONArray(jsonObject.getString("label") + "Child");
    
                        List<Object> list = new LinkedList<>();
                        if ((Objects.nonNull(jsonObject.get("order")) && jsonObject.getString("order").equals("desc"))) {
                            if (label.size() == 2) {
                                for (int i = 0; i < loopTime; i++) {
                                    Map<String, Object> loopMap = new HashMap<>();
                                    List<Integer> countList = new LinkedList<>();
                                    countList.add(count * 2);
                                    countList.add(count * 2 - 1);
                                    Map<String, Object> desc = getData(label, loopMap, countList, binaryStr, bigSet, "desc", isIndex);
                                    bigSet = Integer.parseInt(desc.get("bigSet").toString());
                                    desc.remove("bigSet");
                                    list.add(desc);
                                    count++;
                                }
                            } else if (label.size() == 4) {
                                for (int i = 0; i < loopTime; i++) {
                                    Map<String, Object> loopMap = new HashMap<>();
                                    List<Integer> countList = new LinkedList<>();
                                    countList.add(count * 4);
                                    countList.add(count * 4 - 1);
                                    countList.add(count * 4 - 2);
                                    countList.add(count * 4 - 3);
                                    Map<String, Object> desc = getData(label, loopMap, countList, binaryStr, bigSet, "desc", isIndex);
                                    bigSet = Integer.parseInt(desc.get("bigSet").toString());
                                    desc.remove("bigSet");
                                    list.add(desc);
                                    count++;
                                }
                            }
                        } else {
                            for (int i = 0; i < loopTime; i++) {
                                Map<String, Object> loopMap = new HashMap<>();
                                List<Integer> countList = new LinkedList<>();
                                countList.add(count);
                                Map<String, Object> data = getData(label, loopMap, countList, binaryStr, bigSet, null, isIndex);
                                bigSet = Integer.parseInt(data.get("bigSet").toString());
                                data.remove("bigSet");
                                list.add(data);
                                count++;
                            }
                        }
                        queryMap.put(englishName, list);
                    } else {
                        Map<String, Object> label = getData(jsonObject.getJSONArray(jsonObject.getString("label") + "Child"), queryMap, null, binaryStr, bigSet, null, false);
                        if (label.get("bigSet") != null) {
                            bigSet = Integer.parseInt(label.get("bigSet").toString());
                            label.remove("bigSet");
                        }
                        queryMap.put(englishName, label);
                    }
                } else {
                    if (bigSet >= binaryStr.length()) {
                        return queryMap;
                    }
                    int longLength = Integer.parseInt(length);
                    String substring = binaryStr.substring(bigSet, bigSet + longLength);
                    bigSet += longLength;
                    BigInteger bigInteger = new BigInteger(substring, 2);
                    if (CollectionUtils.isNotEmpty(suffixList)) {
                        queryMap.put(englishName + suffixList.get(j), bigInteger);
                    } else {
                        queryMap.put(englishName, bigInteger);
                    }
    
                }
            }
            queryMap.put("bigSet", bigSet);
            return queryMap;
        }
    
    
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130
    • 131
    • 132
    • 133
    • 134
    • 135
    • 136
    • 137
    • 138
    • 139
    • 140
    • 141
    • 142
    • 143
    • 144
    • 145
    • 146
    • 147
    • 148
    • 149
    • 150
    • 151
    • 152
    • 153
    • 154
    • 155
    • 156
    • 157
    • 158
    • 159
    • 160
    • 161
    • 162
    • 163
    • 164
    • 165
    • 166
    • 167
    • 168
    • 169
    • 170
    • 171
    • 172
    • 173
    • 174
    • 175
    • 176
    • 177
    • 178
    • 179
    • 180
    • 181
    • 182
    • 183
    • 184
    • 185
    • 186
    • 187
    • 188
    • 189
    • 190
    • 191
    • 192
    • 193
    • 194
    • 195
    • 196
    • 197
    • 198
    • 199
    • 200
    • 201
    • 202
    • 203
    • 204
    • 205
    • 206
    • 207
    • 208
    • 209
    • 210
    • 211
    • 212
    • 213
    • 214
    • 215
    • 216
    • 217
    • 218
    • 219
    • 220
    • 221
    • 222
    • 223
    • 224
    • 225
    • 226
    • 227
    • 228
    • 229
    • 230
    • 231
    • 232
    • 233
    • 234
    • 235
    • 236
    • 237
    • 238
    • 239
    • 240
    • 241
    • 242
    • 243
    • 244
    • 245
    • 246
    • 247
    • 248
    • 249
    • 250
    • 251
    • 252
    • 253
    • 254
    • 255
    • 256
    • 257
    • 258
    • 259
    • 260
    • 261
    • 262
    • 263
    • 264
    • 265
    • 266
    • 267
    • 268
    • 269
    • 270
    • 271
    • 272
    • 273
    • 274
    • 275
    • 276
    • 277
    • 278
    • 279
    • 280
    • 281
    • 282
    • 283
    • 284
    • 285
    • 286
    • 287
    • 288
    • 289
    • 290
    • 291
    • 292
    • 293
    • 294
    • 295
    • 296
    • 297
    • 298
    • 299
    • 300
    • 301
    • 302
    • 303
    • 304
    • 305
    • 306
    • 307
    • 308
    • 309
    • 310
    • 311
    • 312
    • 313
    • 314
    • 315
    • 316
    • 317
    • 318
    • 319
    • 320
    • 321
    • 322
    • 323
    • 324
    • 325
    • 326
    • 327
    • 328
    • 329
    • 330
    • 331
    • 332
    • 333
    • 334
    • 335
    • 336
    • 337
    • 338
    • 339
    • 340
    • 341
    • 342
    • 343
    • 344
    • 345
    • 346
    • 347
    • 348
    • 349
    • 350
    • 351
    • 352
    • 353
    • 354
    • 355
    • 356
    • 357
    • 358
    • 359
    • 360
    • 361
    • 362
    • 363
    • 364
    • 365
    • 366
    • 367
    • 368
    • 369
    • 370
    • 371
    • 372
    • 373
    • 374
    • 375
    • 376
    • 377
    • 378
    • 379
    • 380
    • 381
    • 382
    • 383
    • 384
    • 385
    • 386
    • 387
    • 388
    • 389
    • 390
    • 391
    • 392
    • 393
    • 394
    • 395
    • 396
    • 397
    • 398
    • 399
    • 400
    • 401
    • 402
    • 403
    • 404
    • 405
    • 406
    • 407
    • 408
    • 409
    • 410
    • 411
    • 412
    • 413
    • 414
    • 415
    • 416
    • 417
    • 418
    • 419
    • 420
    • 421
    • 422
    • 423
    • 424
    • 425
    • 426
    • 427
    • 428
    • 429
    • 430
    • 431
    • 432
    • 433
    • 434
    • 435
    • 436
    • 437
    • 438
    • 439
    • 440
    • 441
    • 442
    • 443
    • 444
    • 445
    • 446
    • 447
    • 448
    • 449
    • 450
    • 451
    • 452
    • 453
    • 454
    • 455
    • 456
    • 457
    • 458
    • 459
    • 460
    • 461
    • 462
    • 463
    • 464
    • 465
    • 466
    • 467
    • 468
    • 469
    • 470
    • 471
    • 472
    • 473
    • 474
    • 475
    • 476
    • 477
    • 478
    • 479
    • 480
    • 481
    • 482
    • 483
    • 484
    • 485
    • 486
    • 487
    • 488
    • 489
    • 490
    • 491
    • 492
    • 493
    • 494
    • 495
    • 496
    • 497
    • 498
    • 499
    • 500
    • 501
    • 502
    • 503
    • 504
    • 505
    • 506
    • 507
    • 508
    • 509
    • 510
    • 511
    • 512
    • 513
    • 514
    • 515
    • 516
    • 517
    • 518
    • 519
    • 520
    • 521
    • 522
    • 523
    • 524
    • 525
    • 526
    • 527
    • 528
    • 529
    • 530
    • 531
    • 532
    • 533
    • 534
    • 535
    • 536
    • 537
    • 538
    • 539
    • 540
    • 541
    • 542
    • 543
    • 544
    • 545
    • 546
    • 547
    • 548
    • 549
    • 550
    • 551
    • 552
    • 553
    • 554
    • 555
    • 556
    • 557
    • 558
    • 559
    • 560
    • 561
    • 562
    • 563
    • 564
    • 565
    • 566
    • 567
    • 568
    • 569
    • 570
    • 571
    • 572
    • 573
    • 574
    • 575
    • 576
    • 577
    • 578
    • 579
    • 580
    • 581
    • 582
    • 583
    • 584
    • 585
    • 586
    • 587
    • 588
    • 589
    • 590
    • 591
    • 592
    • 593
    • 594
    • 595
    • 596
    • 597
    • 598
    • 599
    • 600
    • 601
    • 602
    • 603
    • 604
    • 605
    • 606
    • 607
    • 608
    • 609
    • 610
    • 611
    • 612
    • 613
    • 614
    • 615
    • 616
    • 617
    • 618
    • 619
    • 620
    • 621
    • 622
    • 623
    • 624
    • 625
    • 626
    • 627
    • 628
    • 629
    • 630
    • 631
    • 632
    • 633
    • 634
    • 635
    • 636
    • 637
    • 638
    • 639
    • 640
    • 641
    • 642
    • 643
    • 644
    • 645
    • 646
    • 647
    • 648
    • 649
    • 650
    • 651
    • 652
    • 653
    • 654
    • 655
    • 656
    • 657
    • 658
    • 659
    • 660
    • 661
    • 662
    • 663
    • 664
    • 665
    • 666
    • 667
    • 668
    • 669
    • 670
    • 671
  • 相关阅读:
    pycharm终端pip安装模块成功但还是显示找不到 ModuleNotFoundError: No module named
    2022亚马逊云科技re:Invent科创风尚,抢占下一个万亿赛道
    未来战争机器人
    【java】IO流
    bfs模板总结
    02_SpringSecurity学习之多种配置共存
    Linux生产者消费者模型
    c++day6
    基于ECS搭建云上博客
    物联网的未来:连接的智能世界
  • 原文地址:https://blog.csdn.net/weixin_44684812/article/details/115664123