ES报文辅助生成工具-JavaFX

news2024/9/29 17:29:13

此程序为基于 Java8 开发的 JavaFX Maven 工程,是 Java 组装ElasticSearch请求报文工具的辅助 Java 代码生成工具,方便开发者快速编写代码。现学现用,写得不好。

工具界面

在这里插入图片描述

代码

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.fx</groupId>
  <artifactId>esjson</artifactId>
  <version>1.0.0-SNAPSHOT</version>
  <name>EsjsonFx</name>
  <description>EsjsonFx</description>
  
  <properties>
    <maven.compiler.target>1.8</maven.compiler.target>
    <maven.compiler.source>1.8</maven.compiler.source>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>
  
  <dependencies>
	<dependency>
	    <groupId>com.google.code.gson</groupId>
	    <artifactId>gson</artifactId>
	    <version>2.10</version>
	</dependency>
  </dependencies>
  
  <build>
	<resources>
		<resource>
            <directory>config</directory>
            <targetPath>${project.build.directory}/jfx/app/config</targetPath>
        </resource>
        <resource>
			<!--把src/main/resources目录下的properties、xm文件打包打进程序中-->
			<directory>src/main/resources</directory>
			<includes>
				<include>**/*.properties</include>
				<include>**/*.xml</include>
				<include>**/*.fxml</include>
				<include>**/*.setting</include>
				<include>**/*.png</include>
			</includes>
			<filtering>false</filtering>
		</resource>
	</resources>
	<plugins>
		<plugin>
			<groupId>com.zenjava</groupId>
			<artifactId>javafx-maven-plugin</artifactId>
			<version>8.8.3</version>
			<configuration>
				<!-- 作者 -->
				<vendor></vendor>
				<!-- main方法的类 -->
				<mainClass>com.fx.esjson.MainApplication</mainClass>
				<!-- 运行文件名 -->
				<appName>${project.build.finalName}</appName>
				<!-- 发行版本 -->
				<nativeReleaseVersion>${project.version}</nativeReleaseVersion>
				<!-- 图标的位置,默认位置 src/main/deploy -->
				<!--<deployDir>${basedir}/src/main/resources/icon/icon.png</deployDir>-->
				<!-- 菜单 -->
				<needMenu>true</needMenu>
				<!-- 桌面图标 -->
				<needShortcut>true</needShortcut>
				<source>${maven.compiler.source}</source>
                <target>${maven.compiler.target}</target>
                <encoding>${project.build.sourceEncoding}</encoding>
                <bundleArguments>
                    <icon>${project.basedir}/src/main/resources/icon/icon.png</icon>
                    <!--下面这2个参数搭配,可实现一个特别重要的功能,就是,提示用户手动选择程序安装目录,默认目录是在:C:\Program Files (x86)\appName-->
                    <!--设置为true将在Program Files中安装应用程序。设置为false将应用程序安装到用户的主目录中。默认值为false。-->
                    <systemWide>true</systemWide>
                    <!-- 让用户选择安装目标文件夹 -->
                    <installdirChooser>true</installdirChooser>
                </bundleArguments>
			</configuration>
		</plugin>
	</plugins>
  </build>
</project>

应用图标路径

/src/main/resources/icon/icon.png

CharEnum.java

package com.fx.esjson;

public enum CharEnum {
	DOT("."),
	SPACE(" "),
	DOUBLE_QUOTE("\""),
	NULL("null"),
	COMMA(","),
	CURVE_LEFT("("),
	CURVE_RIGHT(")"),
	;

	private String ch;
	
	private CharEnum (String ch) {
		this.ch = ch;
	}

	public String getCh() {
		return ch;
	}
	
}

LineToken.java

package com.fx.esjson;

import java.util.ArrayList;
import java.util.List;

public class LineToken {

	/**
	 * 缩进次数
	 */
	private Integer indentCnt;
	
	/**
	 * 缩进字符
	 */
	private String indentChar;
	
	/**
	 * 一行中的字符串
	 */
	private List<String> lineStrs;
	
	/**
	 * 是否允许追加到前一个对象
	 */
	private Boolean allowAppendTo;
	
	/**
	 * 是否允许后面的对象追加进来
	 */
	private Boolean canAppendInto;
	
	/**
	 * 是否以左括号结尾
	 */
	private Boolean endsWithCurveLeft;
	
	/**
	 * 是否右括号
	 */
	private Boolean curveRight;

	public Integer getIndentCnt() {
		return indentCnt;
	}

	public void setIndentCnt(Integer indentCnt) {
		this.indentCnt = indentCnt;
	}

	public String getIndentChar() {
		return indentChar;
	}

	public void setIndentChar(String indentChar) {
		this.indentChar = indentChar;
	}

	public List<String> getLineStrs() {
		return lineStrs;
	}

	public void setLineStrs(List<String> lineStrs) {
		this.lineStrs = lineStrs;
	}

	public Boolean getAllowAppendTo() {
		return allowAppendTo;
	}

	public void setAllowAppendTo(Boolean allowAppendTo) {
		this.allowAppendTo = allowAppendTo;
	}
	
	public Boolean getCanAppendInto() {
		return canAppendInto;
	}

	public void setCanAppendInto(Boolean canAppendInto) {
		this.canAppendInto = canAppendInto;
	}

	public Boolean getEndsWithCurveLeft() {
		return endsWithCurveLeft;
	}

	public void setEndsWithCurveLeft(Boolean endsWithCurveLeft) {
		this.endsWithCurveLeft = endsWithCurveLeft;
	}

	public Boolean getCurveRight() {
		return curveRight;
	}

	public void setCurveRight(Boolean curveRight) {
		this.curveRight = curveRight;
	}

	public void appendLineStrs(String... strs) {
		if (strs != null) {
			if (lineStrs == null) {
				lineStrs = new ArrayList<>();
			}
			for (String str : strs) {
				lineStrs.add(str);
			}
		}
	}
	
	public void appendLineStrs(List<String> lineStrs) {
		if (lineStrs != null) {
			if (this.lineStrs == null) {
				this.lineStrs = new ArrayList<>();
			}
			this.lineStrs.addAll(lineStrs);
		}
	}

	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder();
		if (this.indentCnt != null && this.indentChar != null) {
			int cnt = this.indentCnt;
			String ch = this.indentChar;
			for (int i = 0; i < cnt; i++) {
				sb.append(ch);
			}
		}
		if (this.lineStrs != null) {
			List<String> lineStrs = this.lineStrs;
			for (String str : lineStrs) {
				sb.append(str);
			}
		}
		return sb.toString();
	}
	
}

