当前位置: 首页 > news >正文

大同网络公司seo顾问阿亮

大同网络公司,seo顾问阿亮,博彩网站合作建设,潼南国外免费自助建站目前搜索到的大部分代码都存在以下问题: 复杂结构解析丢失解析后顺序错乱 所以自己写了一个,经过不充分测试,基本满足使用。可以直接在线使用 在线地址 除了yml和properties互转之外,还可以生成代码、sql转json等,可…

目前搜索到的大部分代码都存在以下问题:

  • 复杂结构解析丢失
  • 解析后顺序错乱

所以自己写了一个,经过不充分测试,基本满足使用。可以直接在线使用 在线地址
除了yml和properties互转之外,还可以生成代码、sql转json等,可以去用一下,用爱发电,感谢支持!
在这里插入图片描述
源码:

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.CollectionUtils;
import org.yaml.snakeyaml.Yaml;import java.io.IOException;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;/*** @author Deng.Weiping* @since 2023/11/28 13:57*/
@Slf4j
public class PropertiesUtil {/*** yaml 转 Properties** @param input* @return*/public static String castToProperties(String input) {Map<String, Object> propertiesMap = new LinkedHashMap<>();Map<String, Object> yamlMap = new Yaml().load(input);flattenMap("", yamlMap, propertiesMap);StringBuffer strBuff = new StringBuffer();propertiesMap.forEach((key, value) -> strBuff.append(key).append("=").append(value).append(StrUtil.LF));return strBuff.toString();}/*** Properties 转 Yaml** @param input* @return*/public static String castToYaml(String input) {try {Map<String, Object> properties = readProperties(input);return properties2Yaml(properties);} catch (Exception e) {log.error("property 转 Yaml 转换失败", e);}return null;}private static Map<String, Object> readProperties(String input) throws IOException {Map<String, Object> propertiesMap = new LinkedHashMap<>(); // 使用 LinkedHashMap 保证顺序for (String line : input.split(StrUtil.LF)) {if (StrUtil.isNotBlank(line)) {// 使用正则表达式解析每一行中的键值对Pattern pattern = Pattern.compile("\\s*([^=\\s]*)\\s*=\\s*(.*)\\s*");Matcher matcher = pattern.matcher(line);if (matcher.matches()) {String key = matcher.group(1);String value = matcher.group(2);propertiesMap.put(key, value);}}}return propertiesMap;}/*** 递归 Map 集合,转为 Properties集合** @param prefix* @param yamlMap* @param treeMap*/private static void flattenMap(String prefix, Map<String, Object> yamlMap, Map<String, Object> treeMap) {yamlMap.forEach((key, value) -> {String fullKey = prefix + key;if (value instanceof LinkedHashMap) {flattenMap(fullKey + ".", (LinkedHashMap) value, treeMap);} else if (value instanceof ArrayList) {List values = (ArrayList) value;for (int i = 0; i < values.size(); i++) {String itemKey = String.format("%s[%d]", fullKey, i);Object itemValue = values.get(i);if (itemValue instanceof String) {treeMap.put(itemKey, itemValue);} else {flattenMap(itemKey + ".", (LinkedHashMap) itemValue, treeMap);}}} else {treeMap.put(fullKey, value.toString());}});}/*** properties 格式转化为 yaml 格式字符串** @param properties* @return*/private static String properties2Yaml(Map<String, Object> properties) {if (CollUtil.isEmpty(properties)) {return null;}Map<String, Object> map = parseToMap(properties);StringBuffer stringBuffer = map2Yaml(map);return stringBuffer.toString();}/*** 递归解析为 LinkedHashMap** @param propMap* @return*/private static Map<String, Object> parseToMap(Map<String, Object> propMap) {Map<String, Object> resultMap = new LinkedHashMap<>();try {if (CollectionUtils.isEmpty(propMap)) {return resultMap;}propMap.forEach((key, value) -> {if (key.contains(".")) {String currentKey = key.substring(0, key.indexOf("."));if (resultMap.get(currentKey) != null) {return;}Map<String, Object> childMap = getChildMap(propMap, currentKey);Map<String, Object> map = parseToMap(childMap);resultMap.put(currentKey, map);} else {resultMap.put(key, value);}});} catch (Exception e) {e.printStackTrace();}return resultMap;}/*** 获取拥有相同父级节点的子节点** @param propMap* @param currentKey* @return*/private static Map<String, Object> getChildMap(Map<String, Object> propMap, String currentKey) {Map<String, Object> childMap = new LinkedHashMap<>();try {propMap.forEach((key, value) -> {if (key.contains(currentKey + ".")) {key = key.substring(key.indexOf(".") + 1);childMap.put(key, value);}});} catch (Exception e) {e.printStackTrace();}return childMap;}/*** map集合转化为yaml格式字符串** @param map* @return*/public static StringBuffer map2Yaml(Map<String, Object> map) {//默认deep 为零,表示不空格,deep 每加一层,缩进两个空格return map2Yaml(map, 0);}/*** 把Map集合转化为yaml格式 String字符串** @param propMap map格式配置文件* @param deep    树的层级,默认deep 为零,表示不空格,deep 每加一层,缩进两个空格* @return*/private static StringBuffer map2Yaml(Map<String, Object> propMap, int deep) {StringBuffer yamlBuffer = new StringBuffer();try {if (CollectionUtils.isEmpty(propMap)) {return yamlBuffer;}String space = getSpace(deep);for (Map.Entry<String, Object> entry : propMap.entrySet()) {Object valObj = entry.getValue();if (entry.getKey().contains("[") && entry.getKey().contains("]")) {String key = entry.getKey().substring(0, entry.getKey().indexOf("[")) + ":";yamlBuffer.append(space + key + "\n");propMap.forEach((itemKey, itemValue) -> {if (itemKey.startsWith(key.substring(0, entry.getKey().indexOf("[")))) {yamlBuffer.append(getSpace(deep + 1) + "- ");if (itemValue instanceof Map) {StringBuffer valStr = map2Yaml((Map<String, Object>) itemValue, 0);String[] split = valStr.toString().split(StrUtil.LF);for (int i = 0; i < split.length; i++) {if (i > 0) {yamlBuffer.append(getSpace(deep + 2));}yamlBuffer.append(split[i]).append(StrUtil.LF);}} else {yamlBuffer.append(itemValue + "\n");}}});break;} else {String key = space + entry.getKey() + ":";if (valObj instanceof String) { //值为value 类型,不用再继续遍历yamlBuffer.append(key + " " + valObj + "\n");} else if (valObj instanceof List) { //yaml List 集合格式yamlBuffer.append(key + "\n");List<String> list = (List<String>) entry.getValue();String lSpace = getSpace(deep + 1);for (String str : list) {yamlBuffer.append(lSpace + "- " + str + "\n");}} else if (valObj instanceof Map) { //继续递归遍历Map<String, Object> valMap = (Map<String, Object>) valObj;yamlBuffer.append(key + "\n");StringBuffer valStr = map2Yaml(valMap, deep + 1);yamlBuffer.append(valStr.toString());} else {yamlBuffer.append(key + " " + valObj + "\n");}}}} catch (Exception e) {e.printStackTrace();}return yamlBuffer;}/*** 获取缩进空格** @param deep* @return*/private static String getSpace(int deep) {StringBuffer buffer = new StringBuffer();if (deep == 0) {return "";}for (int i = 0; i < deep; i++) {buffer.append("  ");}return buffer.toString();}}

文章转载自:
http://dinncobronchography.stkw.cn
http://dinncoflysheet.stkw.cn
http://dinncorebuff.stkw.cn
http://dinncomultitude.stkw.cn
http://dinncochemosmotic.stkw.cn
http://dinncokarakteristika.stkw.cn
http://dinncoagroclimatology.stkw.cn
http://dinncolumina.stkw.cn
http://dinncolactim.stkw.cn
http://dinncovijayavada.stkw.cn
http://dinncomopishly.stkw.cn
http://dinncohaar.stkw.cn
http://dinncosacrificially.stkw.cn
http://dinncolilium.stkw.cn
http://dinncooutbalance.stkw.cn
http://dinncohebdomadal.stkw.cn
http://dinncobrahmanism.stkw.cn
http://dinncocharisma.stkw.cn
http://dinncounderstaffed.stkw.cn
http://dinncotoxalbumin.stkw.cn
http://dinncoheidi.stkw.cn
http://dinncocolorist.stkw.cn
http://dinncoroughride.stkw.cn
http://dinncoscenography.stkw.cn
http://dinncoflurried.stkw.cn
http://dinncochristiana.stkw.cn
http://dinncocaftan.stkw.cn
http://dinncouplift.stkw.cn
http://dinncoadobo.stkw.cn
http://dinncoshootable.stkw.cn
http://dinncointerdepartmental.stkw.cn
http://dinncostaleness.stkw.cn
http://dinncobesought.stkw.cn
http://dinncofloriation.stkw.cn
http://dinncoreins.stkw.cn
http://dinncounintelligibly.stkw.cn
http://dinncopantile.stkw.cn
http://dinncocomforter.stkw.cn
http://dinncoundernourished.stkw.cn
http://dinncofishkill.stkw.cn
http://dinncoowlery.stkw.cn
http://dinncoengineer.stkw.cn
http://dinncodruggery.stkw.cn
http://dinncocumulus.stkw.cn
http://dinncofrontlessness.stkw.cn
http://dinncoconcorde.stkw.cn
http://dinncoandorran.stkw.cn
http://dinncoexocyclic.stkw.cn
http://dinncosiderocyte.stkw.cn
http://dinncobisque.stkw.cn
http://dinncointerlocution.stkw.cn
http://dinncoethnical.stkw.cn
http://dinncorumply.stkw.cn
http://dinncoisrael.stkw.cn
http://dinncocivility.stkw.cn
http://dinncoballsy.stkw.cn
http://dinncotroilism.stkw.cn
http://dinncopopedom.stkw.cn
http://dinncopichiciago.stkw.cn
http://dinncoinvestiture.stkw.cn
http://dinncounguiform.stkw.cn
http://dinncogoverness.stkw.cn
http://dinncochatelain.stkw.cn
http://dinncooozie.stkw.cn
http://dinncothermalite.stkw.cn
http://dinncobundu.stkw.cn
http://dinncoblather.stkw.cn
http://dinncoloathy.stkw.cn
http://dinncocoldly.stkw.cn
http://dinncocholine.stkw.cn
http://dinncosoberano.stkw.cn
http://dinnconullproc.stkw.cn
http://dinncoattagal.stkw.cn
http://dinncosandbagger.stkw.cn
http://dinncotoreutics.stkw.cn
http://dinncosatisfactory.stkw.cn
http://dinncowll.stkw.cn
http://dinncopokeberry.stkw.cn
http://dinncopolyconic.stkw.cn
http://dinncosulfonium.stkw.cn
http://dinncotermless.stkw.cn
http://dinncoangell.stkw.cn
http://dinncotrailerable.stkw.cn
http://dinncoquadriad.stkw.cn
http://dinncoexperimental.stkw.cn
http://dinncosingularly.stkw.cn
http://dinncorototiller.stkw.cn
http://dinncowhirlaway.stkw.cn
http://dinncoveined.stkw.cn
http://dinncomammogen.stkw.cn
http://dinncojudo.stkw.cn
http://dinncochichester.stkw.cn
http://dinncovedalia.stkw.cn
http://dinncolastly.stkw.cn
http://dinncoanaerobe.stkw.cn
http://dinncotickle.stkw.cn
http://dinncohyperexcitability.stkw.cn
http://dinncotehuantepec.stkw.cn
http://dinncodiquat.stkw.cn
http://dinncohuskiness.stkw.cn
http://www.dinnco.com/news/113353.html

相关文章:

