From 9b4433fddf5b401edb0aace8a404ac733b122702 Mon Sep 17 00:00:00 2001 From: 田源 <tianyuan@vci-tech.com> Date: 星期四, 03 四月 2025 14:35:02 +0800 Subject: [PATCH] 添加非密字段显示 --- Source/BladeX-Tool/blade-core-tool/src/main/java/org/springblade/core/tool/utils/Version.java | 202 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 202 insertions(+), 0 deletions(-) diff --git a/Source/BladeX-Tool/blade-core-tool/src/main/java/org/springblade/core/tool/utils/Version.java b/Source/BladeX-Tool/blade-core-tool/src/main/java/org/springblade/core/tool/utils/Version.java new file mode 100644 index 0000000..fc42bca --- /dev/null +++ b/Source/BladeX-Tool/blade-core-tool/src/main/java/org/springblade/core/tool/utils/Version.java @@ -0,0 +1,202 @@ +/* + * Copyright (c) 2018-2028, DreamLu All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the dreamlu.net developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: DreamLu 鍗㈡槬姊� (596392912@qq.com) + */ + +package org.springblade.core.tool.utils; + +import org.springframework.lang.Nullable; + +/** + * 鐗堟湰鍙锋瘮杈冨伐鍏� + * <p> + * 鎬濊矾鏉ユ簮浜庯細 https://github.com/hotoo/versioning/blob/master/versioning.js + * <p> + * example + * * ##瀹屾暣妯″紡 + * Version.of("v0.1.1").eq("v0.1.2"); // false + * <p> + * ##涓嶅畬鏁存ā寮� + * Version.of("v0.1").incomplete().eq("v0.1.2"); // true + * + * @author L.cm + * email: 596392912@qq.com + * site:http://www.dreamlu.net + * date 2015骞�7鏈�9鏃ヤ笅鍗�10:48:39 + */ +public class Version { + private static final String DELIMITER = "\\."; + + /** + * 鐗堟湰鍙� + */ + @Nullable + private String version; + /** + * 鏄惁瀹屾暣妯″紡锛岄粯璁や娇鐢ㄥ畬鏁存ā寮� + */ + private boolean complete = true; + + /** + * 绉佹湁瀹炰緥鍖栨瀯閫犳柟娉� + */ + private Version() { + } + + private Version(@Nullable String version) { + this.version = version; + } + + /** + * 涓嶅畬鏁存ā寮� + * + * @return {Version} + */ + public Version incomplete() { + this.complete = false; + return this; + } + + /** + * 鏋勯�犲櫒 + * + * @param version 鐗堟湰 + * @return {Version} + */ + public static Version of(@Nullable String version) { + return new Version(version); + } + + /** + * 姣旇緝鐗堟湰鍙锋槸鍚︾浉鍚� + * <p> + * example: + * * Version.of("v0.3").eq("v0.4") + * + * @param version 瀛楃涓茬増鏈彿 + * @return {boolean} + */ + public boolean eq(@Nullable String version) { + return compare(version) == 0; + } + + /** + * 涓嶇浉鍚� + * <p> + * example: + * * Version.of("v0.3").ne("v0.4") + * + * @param version 瀛楃涓茬増鏈彿 + * @return {boolean} + */ + public boolean ne(@Nullable String version) { + return compare(version) != 0; + } + + /** + * 澶т簬 + * + * @param version 鐗堟湰鍙� + * @return 鏄惁澶т簬 + */ + public boolean gt(@Nullable String version) { + return compare(version) > 0; + } + + /** + * 澶т簬鍜岀瓑浜� + * + * @param version 鐗堟湰鍙� + * @return 鏄惁澶т簬鍜岀瓑浜� + */ + public boolean gte(@Nullable String version) { + return compare(version) >= 0; + } + + /** + * 灏忎簬 + * + * @param version 鐗堟湰鍙� + * @return 鏄惁灏忎簬 + */ + public boolean lt(@Nullable String version) { + return compare(version) < 0; + } + + /** + * 灏忎簬鍜岀瓑浜� + * + * @param version 鐗堟湰鍙� + * @return 鏄惁灏忎簬鍜岀瓑浜� + */ + public boolean lte(@Nullable String version) { + return compare(version) <= 0; + } + + /** + * 鍜屽彟澶栦竴涓増鏈彿姣旇緝 + * + * @param version 鐗堟湰鍙� + * @return {int} + */ + private int compare(@Nullable String version) { + return Version.compare(this.version, version, complete); + } + + /** + * 姣旇緝2涓増鏈彿 + * + * @param v1 v1 + * @param v2 v2 + * @param complete 鏄惁瀹屾暣鐨勬瘮杈冧袱涓増鏈� + * @return (v1 < v2) ? -1 : ((v1 == v2) ? 0 : 1) + */ + private static int compare(@Nullable String v1, @Nullable String v2, boolean complete) { + // v1 null瑙嗕负鏈�灏忕増鏈紝鎺掑湪鍓� + if (v1 == v2) { + return 0; + } else if (v1 == null) { + return -1; + } else if (v2 == null) { + return 1; + } + // 鍘婚櫎绌烘牸 + v1 = v1.trim(); + v2 = v2.trim(); + if (v1.equals(v2)) { + return 0; + } + String[] v1s = v1.split(DELIMITER); + String[] v2s = v2.split(DELIMITER); + int v1sLen = v1s.length; + int v2sLen = v2s.length; + int len = complete + ? Math.max(v1sLen, v2sLen) + : Math.min(v1sLen, v2sLen); + + for (int i = 0; i < len; i++) { + String c1 = len > v1sLen || null == v1s[i] ? "" : v1s[i]; + String c2 = len > v2sLen || null == v2s[i] ? "" : v2s[i]; + + int result = c1.compareTo(c2); + if (result != 0) { + return result; + } + } + + return 0; + } + +} -- Gitblit v1.9.3