FormatConfig.java

package com.fx.esjson;

public class FormatConfig {
	
	/**
	 * 全限定包名
	 */
	private String fullPackageName;
	
	/**
	 * 缩进次数
	 */
	private Integer indentCnt;
	
	/**
	 * 缩进字符
	 */
	private String indentChar;
	
	/**
	 * 静态kv方法名称
	 */
	private String staticKv;
	
	/**
	 * 动态kv方法名称
	 */
	private String dynamicKv;
	
	/**
	 * 静态数组方法名称
	 */
	private String staticArr;
	
	/**
	 * 动态数组方法名称
	 */
	private String dynamicArr;

	public String getFullPackageName() {
		return fullPackageName;
	}

	public void setFullPackageName(String fullPackageName) {
		this.fullPackageName = fullPackageName;
	}

	public Integer getIndentCnt() {
		return indentCnt;
	}

	public void setIndentCnt(Integer indentCnt) {
		this.indentCnt = indentCnt;
	}

	public String getIndentChar() {
		return indentChar;
	}

	public void setIndentChar(String indentChar) {
		this.indentChar = indentChar;
	}

	public String getStaticKv() {
		return staticKv;
	}

	public void setStaticKv(String staticKv) {
		this.staticKv = staticKv;
	}

	public String getDynamicKv() {
		return dynamicKv;
	}

	public void setDynamicKv(String dynamicKv) {
		this.dynamicKv = dynamicKv;
	}

	public String getStaticArr() {
		return staticArr;
	}

	public void setStaticArr(String staticArr) {
		this.staticArr = staticArr;
	}

	public String getDynamicArr() {
		return dynamicArr;
	}

	public void setDynamicArr(String dynamicArr) {
		this.dynamicArr = dynamicArr;
	}
	
}

CodeFormatUtils.java

核心类

package com.fx.esjson;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.Map.Entry;

import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.JsonPrimitive;

public class CodeFormatUtils {
	
	public static String getStaticPackage(FormatConfig formatConfig) {
		StringBuilder sb = new StringBuilder();
		sb.append("import static ").append(formatConfig.getFullPackageName()).append(CharEnum.DOT.getCh())
				.append("JsonSupport").append(CharEnum.DOT.getCh()).append(formatConfig.getStaticKv()).append(";");
		sb.append("\n");
		sb.append("import static ").append(formatConfig.getFullPackageName()).append(CharEnum.DOT.getCh())
				.append("JsonSupport").append(CharEnum.DOT.getCh()).append(formatConfig.getStaticArr()).append(";");
		return sb.toString();
	}

	public static String getCode (String json, FormatConfig formatConfig) {
		JsonElement element = JsonParser.parseString(json);
		if (!element.isJsonArray() && !element.isJsonObject()) {
			throw new RuntimeException("请在左侧面板输入 json 格式的文本...");
		}
		List<LineToken> list = new ArrayList<>();
		intoList(list, element, formatConfig);
		Iterator<LineToken> iterator = list.iterator();
		
		LineToken prevToken = null;
		while (iterator.hasNext()) {
			LineToken lineToken = iterator.next();
			if (prevToken == null) {
				prevToken = lineToken;
			} else {
				if (prevToken.getCanAppendInto() && lineToken.getAllowAppendTo()) {
					if (!lineToken.getCurveRight() && !prevToken.getEndsWithCurveLeft()) {
						prevToken.appendLineStrs(CharEnum.SPACE.getCh());
					}
					prevToken.appendLineStrs(lineToken.getLineStrs());
					prevToken.setCanAppendInto(lineToken.getCanAppendInto());
					iterator.remove();
				} else {
					prevToken = lineToken;
				}
			}
			
		}
		
		StringBuilder sb = new StringBuilder();
		for (LineToken lineToken : list) {
			if (sb.length() > 0) {
				sb.append("\n");
			}
			sb.append(lineToken.toString());
		}
		sb.append(";");
		return sb.toString();
	}
	
