解析小结—自用

解析流程

1 拿到文件

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

RedisUtils

2 转化进制

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

进入解析流程

1.解析XML

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

getChildNode()

知识点

基于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) {
                    /**
                     * 当前节点名字
                     *<category></category>
                     * <segment></segment>
                     * ...
                     */
                    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;
    }


}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值