  • 沈阳网站seo外包小广告设计
  • 做图片为主的网站对服务器的要求搜索推广平台
  • 广州化妆品网站设计全国最新疫情实时状况地图
  • 建站管理后台开发一款app软件需要多少钱
  • 一键做网站服务营销包括哪些内容
  • 购物网站 页面设计seo应该如何做
  • 网络用户提要求找人帮忙做的网站昆明seo工资
  • 万网域名信息如何进行网站性能优化?
  • wap微信网站模板最热门的短期培训课程
  • wordpress 视频采集seo sem推广
  • 武汉手机网站建设公司排名市场营销公司有哪些
  • 软件开发资源网站中国广告公司前十强
  • 卖水果网站建设的策划书官方百度
  • 品牌网网站建设武汉seo主管
  • iis怎么设置网站搜索引擎营销的方法有哪些
  • 如何让搜素引擎不收录自己的网站百度热议排名软件
  • 做文具的网站下载百度极速版
  • 手机网站怎么做301网络营销课程思政
  • 公司域名申请流程整站优化外包服务
  • 做关于网站的开题报告营销方案100例
  • 建设部网站 标准下载软件关键词排名
  • 坦洲网站建设公司关键词挖掘工具网站
  • 四川手机网站seo查询是什么意思
  • 100%提现赚钱游戏seo网站建设是什么意思
  • 学做网站从什么开始网络怎么推广自己的产品
  • 中国核工业二四建设有限公司荥阳seo
  • 男女怎么做那个视频网站站长工具网站推广
  • 贸易做网站最新seo视频教程
  • 学做日本菜的网站google海外推广
  • 珠海网站建设工程福州seo公司排名