generated from mingliqiye/lib-tem
Compare commits
No commits in common. "93f8cd9386e1171004bbe011a87571baf1c17a20" and "c54cab4a4408fe724b778cf7581bc564fc7df246" have entirely different histories.
93f8cd9386
...
c54cab4a44
8
.github/workflows/build.yaml
vendored
8
.github/workflows/build.yaml
vendored
@ -9,13 +9,7 @@ jobs:
|
||||
runs-on: ubuntu-dev
|
||||
steps:
|
||||
- name: Check out repository code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up JDK 8
|
||||
uses: actions/setup-java@v4
|
||||
with:
|
||||
java-version: '8'
|
||||
|
||||
uses: checkout@v4
|
||||
|
||||
- name: build
|
||||
run: |
|
||||
|
167
README.md
167
README.md
@ -1,167 +0,0 @@
|
||||
# mingli-utils
|
||||
|
||||
一个功能丰富的Java工具类库,提供字符串处理、时间处理、文件操作、网络工具、哈希计算等常用工具方法。
|
||||
|
||||
## 项目概述
|
||||
|
||||
mingli-utils 是一个 Java 工具类库,提供各种常用的工具方法,旨在简化开发流程,减少重复代码。
|
||||
|
||||
## 技术栈
|
||||
|
||||
- JDK 版本: Java 8
|
||||
- 构建工具: Gradle (Kotlin DSL)
|
||||
- 依赖库:
|
||||
- Lombok 1.18.38: 用于简化 Java Bean 代码
|
||||
- Jackson Databind 2.19.2: 用于 JSON 序列化
|
||||
- MyBatis 3.5.19: 持久层框架
|
||||
- Spring Boot Starter 2.7.14: Spring Boot基础依赖
|
||||
- Bouncy Castle 1.81: 加密算法库
|
||||
- UUID Creator 6.1.0: UUID生成工具
|
||||
- jBCrypt 0.4: BCrypt加密实现
|
||||
- JetBrains Annotations 24.0.0: 注解库
|
||||
|
||||
## 主要功能模块
|
||||
|
||||
### 字符串处理 (StringUtil)
|
||||
|
||||
提供常用的字符串操作方法:
|
||||
|
||||
- `toString()`: 对象转字符串
|
||||
- `format()`: 格式化字符串
|
||||
- `isEmpty()`: 判断字符串是否为空
|
||||
- `join()`: 连接字符串
|
||||
- `split()`: 分割字符串
|
||||
|
||||
### 集合工具 (Lists)
|
||||
|
||||
提供创建各种List实现的便捷方法:
|
||||
|
||||
- `newArrayList()`: 创建ArrayList实例
|
||||
- `newLinkedList()`: 创建LinkedList实例
|
||||
- `newVector()`: 创建Vector实例
|
||||
|
||||
### 时间处理 (time)
|
||||
|
||||
提供时间相关功能:
|
||||
|
||||
- `DateTime`: 时间处理类,封装了LocalDateTime的操作
|
||||
- `DateTimeOffset`: 时间偏移量处理
|
||||
- `Formatter`: 常用时间格式枚举
|
||||
- `DateTimeUnit`: 时间单位常量定义
|
||||
|
||||
### 文件操作 (FileUtil)
|
||||
|
||||
提供文件读写等操作:
|
||||
|
||||
- `readFileToString()`: 读取文件内容为字符串
|
||||
- `writeStringToFile()`: 将字符串写入文件
|
||||
- `readLines()`: 读取文件内容为字符串列表(按行分割)
|
||||
- `writeLines()`: 将字符串列表写入文件(每行一个元素)
|
||||
- `copyFile()`: 复制文件
|
||||
- `deleteFile()`: 删除文件
|
||||
- `exists()`: 检查文件是否存在
|
||||
- `getFileSize()`: 获取文件大小
|
||||
|
||||
### 网络工具 (network)
|
||||
|
||||
提供网络地址处理功能:
|
||||
|
||||
- `NetworkEndpoint`: 网络端点(IP+端口)封装
|
||||
- `NetworkAddress`: 网络地址处理(支持IPv4/IPv6)
|
||||
- `NetworkPort`: 网络端口处理
|
||||
|
||||
### 哈希工具 (HashUtils)
|
||||
|
||||
提供哈希计算功能:
|
||||
|
||||
- `calculateFileHash()`: 计算文件哈希值
|
||||
- `bcrypt()`: BCrypt加密
|
||||
- `checkBcrypt()`: 验证BCrypt哈希
|
||||
|
||||
### 系统工具 (SystemUtil)
|
||||
|
||||
提供系统相关工具方法:
|
||||
|
||||
- `isWindows()/isMac()/isUnix()`: 操作系统类型判断
|
||||
- `getJdkVersion()`: 获取JDK版本
|
||||
- `getLocalIps()`: 获取本地IP地址
|
||||
|
||||
### UUID工具 (uuid)
|
||||
|
||||
提供UUID处理功能:
|
||||
|
||||
- `UUID`: UUID封装类,支持时间戳型UUID
|
||||
|
||||
### 并发工具 (concurrent)
|
||||
|
||||
提供线程安全的数据结构:
|
||||
|
||||
- `IsChanged`: 基于CAS操作的线程安全包装类
|
||||
|
||||
### 函数式工具 (functions)
|
||||
|
||||
提供函数式编程支持:
|
||||
|
||||
- `Debouncer`: 防抖器实现
|
||||
|
||||
## 使用示例
|
||||
|
||||
```java
|
||||
// 字符串格式化
|
||||
String message =
|
||||
StringUtil.format("Hello {}, you are {} years old", "张三", 25);
|
||||
|
||||
// 创建列表
|
||||
List<String> fruits = Lists.newArrayList("苹果", "香蕉", "橙子");
|
||||
|
||||
// 连接字符串
|
||||
String result = StringUtil.join(", ", fruits);
|
||||
|
||||
// 时间处理
|
||||
DateTime now = DateTime.now();
|
||||
String formatted = now.format(Formatter.STANDARD_DATETIME);
|
||||
|
||||
// 文件操作
|
||||
FileUtil.
|
||||
|
||||
writeStringToFile("example.txt","Hello World");
|
||||
|
||||
String content = FileUtil.readFileToString("example.txt");
|
||||
|
||||
// 网络地址处理
|
||||
NetworkEndpoint endpoint = NetworkEndpoint.of("127.0.0.1", 8080);
|
||||
InetSocketAddress address = endpoint.toInetSocketAddress();
|
||||
|
||||
// 哈希计算
|
||||
String hash = HashUtils.bcrypt("password");
|
||||
boolean matches = HashUtils.checkBcrypt("password", hash);
|
||||
```
|
||||
|
||||
## 构建和运行
|
||||
|
||||
使用以下命令构建项目:
|
||||
|
||||
```bash
|
||||
./gradlew build
|
||||
```
|
||||
|
||||
发布到本地Maven仓库:
|
||||
|
||||
```bash
|
||||
./gradlew publishToMavenLocal
|
||||
```
|
||||
|
||||
## 项目配置
|
||||
|
||||
项目在 `gradle.properties` 中定义了以下配置:
|
||||
|
||||
```properties
|
||||
JDKVERSIONS=1.8
|
||||
GROUPSID=com.mingliqiye.utils
|
||||
ARTIFACTID=mingli-utils
|
||||
VERSIONS=1.0.4
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
本项目采用Apache 2.0许可证,详细信息请查看 [LICENSE](LICENSE) 文件。
|
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Binary file not shown.
5
gradle/wrapper/gradle-wrapper.properties
vendored
5
gradle/wrapper/gradle-wrapper.properties
vendored
@ -1,7 +1,6 @@
|
||||
#Thu Jun 26 08:26:37 CST 2025
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-9.0.0-rc-1-bin.zip
|
||||
networkTimeout=10000
|
||||
validateDistributionUrl=true
|
||||
distributionUrl=https\://repository.mingliqiye.com/repository/raw/gradle/gradle-8.14.2-all.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
|
49
gradlew
vendored
49
gradlew
vendored
@ -1,7 +1,7 @@
|
||||
#!/bin/sh
|
||||
|
||||
#
|
||||
# Copyright © 2015 the original authors.
|
||||
# Copyright © 2015-2021 the original authors.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
@ -15,8 +15,6 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
@ -57,7 +55,7 @@
|
||||
# Darwin, MinGW, and NonStop.
|
||||
#
|
||||
# (3) This script is generated from the Groovy template
|
||||
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||
# within the Gradle project.
|
||||
#
|
||||
# You can find Gradle at https://github.com/gradle/gradle/.
|
||||
@ -82,11 +80,13 @@ do
|
||||
esac
|
||||
done
|
||||
|
||||
# This is normally unused
|
||||
# shellcheck disable=SC2034
|
||||
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
|
||||
|
||||
APP_NAME="Gradle"
|
||||
APP_BASE_NAME=${0##*/}
|
||||
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
|
||||
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD=maximum
|
||||
@ -114,7 +114,7 @@ case "$( uname )" in #(
|
||||
NONSTOP* ) nonstop=true ;;
|
||||
esac
|
||||
|
||||
CLASSPATH="\\\"\\\""
|
||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||
|
||||
|
||||
# Determine the Java command to use to start the JVM.
|
||||
@ -133,29 +133,22 @@ location of your Java installation."
|
||||
fi
|
||||
else
|
||||
JAVACMD=java
|
||||
if ! command -v java >/dev/null 2>&1
|
||||
then
|
||||
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
fi
|
||||
|
||||
# Increase the maximum file descriptors if we can.
|
||||
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
||||
case $MAX_FD in #(
|
||||
max*)
|
||||
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
|
||||
# shellcheck disable=SC2039,SC3045
|
||||
MAX_FD=$( ulimit -H -n ) ||
|
||||
warn "Could not query maximum file descriptor limit"
|
||||
esac
|
||||
case $MAX_FD in #(
|
||||
'' | soft) :;; #(
|
||||
*)
|
||||
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
|
||||
# shellcheck disable=SC2039,SC3045
|
||||
ulimit -n "$MAX_FD" ||
|
||||
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
||||
esac
|
||||
@ -200,28 +193,18 @@ if "$cygwin" || "$msys" ; then
|
||||
done
|
||||
fi
|
||||
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||
|
||||
# Collect all arguments for the java command:
|
||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
|
||||
# and any embedded shellness will be escaped.
|
||||
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
|
||||
# treated as '${Hostname}' itself on the command line.
|
||||
# Collect all arguments for the java command;
|
||||
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
|
||||
# shell script including quotes and variable substitutions, so put them in
|
||||
# double quotes to make sure that they get re-expanded; and
|
||||
# * put everything else in single quotes, so that it's not re-expanded.
|
||||
|
||||
set -- \
|
||||
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||
-classpath "$CLASSPATH" \
|
||||
-jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \
|
||||
org.gradle.wrapper.GradleWrapperMain \
|
||||
"$@"
|
||||
|
||||
# Stop when "xargs" is not available.
|
||||
if ! command -v xargs >/dev/null 2>&1
|
||||
then
|
||||
die "xargs is not available"
|
||||
fi
|
||||
|
||||
# Use "xargs" to parse quoted args.
|
||||
#
|
||||
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
|
||||
|
41
gradlew.bat
vendored
41
gradlew.bat
vendored
@ -13,10 +13,8 @@
|
||||
@rem See the License for the specific language governing permissions and
|
||||
@rem limitations under the License.
|
||||
@rem
|
||||
@rem SPDX-License-Identifier: Apache-2.0
|
||||
@rem
|
||||
|
||||
@if "%DEBUG%"=="" @echo off
|
||||
@if "%DEBUG%" == "" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Gradle startup script for Windows
|
||||
@ -27,8 +25,7 @@
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%"=="" set DIRNAME=.
|
||||
@rem This is normally unused
|
||||
if "%DIRNAME%" == "" set DIRNAME=.
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@ -43,13 +40,13 @@ if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if %ERRORLEVEL% equ 0 goto execute
|
||||
if "%ERRORLEVEL%" == "0" goto execute
|
||||
|
||||
echo. 1>&2
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
|
||||
echo. 1>&2
|
||||
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||
echo location of your Java installation. 1>&2
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
@ -59,34 +56,32 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto execute
|
||||
|
||||
echo. 1>&2
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
|
||||
echo. 1>&2
|
||||
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||
echo location of your Java installation. 1>&2
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=
|
||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %*
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if %ERRORLEVEL% equ 0 goto mainEnd
|
||||
if "%ERRORLEVEL%"=="0" goto mainEnd
|
||||
|
||||
:fail
|
||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||
rem the _cmd.exe /c_ return code!
|
||||
set EXIT_CODE=%ERRORLEVEL%
|
||||
if %EXIT_CODE% equ 0 set EXIT_CODE=1
|
||||
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
|
||||
exit /b %EXIT_CODE%
|
||||
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
||||
exit /b 1
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
@ -1,39 +1,6 @@
|
||||
package com.mingliqiye.utils;
|
||||
|
||||
import com.mingliqiye.utils.collection.Lists;
|
||||
import com.mingliqiye.utils.string.StringUtil;
|
||||
import com.mingliqiye.utils.time.DateTime;
|
||||
import com.mingliqiye.utils.time.Formatter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// 字符串工具使用示例
|
||||
System.out.println("=== 字符串工具使用示例 ===");
|
||||
String formatted = StringUtil.format("你好 {},今天是{}年{}月{}日", "张三", 2025, 7, 25);
|
||||
System.out.println(formatted);
|
||||
|
||||
List<String> fruits = Lists.newArrayList("苹果", "香蕉", "橙子");
|
||||
String joined = StringUtil.join(", ", fruits);
|
||||
System.out.println("水果列表: " + joined);
|
||||
|
||||
// 时间工具使用示例
|
||||
System.out.println("\n=== 时间工具使用示例 ===");
|
||||
DateTime now = DateTime.now();
|
||||
System.out.println("当前时间: " + now);
|
||||
System.out.println("标准格式: " + now.format(Formatter.STANDARD_DATETIME));
|
||||
|
||||
DateTime specificDate = DateTime.of(2025, 1, 1, 12, 0, 0);
|
||||
System.out.println("指定时间: " + specificDate.format(Formatter.STANDARD_DATETIME));
|
||||
|
||||
// 集合工具使用示例
|
||||
System.out.println("\n=== 集合工具使用示例 ===");
|
||||
List<Integer> numbers = Lists.newArrayList(10, 20, 30);
|
||||
System.out.println("数字列表: " + numbers);
|
||||
|
||||
List<String> linkedList = Lists.newLinkedList("第一个", "第二个", "第三个");
|
||||
System.out.println("链表内容: " + linkedList);
|
||||
}
|
||||
}
|
||||
public static void main(String[] args) {}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user