	private static void intoList (List<LineToken> list, JsonElement element, FormatConfig formatConfig) {
		if (element.isJsonObject()) {
			int preCnt = 0 - formatConfig.getIndentCnt();
			if (!list.isEmpty()) {
				int index = list.size() - 1;
				preCnt = list.get(index).getIndentCnt();
			}
			JsonObject jsonObject = element.getAsJsonObject();
			LineToken primaryToken = new LineToken();
			primaryToken.setIndentCnt(formatConfig.getIndentCnt() + preCnt);
			primaryToken.setIndentChar(formatConfig.getIndentChar());
			primaryToken.setAllowAppendTo(false);
			primaryToken.setCanAppendInto(false);
			primaryToken.setEndsWithCurveLeft(false);
			primaryToken.setCurveRight(false);
			primaryToken.appendLineStrs(formatConfig.getStaticKv(), CharEnum.CURVE_LEFT.getCh(), CharEnum.CURVE_RIGHT.getCh());
			list.add(primaryToken);
			Set<Entry<String, JsonElement>> entrySet = jsonObject.entrySet();
			for (Entry<String, JsonElement> entry : entrySet) {
				LineToken startToken = new LineToken();
				startToken.setIndentCnt(formatConfig.getIndentCnt() + preCnt);
				startToken.setIndentChar(formatConfig.getIndentChar());
				startToken.setAllowAppendTo(false);
				startToken.setCanAppendInto(true);
				startToken.setEndsWithCurveLeft(false);
				startToken.setCurveRight(false);
				startToken.appendLineStrs(CharEnum.DOT.getCh(), formatConfig.getDynamicKv(), CharEnum.CURVE_LEFT.getCh(), CharEnum.DOUBLE_QUOTE.getCh(), entry.getKey(), CharEnum.DOUBLE_QUOTE.getCh(), CharEnum.COMMA.getCh());
				list.add(startToken);
				JsonElement value = entry.getValue();
				if (value.isJsonObject() || value.isJsonArray()) {
					intoList(list, value, formatConfig);
				} else {
					primitiveIntoList(list, value, formatConfig);
				}
				LineToken endToken = new LineToken();
				endToken.setIndentCnt(formatConfig.getIndentCnt() + preCnt);
				endToken.setIndentChar(formatConfig.getIndentChar());
				endToken.setAllowAppendTo(true);
				endToken.setCanAppendInto(false);
				endToken.setEndsWithCurveLeft(false);
				endToken.setCurveRight(true);
				endToken.appendLineStrs(CharEnum.CURVE_RIGHT.getCh());
				list.add(endToken);
			}
		} else if (element.isJsonArray()) {
			int preCnt = 0 - formatConfig.getIndentCnt();
			if (!list.isEmpty()) {
				int index = list.size() - 1;
				preCnt = list.get(index).getIndentCnt();
			}
			JsonArray jsonArray = element.getAsJsonArray();
			if (jsonArray.isEmpty()) {
				throw new RuntimeException("ElasticSearch 请求报文不能存在空数组");
			}
			if (isAllString(jsonArray)) {
				list.add(generatePlainArr(jsonArray, true));
			} else if (isAllNonString(jsonArray)) {
				list.add(generatePlainArr(jsonArray, false));
			} else {
				LineToken primaryToken = new LineToken();
				primaryToken.setIndentCnt(formatConfig.getIndentCnt() + preCnt);
				primaryToken.setIndentChar(formatConfig.getIndentChar());
				primaryToken.setAllowAppendTo(false);
				primaryToken.setCanAppendInto(false);
				primaryToken.setEndsWithCurveLeft(false);
				primaryToken.setCurveRight(false);
				primaryToken.appendLineStrs(formatConfig.getStaticArr(), CharEnum.CURVE_LEFT.getCh(), CharEnum.CURVE_RIGHT.getCh());
				list.add(primaryToken);
				for (JsonElement jsonElement : jsonArray) {
					LineToken startToken = new LineToken();
					startToken.setIndentCnt(formatConfig.getIndentCnt() + preCnt);
					startToken.setIndentChar(formatConfig.getIndentChar());
					startToken.setAllowAppendTo(false);
					startToken.setCanAppendInto(true);
					startToken.setEndsWithCurveLeft(true);
					startToken.setCurveRight(false);
					startToken.appendLineStrs(CharEnum.DOT.getCh(), formatConfig.getDynamicArr(), CharEnum.CURVE_LEFT.getCh());
					list.add(startToken);
					intoList(list, jsonElement, formatConfig);
					LineToken endToken = new LineToken();
					endToken.setIndentCnt(formatConfig.getIndentCnt() + preCnt);
					endToken.setIndentChar(formatConfig.getIndentChar());
					endToken.setAllowAppendTo(true);
					endToken.setCanAppendInto(false);
					endToken.setEndsWithCurveLeft(false);
					endToken.setCurveRight(true);
					endToken.appendLineStrs(CharEnum.CURVE_RIGHT.getCh());
					list.add(endToken);
				}
			}
		} else {
			primitiveIntoList(list, element, formatConfig);
		}
	}
	
	private static void primitiveIntoList (List<LineToken> list, JsonElement element, FormatConfig formatConfig) {
		int preCnt = 0 - formatConfig.getIndentCnt();
		if (!list.isEmpty()) {
			int index = list.size() - 1;
			preCnt = list.get(index).getIndentCnt();
		}
		if (element.isJsonNull()) {
			throw new RuntimeException("ElasticSearch 请求报文不能包含 null");
		} else if (element.isJsonPrimitive()) {
			JsonPrimitive primitive = element.getAsJsonPrimitive();
			if (primitive.isBoolean() || primitive.isNumber()) {
				LineToken lineToken = new LineToken();
				lineToken.setIndentCnt(formatConfig.getIndentCnt() + preCnt);
				lineToken.setIndentChar(formatConfig.getIndentChar());
				lineToken.setAllowAppendTo(true);
				lineToken.setCanAppendInto(true);
				lineToken.setEndsWithCurveLeft(false);
				lineToken.setCurveRight(false);
				String str = primitive.getAsString();
				if (isLong(str)) {
					lineToken.appendLineStrs(str, "L");
				} else {
					lineToken.appendLineStrs(str);
				}
				list.add(lineToken);
			} else if (primitive.isString()) {
				LineToken lineToken = new LineToken();
				lineToken.setIndentCnt(formatConfig.getIndentCnt() + preCnt);
				lineToken.setIndentChar(formatConfig.getIndentChar());
				lineToken.setAllowAppendTo(true);
				lineToken.setCanAppendInto(true);
				lineToken.setEndsWithCurveLeft(false);
				lineToken.setCurveRight(false);
				lineToken.appendLineStrs(CharEnum.DOUBLE_QUOTE.getCh(), primitive.getAsString(), CharEnum.DOUBLE_QUOTE.getCh());
				list.add(lineToken);
			}
		}
	}
	
	private static boolean isAllString (JsonArray jsonArray) {
		for (JsonElement jsonElement : jsonArray) {
			if (jsonElement.isJsonPrimitive()) {
				JsonPrimitive primitive = jsonElement.getAsJsonPrimitive();
				if (!primitive.isString()) {
					return false;
				}
			} else {
				return false;
			}
		}
		return true;
	}
	
	private static boolean isAllNonString (JsonArray jsonArray) {
		for (JsonElement jsonElement : jsonArray) {
			if (jsonElement.isJsonNull()) {
				throw new RuntimeException("ElasticSearch 请求报文不能包含 null");
			}
			if (jsonElement.isJsonPrimitive()) {
				JsonPrimitive primitive = jsonElement.getAsJsonPrimitive();
				if (primitive.isString()) {
					return false;
				}
			} else {
				return false;
			}
		}
		return true;
	}
	
