public class VersionUtil extends Object
VersionComparator
的封装
最主要功能包括:
1. 版本表达式匹配 2. 单个版本匹配
VersionComparator
Constructor and Description |
---|
VersionUtil() |
Modifier and Type | Method and Description |
---|---|
static boolean |
anyMatch(String currentVersion,
Collection<String> compareVersions)
是否匹配任意一个版本
|
static boolean |
anyMatch(String currentVersion,
String... compareVersions)
是否匹配任意一个版本
|
static boolean |
isGreaterThan(String currentVersion,
String compareVersion)
当前版本大于待比较版本
|
static boolean |
isGreaterThanOrEqual(String currentVersion,
String compareVersion)
当前版本大于等于待比较版本
|
static boolean |
isLessThan(String currentVersion,
String compareVersion)
当前版本小于待比较版本
|
static boolean |
isLessThanOrEqual(String currentVersion,
String compareVersion)
当前版本小于等于待比较版本
|
static boolean |
matchEl(String currentVersion,
String versionEl)
当前版本是否满足版本表达式
matchEl("1.0.2", ">=1.0.2") == true
matchEl("1.0.2", "<1.0.1;1.0.2") == true
matchEl("1.0.2", "<1.0.2") == false
matchEl("1.0.2", "1.0.0-1.1.1") == true
matchEl("1.0.2", "1.0.0-1.1.1") == true
|
static boolean |
matchEl(String currentVersion,
String versionEl,
String versionsDelimiter)
当前版本是否满足版本表达式
matchEl("1.0.2", ">=1.0.2", ";") == true
matchEl("1.0.2", "<1.0.1,1.0.2", ",") == true
matchEl("1.0.2", "<1.0.2", ";") == false
matchEl("1.0.2", "1.0.0-1.1.1", ",") == true
matchEl("1.0.2", "1.0.1,1.0.2-1.1.1", ",") == true
|
public static boolean anyMatch(String currentVersion, Collection<String> compareVersions)
currentVersion
- 当前版本compareVersions
- 待匹配的版本列表public static boolean anyMatch(String currentVersion, String... compareVersions)
currentVersion
- 当前版本compareVersions
- 待匹配的版本列表public static boolean isGreaterThan(String currentVersion, String compareVersion)
currentVersion
- 当前本本compareVersion
- 待比较版本public static boolean isGreaterThanOrEqual(String currentVersion, String compareVersion)
currentVersion
- 当前本本compareVersion
- 待比较版本public static boolean isLessThan(String currentVersion, String compareVersion)
currentVersion
- 当前本本compareVersion
- 待比较版本public static boolean isLessThanOrEqual(String currentVersion, String compareVersion)
currentVersion
- 当前本本compareVersion
- 待比较版本public static boolean matchEl(String currentVersion, String versionEl)
matchEl("1.0.2", ">=1.0.2") == true
matchEl("1.0.2", "<1.0.1;1.0.2") == true
matchEl("1.0.2", "<1.0.2") == false
matchEl("1.0.2", "1.0.0-1.1.1") == true
matchEl("1.0.2", "1.0.0-1.1.1") == true
currentVersion
- 当前本本versionEl
- 版本表达式public static boolean matchEl(String currentVersion, String versionEl, String versionsDelimiter)
matchEl("1.0.2", ">=1.0.2", ";") == true
matchEl("1.0.2", "<1.0.1,1.0.2", ",") == true
matchEl("1.0.2", "<1.0.2", ";") == false
matchEl("1.0.2", "1.0.0-1.1.1", ",") == true
matchEl("1.0.2", "1.0.1,1.0.2-1.1.1", ",") == true
currentVersion
- 当前本本versionEl
- 版本表达式(可以匹配多个条件,使用指定的分隔符(默认;)分隔),
'-'
表示范围包含左右版本,如果 '-'
的左边没有,表示小于等于某个版本号, 右边表示大于等于某个版本号。
支持比较符号'>'
,'<'
, '>='
,'<='
,'≤'
,'≥'
1.0.1-1.2.4, 1.9.8
表示版本号 大于等于1.0.1
且小于等于1.2.4
或 版本1.9.8
>=2.0.0, 1.9.8
表示版本号 大于等于2.0.0
或 版本1.9.8
versionsDelimiter
- 多表达式分隔符Copyright © 2025. All rights reserved.