	private static LineToken generatePlainArr (JsonArray jsonArray, boolean isString) {
		LineToken primaryToken = new LineToken();
		primaryToken.setIndentCnt(0);
		primaryToken.setIndentChar("");
		primaryToken.setAllowAppendTo(true);
		primaryToken.setCanAppendInto(true);
		primaryToken.setEndsWithCurveLeft(false);
		primaryToken.setCurveRight(false);
		StringBuilder sb = new StringBuilder();
		sb.append(CharEnum.CURVE_LEFT.getCh())
			.append(CharEnum.CURVE_RIGHT.getCh())
			.append(CharEnum.SPACE.getCh())
			.append("->")
			.append(CharEnum.SPACE.getCh())
			.append("Stream")
			.append(CharEnum.DOT.getCh())
			.append("of")
			.append(CharEnum.CURVE_LEFT.getCh());
		int i = 0;
		if (isString) {
			for (JsonElement jsonElement : jsonArray) {
				if (i > 0) {
					sb.append(CharEnum.COMMA.getCh()).append(CharEnum.SPACE.getCh());
				} else {
					i++;
				}
				sb.append(CharEnum.DOUBLE_QUOTE.getCh()).append(jsonElement.getAsString()).append(CharEnum.DOUBLE_QUOTE.getCh());
			}
		} else {
			for (JsonElement jsonElement : jsonArray) {
				if (i > 0) {
					sb.append(CharEnum.COMMA.getCh()).append(CharEnum.SPACE.getCh());
				} else {
					i++;
				}
				String str = jsonElement.getAsString();
				if (isLong(str)) {
					sb.append(str).append("L");
				} else {
					sb.append(str);
				}
			}
		}
		sb.append(CharEnum.CURVE_RIGHT.getCh())
			.append(CharEnum.DOT.getCh())
			.append("collect")
			.append(CharEnum.CURVE_LEFT.getCh())
			.append("Collectors")
			.append(CharEnum.DOT.getCh())
			.append("toList")
			.append(CharEnum.CURVE_LEFT.getCh())
			.append(CharEnum.CURVE_RIGHT.getCh())
			.append(CharEnum.CURVE_RIGHT.getCh());
			
		primaryToken.appendLineStrs(sb.toString());
		return primaryToken;
	}
	
	private static boolean isLong (String str) {
		if (str == null) {
			return false;
		}
		if (!str.matches("^-?\\d+$")) {
			return false;
		}
		long longValue = Long.valueOf(str).longValue();
		if (longValue < Integer.MIN_VALUE || longValue > Integer.MAX_VALUE) {
			return true;
		}
		return false;
	}
	
}

FileUtils.java

用于持久化

package com.fx.esjson;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.nio.charset.StandardCharsets;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

public final class FileUtils {

	private FileUtils () {}
	
	public static String readFileToString (File file) throws IOException {
		String content = "";
		StringBuilder sb = new StringBuilder();
		try (
				BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8));
				) {
			int i = 0;
			while ((content = reader.readLine()) != null) {
				if (i > 0) {
					sb.append("\n");
				} else {
					i++;
				}
				sb.append(content);
			}
		}
		return sb.toString();
	}
	
	public static void writeFile (File file, String str) throws IOException {
		try (
				BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8));
				) {
			writer.write(str);
			writer.flush();
		}
	}
	
	public static FormatConfig defaultConfig () {
		FormatConfig formatConfig = new FormatConfig();
		formatConfig.setFullPackageName("com.fx.learn");
		formatConfig.setIndentCnt(4);
		formatConfig.setIndentChar(" ");
		formatConfig.setStaticKv("KV");
		formatConfig.setDynamicKv("kv");
		formatConfig.setStaticArr("L");
		formatConfig.setDynamicArr("l");
		return formatConfig;
	}
	
	public static FormatConfig readConfig () {
		FormatConfig defaultConfig = defaultConfig();
		return readConfig(defaultConfig);
	}
	
	private static FormatConfig readConfig (FormatConfig defaultConfig) {
		try {
			File dir = new File("config");
			if (!dir.exists()) {
				dir.mkdirs();
			}
			File file = new File(dir, "config.json");
			if (!file.exists()) {
				file.createNewFile();
			}
			String str = readFileToString(file);
			if (str == null || str.isEmpty()) {
				return defaultConfig;
			}
			Gson gson = new Gson();
			FormatConfig formatConfig = gson.fromJson(str, FormatConfig.class);
			if (formatConfig == null) {
				return defaultConfig;
			}
			if (formatConfig.getFullPackageName() == null || !formatConfig.getFullPackageName().matches("^[a-zA-Z0-9_\\.]{0,256}$")) {
				formatConfig.setFullPackageName(defaultConfig.getFullPackageName());
			}
			if (!" ".equals(formatConfig.getIndentChar()) && !"\t".equals(formatConfig.getIndentChar())) {
				formatConfig.setIndentChar(defaultConfig.getIndentChar());
			}
			Integer indentCnt = formatConfig.getIndentCnt();
			if (indentCnt == null || indentCnt < 0 || indentCnt > 8) {
				if (" ".equals(formatConfig.getIndentChar())) {
					formatConfig.setIndentCnt(4);
				} else {
					formatConfig.setIndentCnt(1);
				}
			}
			if (formatConfig.getStaticKv() == null || !formatConfig.getStaticKv().matches("^[a-zA-Z_]{1}[0-9a-zA-Z_]{0,63}$")) {
				formatConfig.setStaticKv(defaultConfig.getStaticKv());
			}
			if (formatConfig.getDynamicKv() == null || !formatConfig.getDynamicKv().matches("^[a-zA-Z_]{1}[0-9a-zA-Z_]{0,63}$")) {
				formatConfig.setDynamicKv(defaultConfig.getDynamicKv());
			}
			if (formatConfig.getStaticArr() == null || !formatConfig.getStaticArr().matches("^[a-zA-Z_]{1}[0-9a-zA-Z_]{0,63}$")) {
				formatConfig.setStaticArr(defaultConfig.getStaticArr());
			}
			if (formatConfig.getDynamicArr() == null || !formatConfig.getDynamicArr().matches("^[a-zA-Z_]{1}[0-9a-zA-Z_]{0,63}$")) {
				formatConfig.setDynamicArr(defaultConfig.getDynamicArr());
			}
			return formatConfig;
		} catch (Exception e) {
			return defaultConfig;
		}
	}
	
	public static FormatConfig writeConfig (FormatConfig formatConfig) {
		File dir = new File("config");
		if (!dir.exists()) {
			dir.mkdirs();
		}
		File file = new File(dir, "config.json");
		if (!file.exists()) {
			try {
				file.createNewFile();
			} catch (IOException e) {
			}
		}
		if (formatConfig == null) {
			FormatConfig defaultConfig = defaultConfig();
			try {
				String str = readFileToString(file);
				if (str == null || str.isEmpty()) {
					Gson gson = new GsonBuilder().setPrettyPrinting().create();
					writeFile(file, gson.toJson(defaultConfig));
				}
				Gson gson1 = new Gson();
				FormatConfig fromJson = gson1.fromJson(str, FormatConfig.class);
				if (fromJson == null) {
					Gson gson = new GsonBuilder().setPrettyPrinting().create();
					writeFile(file, gson.toJson(defaultConfig));
				}
			} catch (IOException e) {
			}
			return defaultConfig;
		} else {
			try {
				Gson gson = new GsonBuilder().setPrettyPrinting().create();
				writeFile(file, gson.toJson(formatConfig));
			} catch (IOException e) {
			}
			return formatConfig;
		}
		
	}
	
	public static void copyProperties (FormatConfig source, FormatConfig target) {
		target.setFullPackageName(source.getFullPackageName());
		target.setStaticKv(source.getStaticKv());
		target.setDynamicKv(source.getDynamicKv());
		target.setStaticArr(source.getStaticArr());
		target.setDynamicArr(source.getDynamicArr());
		target.setIndentChar(source.getIndentChar());
		target.setIndentCnt(source.getIndentCnt());
	}
	
	public static boolean equals (FormatConfig source, FormatConfig target) {
		if (!source.getFullPackageName().equals(target.getFullPackageName())) {
			return false;
		}
		if (!source.getStaticKv().equals(target.getStaticKv())) {
			return false;
		}
		if (!source.getDynamicKv().equals(target.getDynamicKv())) {
			return false;
		}
		if (!source.getStaticArr().equals(target.getStaticArr())) {
			return false;
		}
		if (!source.getDynamicArr().equals(target.getDynamicArr())) {
			return false;
		}
		if (!source.getIndentChar().equals(target.getIndentChar())) {
			return false;
		}
		if (source.getIndentCnt().compareTo(target.getIndentCnt()) != 0) {
			return false;
		}
		return true;
	}
	
	public static void writeLastInput (String str) {
		File dir = new File("history");
		if (!dir.exists()) {
			if (str == null || str.length() == 0) {
				return;
			}
			dir.mkdirs();
		}
		File file = new File(dir, "last-input.txt");
		if (!file.exists() && (str == null || str.length() == 0)) {
			return;
		}
		try {
			writeFile(file, str);
		} catch (IOException e) {
		}
	}
	
	public static String readLastInput () {
		File dir = new File("history");
		if (!dir.exists()) {
			return "";
		}
		File file = new File(dir, "last-input.txt");
		if (!file.exists() || !file.isFile()) {
			return "";
		}
		try {
			return readFileToString(file);
		} catch (IOException e) {
			return "";
		}
	}
}

ConfigScheduledService.java

保存配置的任务

package com.fx.esjson;

import javafx.concurrent.ScheduledService;
import javafx.concurrent.Task;

public class ConfigScheduledService extends ScheduledService<Void> {
	
	private volatile FormatConfig oldConfig;
	
	private volatile FormatConfig newConfig;

	public ConfigScheduledService(FormatConfig oldConfig, FormatConfig newConfig) {
		super();
		this.oldConfig = oldConfig;
		this.newConfig = newConfig;
	}

	@Override
	protected Task<Void> createTask() {
		
		return new Task<Void>() {

			@Override
			protected Void call() throws Exception {
				if (FileUtils.equals(ConfigScheduledService.this.oldConfig, ConfigScheduledService.this.newConfig)) {
					return null;
				}
				FileUtils.copyProperties(ConfigScheduledService.this.newConfig, ConfigScheduledService.this.oldConfig);
				FileUtils.writeConfig(oldConfig);
				return null;
			}
		};
	}

}

FormatScheduledService.java

生成java代码的任务

package com.fx.esjson;

import javafx.concurrent.ScheduledService;
import javafx.concurrent.Task;
import javafx.scene.control.TextArea;

public class FormatScheduledService extends ScheduledService<Void> {
	
	private volatile FormatConfig oldConfig;
	
	private TextArea rightTopTextArea;
	
	private TextArea rightCenterTextArea;
	
	private volatile String[] leftTextAreaValue;
	
	private volatile FormatConfig tempFormatConfig = new FormatConfig();
	
	private volatile String oldJsonSource = "";
	
	private volatile String rightTopTextOld = "";
	
	private volatile String rightTopTextNew = "";
	
	private volatile String rightCenterText = "";
	
	private volatile boolean exception = false;

	public FormatScheduledService(FormatConfig oldConfig, TextArea rightTopTextArea,
			TextArea rightCenterTextArea, String[] leftTextAreaValue) {
		super();
		this.oldConfig = oldConfig;
		this.rightTopTextArea = rightTopTextArea;
		this.rightCenterTextArea = rightCenterTextArea;
		this.leftTextAreaValue = leftTextAreaValue;
		FileUtils.copyProperties(oldConfig, this.tempFormatConfig);
	}

	@Override
	protected Task<Void> createTask() {
		return new Task<Void>() {

			@Override
			protected Void call() throws Exception {
				FormatScheduledService.this.rightTopTextNew = CodeFormatUtils.getStaticPackage(FormatScheduledService.this.oldConfig);
				if (FileUtils.equals(FormatScheduledService.this.tempFormatConfig, FormatScheduledService.this.oldConfig)) {
					if (FormatScheduledService.this.oldJsonSource.equals(FormatScheduledService.this.leftTextAreaValue[0])) {
						return null;
					}
				} else {
					FileUtils.copyProperties(FormatScheduledService.this.oldConfig, FormatScheduledService.this.tempFormatConfig);
				}
				FormatScheduledService.this.oldJsonSource = FormatScheduledService.this.leftTextAreaValue[0];
				if (FormatScheduledService.this.oldJsonSource.length() != 0) {
					try {
						FormatScheduledService.this.rightCenterText = CodeFormatUtils.getCode(FormatScheduledService.this.oldJsonSource, FormatScheduledService.this.oldConfig);
						FormatScheduledService.this.exception = false;
					} catch (Exception e) {
						FormatScheduledService.this.exception = true;
						FormatScheduledService.this.rightCenterText = e.getMessage();
					}
				} else {
					FormatScheduledService.this.exception = false;
					FormatScheduledService.this.rightCenterText = "";
				}
				return null;
			}

			@Override
			protected void updateValue(Void value) {
				super.updateValue(value);
				if (!FormatScheduledService.this.rightTopTextNew.equals(FormatScheduledService.this.rightTopTextOld)) {
					FormatScheduledService.this.rightTopTextOld = FormatScheduledService.this.rightTopTextNew;
					FormatScheduledService.this.rightTopTextArea.setText(FormatScheduledService.this.rightTopTextOld);
				}
				String text = FormatScheduledService.this.rightCenterTextArea.getText();
				if (!FormatScheduledService.this.rightCenterText.equals(text)) {
					if (FormatScheduledService.this.exception) {
						FormatScheduledService.this.rightCenterTextArea.setWrapText(true);
						FormatScheduledService.this.rightCenterTextArea.setStyle("-fx-font-size: 1.2em;-fx-text-fill: #CC0000;");
						FormatScheduledService.this.rightCenterTextArea.setText(FormatScheduledService.this.rightCenterText);
						FormatScheduledService.this.rightCenterTextArea.deselect();
					} else {
						FormatScheduledService.this.rightCenterTextArea.setWrapText(false);
						FormatScheduledService.this.rightCenterTextArea.setStyle("-fx-font-size: 1.2em;-fx-text-fill: #202020;");
						FormatScheduledService.this.rightCenterTextArea.setText(FormatScheduledService.this.rightCenterText);
						FormatScheduledService.this.rightCenterTextArea.requestFocus();
						FormatScheduledService.this.rightCenterTextArea.selectAll();
					}
				}
			}
			
		};
	}

}

MainApplication.java

主启动类和 UI 类

package com.fx.esjson;

import javafx.application.Application;
import javafx.application.Platform;
import javafx.geometry.HPos;
import javafx.geometry.Orientation;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.RadioButton;
import javafx.scene.control.Spinner;
import javafx.scene.control.SplitPane;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.control.ToggleGroup;
import javafx.scene.image.Image;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;
import javafx.util.Duration;

public class MainApplication extends Application {
	
	private TextArea leftTextArea;

	public static void main(String[] args) {
		launch(MainApplication.class, args);
	}

	@Override
	public void init() throws Exception {
		FileUtils.writeConfig(null);
	}

	@Override
	public void start(Stage stage) throws Exception {
		stage.setTitle("ES报文辅助生成工具");
		stage.getIcons().add(new Image(getClass().getClassLoader().getResourceAsStream("icon/icon.png")));
		stage.setWidth(900);
		stage.setHeight(600);
		stage.setMinWidth(680);
		stage.setMinHeight(400);
		
		final FormatConfig initConfig = FileUtils.readConfig();
		final FormatConfig newConfig = new FormatConfig();
		FileUtils.copyProperties(initConfig, newConfig);
		
		final String[] leftTextAreaValue = new String[] {""};
		
		BorderPane root = new BorderPane();
		GridPane topGridPane = new GridPane();
		topGridPane.setPrefHeight(100);
		topGridPane.setStyle("-fx-background-color: #F0F0B0;");
		topGridPane.setAlignment(Pos.CENTER);
		topGridPane.setHgap(6);
		topGridPane.setVgap(6);
		
		Label packageLabel = new Label("全限定包名:");
		GridPane.setHalignment(packageLabel, HPos.RIGHT);
		topGridPane.add(packageLabel, 0, 0);
		TextField packageField = new TextField();
		packageField.setText(initConfig.getFullPackageName());
		packageField.setMinWidth(400);
		packageField.textProperty().addListener((observable, oldValue, newValue) -> {
			if (newValue != null && !newValue.matches("^[a-zA-Z0-9_\\.]{0,255}$") && !newValue.equals(oldValue)) {
				packageField.setText(oldValue);
				return;
			}
			newConfig.setFullPackageName(newValue);
		});
		topGridPane.add(packageField, 1, 0, 7, 1);
		
		Label staticKvLabel = new Label("静态键值方法名:");
		GridPane.setHalignment(staticKvLabel, HPos.RIGHT);
		topGridPane.add(staticKvLabel, 0, 1);
		TextField staticKvField = new TextField();
		staticKvField.setText(initConfig.getStaticKv());
		staticKvField.setPrefWidth(50);
		staticKvField.textProperty().addListener((observable, oldValue, newValue) -> {
			if (newValue != null && newValue.length() > 0) {
				if (!newValue.matches("[a-zA-Z_]{1}[0-9a-zA-Z_]{0,63}$") && !newValue.equals(oldValue)) {
					staticKvField.setText(oldValue);
					return;
				}
				newConfig.setStaticKv(newValue);
			}
		});
		topGridPane.add(staticKvField, 1, 1);
		
		Label dynamicKvLabel = new Label("动态键值方法名:");
		GridPane.setHalignment(dynamicKvLabel, HPos.RIGHT);
		topGridPane.add(dynamicKvLabel, 2, 1);
		TextField dynamicKvField = new TextField();
		dynamicKvField.setText(initConfig.getDynamicKv());
		dynamicKvField.setPrefWidth(50);
		dynamicKvField.textProperty().addListener((observable, oldValue, newValue) -> {
			if (newValue != null && newValue.length() > 0) {
				if (!newValue.matches("[a-zA-Z_]{1}[0-9a-zA-Z_]{0,63}$") && !newValue.equals(oldValue)) {
					dynamicKvField.setText(oldValue);
					return;
				}
				newConfig.setDynamicKv(newValue);
			}
		});
		topGridPane.add(dynamicKvField, 3, 1);
		
		Label staticArrLabel = new Label("静态数组方法名:");
		GridPane.setHalignment(staticArrLabel, HPos.RIGHT);
		topGridPane.add(staticArrLabel, 4, 1);
		TextField staticArrField = new TextField();
		staticArrField.setText(initConfig.getStaticArr());
		staticArrField.setPrefWidth(50);
		staticArrField.textProperty().addListener((observable, oldValue, newValue) -> {
			if (newValue != null && newValue.length() > 0) {
				if (!newValue.matches("[a-zA-Z_]{1}[0-9a-zA-Z_]{0,63}$") && !newValue.equals(oldValue)) {
					staticArrField.setText(oldValue);
					return;
				}
				newConfig.setStaticArr(newValue);
			}
		});
		topGridPane.add(staticArrField, 5, 1);
		
		Label dynamicArrLabel = new Label("动态数组方法名:");
		GridPane.setHalignment(dynamicArrLabel, HPos.RIGHT);
		topGridPane.add(dynamicArrLabel, 6, 1);
		TextField dynamicArrField = new TextField();
		dynamicArrField.setText(initConfig.getDynamicArr());
		dynamicArrField.setPrefWidth(50);
		dynamicArrField.textProperty().addListener((observable, oldValue, newValue) -> {
			if (newValue != null && newValue.length() > 0) {
				if (!newValue.matches("[a-zA-Z_]{1}[0-9a-zA-Z_]{0,63}$") && !newValue.equals(oldValue)) {
					dynamicArrField.setText(oldValue);
					return;
				}
				newConfig.setDynamicArr(newValue);
			}
		});
		topGridPane.add(dynamicArrField, 7, 1);
		
		Label indentCntLabel = new Label("缩进次数:");
		GridPane.setHalignment(indentCntLabel, HPos.RIGHT);
		topGridPane.add(indentCntLabel, 0, 2);
		
		Spinner<Integer> indentCntSpinner = new Spinner<>(0, 8, initConfig.getIndentCnt());
		indentCntSpinner.setPrefWidth(50);
		indentCntSpinner.setEditable(false);
		indentCntSpinner.valueProperty().addListener((observable, oldValue, newValue) -> {
			newConfig.setIndentCnt(newValue);
		});
		topGridPane.add(indentCntSpinner, 1, 2);
		
		Label indentCharLabel = new Label("缩进字符:");
		GridPane.setHalignment(indentCharLabel, HPos.RIGHT);
		topGridPane.add(indentCharLabel, 2, 2);
		
		ToggleGroup tg = new ToggleGroup();
		RadioButton spaceRadioButton = new RadioButton("SPACE");
		spaceRadioButton.setToggleGroup(tg);
		RadioButton tabRadioButton = new RadioButton("TAB");
		tabRadioButton.setToggleGroup(tg);
		if ("\t".equals(initConfig.getIndentChar())) {
			tg.selectToggle(tabRadioButton);
		} else {
			tg.selectToggle(spaceRadioButton);
		}
		tg.selectedToggleProperty().addListener((observable, oldValue, newValue) -> {
			if (newValue == tabRadioButton) {
				newConfig.setIndentChar("\t");
			} else {
				newConfig.setIndentChar(" ");
			}
		});
		topGridPane.add(spaceRadioButton, 3, 2);
		topGridPane.add(tabRadioButton, 4, 2);
		
		root.setTop(topGridPane);
		
		SplitPane centerSplitPane = new SplitPane();
		
		TextArea leftTextArea = new TextArea();
		leftTextArea.setMinWidth(160);
		leftTextArea.setPromptText("请在此输入 json 本文...");
		leftTextArea.setFocusTraversable(false);
		leftTextArea.setStyle("-fx-prompt-text-fill: derive(-fx-control-inner-background,-30%);-fx-font-size: 1.2em;-fx-text-fill: #202020;");
		Platform.runLater(() -> leftTextArea.requestFocus());
		leftTextArea.textProperty().addListener((observable, oldValue, newValue) -> {
			leftTextAreaValue[0] = newValue == null ? "" : newValue.trim();
		});
		this.leftTextArea = leftTextArea;
		
		SplitPane rightSplitPane = new SplitPane();
		rightSplitPane.setOrientation(Orientation.VERTICAL);
		rightSplitPane.setMinWidth(160);
		
		TextArea rightTopTextArea = new TextArea();
		rightTopTextArea.setMinHeight(0);
		rightTopTextArea.setMaxHeight(80);
		rightTopTextArea.setEditable(false);
		rightTopTextArea.setStyle("-fx-font-size: 1.2em;-fx-text-fill: #202020;");
		TextArea rightCenterTextArea = new TextArea();
		rightCenterTextArea.setEditable(false);
		rightCenterTextArea.setStyle("-fx-font-size: 1.2em;-fx-text-fill: #202020;");
		rightSplitPane.getItems().addAll(rightTopTextArea, rightCenterTextArea);
		
		
		centerSplitPane.getItems().addAll(leftTextArea, rightSplitPane);
		
		root.setCenter(centerSplitPane);
		
		Scene scene = new Scene(root);
		stage.setScene(scene);
		stage.show();
		
		leftTextArea.setText(FileUtils.readLastInput());
		leftTextArea.appendText("");
		
		ConfigScheduledService configScheduledService = new ConfigScheduledService(initConfig, newConfig);
		configScheduledService.setDelay(Duration.seconds(2));
		configScheduledService.setPeriod(Duration.seconds(1.5));
		configScheduledService.setRestartOnFailure(true);
		configScheduledService.setMaximumFailureCount(3);
		configScheduledService.start();
		
		FormatScheduledService formatScheduledService = new FormatScheduledService(initConfig, rightTopTextArea, rightCenterTextArea, leftTextAreaValue);
		formatScheduledService.setDelay(Duration.seconds(1));
		formatScheduledService.setPeriod(Duration.seconds(1.5));
		formatScheduledService.setRestartOnFailure(true);
		formatScheduledService.setMaximumFailureCount(3);
		formatScheduledService.start();
	}

	@Override
	public void stop() throws Exception {
		super.stop();
		if (leftTextArea != null) {
			String text = leftTextArea.getText();
			FileUtils.writeLastInput(text);
		}
	}

}

打包

在工具根目录,执行以下 cmd mvn 命令,即可在根目录下生成 target/jfx/ 打包后的程序

mvn jfx:native

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/150112.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

Android:URLEncoder空格被转码为“+”号

Android前段和后端接口交互时&#xff0c;经常会遇到特殊字符&#xff0c;比如表情、特殊标点等&#xff0c;这样在Url中是无法识别的&#xff0c;需要进行转码&#xff0c;后端进行解码交互。 但当使用URLEncoder时&#xff0c;会发现字符串中的空格被转换成“”号&#xff0…

客服系统即时通讯IM开发(四)网站实现实时在线访客列表【唯一客服】网站在线客服系统...

在使用我的客服系统时&#xff0c;如果引入了我的js &#xff0c;就可以实时看到网站上的所有访客了 使用 WebSocket 技术来实现实时通信。 在访客登录或退出时&#xff0c;向指定客服的 WebSocket 客户端发送消息。例如&#xff0c;你可以在访客登录时&#xff0c;向指定客服…

测试用例的设计? 万能公式

万能公式(必背)&#xff1a;功能测试性能测试界面测试兼容性测试易用性测试安全测试功能测试 &#xff1a;可能来自于需求文档&#xff0c;也可能来自生活经验性能测试 &#xff1a;功能没有问题不代表性能是ok的&#xff0c;性能往往体现在一些极端情况界面测试 &#xff1a;颜…

Prometheus-基于Consul的自动注册

一、背景介绍 如果我们的物理机有很多&#xff0c;不管是基于"file_sd_config"还是"kubernetes_sd_config"&#xff0c;我们都需要手动写入目标target及创建目标service&#xff0c;这样才能被prometheus自动发现&#xff0c;为了避免重复性工作过多&#…

【182】Java8利用二叉查找树实现Map

本文利用二叉查找树写了一个Map&#xff0c;用来保存键值对。 二叉查找树的定义 二叉查找树又名二叉搜索树&#xff0c;英文名称是 Binary Search Tree&#xff0c;缩写BST。 二叉排序树&#xff0c;英文名称是 Binary Sorted Tree&#xff0c;缩写BST。 二叉查找树、二叉搜…

excel实用技巧:如何构建多级下拉菜单

使用数据有效性制作下拉菜单对大多数小伙伴来说都不陌生&#xff0c;但说到二级和三级下拉菜单大家可能就不是那么熟悉了。什么是二级和三级下拉菜单呢&#xff1f;举个例子&#xff0c;在一个单元格选择某个省后&#xff0c;第二个单元格选项只能出现该省份所属的市&#xff0…

vue-router原理简单实现

vue-router简单实现 初步预习 动态路由 获取id方式 第一种强依赖路由 第二种父传子方式&#xff08;推荐&#xff09; 嵌套路由 相同的头和尾&#xff0c;默认index&#xff0c;替换为detail 编程时导航 this.$router.push() this.$router.repleace() this.$router.g…

吊炸天,springboot的多环境配置一下搞明白了!

1、 使用springboot的profile命名规则profile用于多环境的激活和配置&#xff0c;用来切换生产&#xff0c;测试&#xff0c;本地等多套不通环境的配置。如果每次去更改配置就非常麻烦&#xff0c;profile就是用来切换多环境配置的。在Spring Boot框架中&#xff0c;使用Profil…

漏洞优先级排序的六大关键因素

当我们谈及开源漏洞时&#xff0c;我们会发现其数量永远处于增长状态。根据安全公司 Mend 研究发现&#xff0c;在 2022 年前九个月发现并添加到其漏洞数据库中的开源漏洞数量比 2021 年增加了 33%。该报告从 2022 年 1 月到 2022 年 9 月对大约 1,000 家北美公司进行了代表性抽…

一篇文章解决C语言操作符

我的主页&#xff1a;一只认真写代码的程序猿本文章是关于C语言操作符的讲解收录于专栏【C语言的学习】 目录 1、算术操作符 2、赋值操作符 3、关系操作符 4、条件操作符&#xff08;三目&#xff09; 5、逻辑操作符 6、单目操作符 7、移位操作符 8、位操作符 9、逗号…

使用Docker+Nignx部署vue项目

文章目录一、前言二、vue项目打包三、nginx基本介绍①nginx常用的功能&#xff1a;②nginx默认的主题配置文件解读③nginx目录解读三、docker内部署nginx①拉取nginx镜像②创建数据持久化目录☆☆☆③创建需要映射进去的文件④运行nginx四、大工告成最近&#xff08;之前&#…

2023年DAMA-CDGA/CDGP数据治理工程师认证(线上班)报名

DAMA认证为数据管理专业人士提供职业目标晋升规划&#xff0c;彰显了职业发展里程碑及发展阶梯定义&#xff0c;帮助数据管理从业人士获得企业数字化转型战略下的必备职业能力&#xff0c;促进开展工作实践应用及实际问题解决&#xff0c;形成企业所需的新数字经济下的核心职业…

gcc、g++,linux升级gcc、g++

安装cv-cuda库&#xff0c;要求gcc11&#xff0c;cmake>3.22版本。 Linux distro:Ubuntu x86_64 > 18.04WSL2 with Ubuntu > 20.04 (tested with 20.04) CUDA Driver > 11.7 (Not tested on 12.0) GCC > 11.0 Python > 3.7 cmake > 3.22gcc、g介绍 参考&…

手把手安装GNN必备库 —— pytorch_geometric

0 BackGround GNN&#xff1a;图神经网络&#xff0c;由于传统的CNN网络无法表示顶点和边这种关系型数据&#xff0c;便出现了图神经网络解决这种图数据的表示问题&#xff0c;这属于CNN往图方向的应用扩展。 GCN&#xff1a;图卷积神经网络&#xff0c;GNN在训练过程中&#…

【ONE·R || 两次作业(二):GEO数据处理下载分析】

总言 两次作业汇报其二&#xff1a;GEO数据处理学习汇报。    文章目录总言2、作业二&#xff1a;GEO数据处理下载分析2.1、GEO数据库下载前准备2.2、GEO数据库下载及数据初步处理2.2.1、分阶段解析演示2.2.1.1、编号下载流程2.2.1.2、对gset[ 1 ]初步分析2.2.1.3、对gset[ 2…

基于requests框架实现接口自动化测试项目实战

requests库是一个常用的用于http请求的模块&#xff0c;它使用python语言编写&#xff0c;在当下python系列的接口自动化中应用广泛&#xff0c;本文将带领大家深入学习这个库&#xff0c;Python环境的安装就不在这里赘述了&#xff0c;我们直接开干。 01 requests的安装 win…

销售结束语话术

销售要记住&#xff0c;结束语不代表结束&#xff0c;而是下一次沟通的开始&#xff0c;所以销售要学会通过结束语来为自己争取下次沟通的机会。 前言 不论是哪一行业&#xff0c;对于销售而言&#xff0c;大多数成交的客户都是经过持续有效的跟踪的&#xff0c;还会出现有很多…

Java设计模式-原型模式Prototype

介绍 当我们有一个类的实例&#xff08;Prototype&#xff09;并且我们想通过复制原型来创建新对象时&#xff0c;通常使用Prototype模式。 原型模式是一种创建型设计模式。能够复制已有对象&#xff0c; 而又无需使代码依赖它们所属的类。 场景举例 现在有一只羊 tom&#xf…

iTerm2连接ssh配置

iTerm2连接ssh配置 #首先在/Users目录下按照如下命令创建sh脚本 cd /Users/#创建iterm文件夹 mkdir iterm#进入iterm文件夹 cd iterm#创建myserver.sh文件 touch myserver.sh#编辑myserver.sh文件 vi myserver.sh如果出现没有权限&#xff0c;就命令前面加上sudo 键盘输入i编…

斯皮尔曼相关(spearman)相关性分析一文详解+python实例代码

前言 相关性分析算是很多算法以及建模的基础知识之一了&#xff0c;十分经典。关于许多特征关联关系以及相关趋势都可以利用相关性分析计算表达。其中常见的相关性系数就有三种&#xff1a;person相关系数&#xff0c;spearman相关系数&#xff0c;Kendalls tau-b等级相关系数…