diff --git a/.gitattributes b/.gitattributes
index 30e0ce8..6313b56 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -1,5 +1 @@
-* text eol=lf
-*.bat text eol=crlf
-*.jar binary
-*.class binary
-*.png binary
+* text=auto eol=lf
diff --git a/.gitignore b/.gitignore
index 79621be..a0f1509 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,10 +5,8 @@ build/
!**/src/test/**/build/
### IntelliJ IDEA ###
-.idea/modules.xml
-.idea/jarRepositories.xml
-.idea/compiler.xml
-.idea/libraries/
+.idea
+!.idea/icon.png
*.iws
*.iml
*.ipr
@@ -16,8 +14,6 @@ out/
!**/src/main/**/out/
!**/src/test/**/out/
-!.idea/icon.png
-
### Eclipse ###
.apt_generated
.classpath
@@ -47,5 +43,5 @@ bin/
log
.idea
node_modules
-pnpm-lock.yaml
+*lock*
diff --git a/.idea/icon.png b/.idea/icon.png
index dfbf5af..af567d4 100644
Binary files a/.idea/icon.png and b/.idea/icon.png differ
diff --git a/build.gradle.kts b/build.gradle.kts
index 4c8fcd0..a924a0d 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -66,8 +66,8 @@ repositories {
publishing {
repositories {
maven {
- name = "localMaven"
- url = uri("D:/git/maven-repository-raw")
+ name = "MavenRepositoryRaw"
+ url = uri("C:/data/git/maven-repository-raw")
}
}
publications {
diff --git a/gradle.properties b/gradle.properties
index 074e616..508f8f8 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -1,4 +1,4 @@
JDKVERSIONS=1.8
GROUPSID=com.mingliqiye.utils
ARTIFACTID=mingli-utils
-VERSIONS=1.0.7
+VERSIONS=1.1.3
diff --git a/package.json b/package.json
index 718cf04..1a80db0 100644
--- a/package.json
+++ b/package.json
@@ -6,7 +6,6 @@
"buildw": "gradlew build-jar",
"format": "prettier --write \"**/*.{js,ts,jsx,tsx,cjs,cts,mjs,mts,vue,astro,json,java}\""
},
- "packageManager": "pnpm@10.4.1",
"devDependencies": {
"prettier-plugin-java": "^2.7.1",
"prettier": "^3.6.2"
diff --git a/src/com/mingliqiye/utils/aes/AesUtils.java b/src/com/mingliqiye/utils/aes/AesUtils.java
index 5704c80..9f7ce64 100644
--- a/src/com/mingliqiye/utils/aes/AesUtils.java
+++ b/src/com/mingliqiye/utils/aes/AesUtils.java
@@ -1,14 +1,13 @@
package com.mingliqiye.utils.aes;
import com.mingliqiye.utils.base64.Base64Utils;
-
-import javax.crypto.Cipher;
-import javax.crypto.spec.GCMParameterSpec;
-import javax.crypto.spec.SecretKeySpec;
import java.nio.charset.StandardCharsets;
import java.security.GeneralSecurityException;
import java.security.MessageDigest;
import java.security.SecureRandom;
+import javax.crypto.Cipher;
+import javax.crypto.spec.GCMParameterSpec;
+import javax.crypto.spec.SecretKeySpec;
public class AesUtils {
diff --git a/src/com/mingliqiye/utils/bytes/ByteUtil.java b/src/com/mingliqiye/utils/bytes/ByteUtil.java
new file mode 100644
index 0000000..2af4d42
--- /dev/null
+++ b/src/com/mingliqiye/utils/bytes/ByteUtil.java
@@ -0,0 +1,33 @@
+package com.mingliqiye.utils.bytes;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Collectors;
+
+/**
+ * @author MingLiPro
+ *
+ * 字节数组处理工具类
+ */
+public class ByteUtil {
+
+ /**
+ * 将字节数组转换为十六进制字符串列表
+ *
+ * 每个字节都会被转换为两位的十六进制字符串表示形式
+ * 例如: 字节值为10的字节会被转换为"0a",值为255的字节会被转换为"ff"
+ *
+ * @param bytes 输入的字节数组
+ * @return 包含每个字节对应十六进制字符串的列表
+ */
+ public static List getByteArrayString(byte[] bytes) {
+ List byteList = new ArrayList<>(bytes.length);
+ for (byte aByte : bytes) {
+ byteList.add(aByte);
+ }
+ return byteList
+ .stream()
+ .map(a -> String.format("%02x", a & 0xFF))
+ .collect(Collectors.toList());
+ }
+}
diff --git a/src/com/mingliqiye/utils/collection/Lists.java b/src/com/mingliqiye/utils/collection/Lists.java
index 34a3661..0968218 100644
--- a/src/com/mingliqiye/utils/collection/Lists.java
+++ b/src/com/mingliqiye/utils/collection/Lists.java
@@ -2,6 +2,7 @@ package com.mingliqiye.utils.collection;
import java.util.*;
import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
/**
* Lists工具类提供了一系列创建List实现的便捷方法。
@@ -245,4 +246,16 @@ public class Lists {
}
return newList.toArray(new String[0]);
}
+
+ @Nullable
+ public static T[] toArray(List ts) {
+ if (ts == null) {
+ return null;
+ }
+ T[] items = (T[]) new Object[ts.size()];
+ ForEach.forEach(ts, (t, i) -> {
+ items[i] = t;
+ });
+ return items;
+ }
}
diff --git a/src/com/mingliqiye/utils/time/DateTime.java b/src/com/mingliqiye/utils/time/DateTime.java
index 62b546c..88badce 100644
--- a/src/com/mingliqiye/utils/time/DateTime.java
+++ b/src/com/mingliqiye/utils/time/DateTime.java
@@ -4,18 +4,27 @@ import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
+import java.time.temporal.ChronoUnit;
import java.util.Date;
import lombok.Getter;
import lombok.Setter;
import lombok.var;
+import org.jetbrains.annotations.NotNull;
/**
* 时间工具类,用于处理日期时间的转换、格式化等操作。
* 提供了多种静态方法来创建 DateTime 实例,并支持与 Date、LocalDateTime 等类型的互转。
*
* @author MingLiPro
+ * @see java.time
* @see LocalDateTime
+ * @see ChronoUnit
+ * @see Date
+ * @see DateTimeFormatter
+ * @see ZoneId
+ * @see Instant
*/
+
public final class DateTime {
@Getter
@@ -73,6 +82,16 @@ public final class DateTime {
);
}
+ /**
+ * 根据 LocalDateTime 创建 DateTime 实例。
+ *
+ * @param localDateTime LocalDateTime 对象
+ * @return 返回对应的 DateTime 实例
+ */
+ public static DateTime of(LocalDateTime localDateTime) {
+ return new DateTime(localDateTime);
+ }
+
/**
* 解析时间字符串并生成 DateTime 实例。
*
@@ -307,11 +326,12 @@ public final class DateTime {
* @return 返回修改后的 DateTime 实例
*/
public DateTime add(DateTimeOffset dateTimeOffset) {
- this.localDateTime = this.localDateTime.plus(
- dateTimeOffset.getOffset(),
- dateTimeOffset.getOffsetType()
+ return new DateTime(
+ this.localDateTime.plus(
+ dateTimeOffset.getOffset(),
+ dateTimeOffset.getOffsetType()
+ )
);
- return this;
}
/**
@@ -321,11 +341,12 @@ public final class DateTime {
* @return 返回修改后的 DateTime 实例
*/
public DateTime sub(DateTimeOffset dateTimeOffset) {
- this.localDateTime = this.localDateTime.plus(
- -dateTimeOffset.getOffset(),
- dateTimeOffset.getOffsetType()
+ return new DateTime(
+ this.localDateTime.plus(
+ -dateTimeOffset.getOffset(),
+ dateTimeOffset.getOffsetType()
+ )
);
- return this;
}
/**
@@ -407,7 +428,41 @@ public final class DateTime {
return false;
}
+ /**
+ * 将当前 DateTime 转换为 Instant 对象。
+ *
+ * @return 返回 Instant 对象
+ */
+ @NotNull
public Instant toInstant() {
return localDateTime.atZone(zoneId).toInstant();
}
+
+ /**
+ * 判断当前时间是否在指定时间之后。
+ *
+ * @param dateTime 指定时间
+ * @return 如果当前时间在指定时间之后则返回 true,否则返回 false
+ */
+
+ public boolean isAfter(DateTime dateTime) {
+ if (dateTime == null) {
+ return false;
+ }
+ return toInstant().isAfter(dateTime.toInstant());
+ }
+
+ /**
+ * 判断当前时间是否在指定时间之前。
+ *
+ * @param dateTime 指定时间
+ * @return 如果当前时间在指定时间之前则返回 true,否则返回 false
+ */
+
+ public boolean isBefore(DateTime dateTime) {
+ if (dateTime == null) {
+ return false;
+ }
+ return toInstant().isBefore(dateTime.toInstant());
+ }
}
diff --git a/src/com/mingliqiye/utils/uuid/MysqlUUIDv1.java b/src/com/mingliqiye/utils/uuid/MysqlUUIDv1.java
index 8274350..af7b261 100644
--- a/src/com/mingliqiye/utils/uuid/MysqlUUIDv1.java
+++ b/src/com/mingliqiye/utils/uuid/MysqlUUIDv1.java
@@ -11,12 +11,12 @@ import lombok.var;
public class MysqlUUIDv1 {
/**
- * 将MySQL格式的UUID转换为标准UUID格式
+ * 将标准UUID格式转换为MySQL格式的UUID
*
- * @param uuid MySQL格式的UUID字节数组,长度必须为16字节
- * @return 标准UUID格式的字节数组,长度为16字节
+ * @param uuid 标准UUID格式的字节数组,长度必须为16字节
+ * @return MySQL格式的UUID字节数组,长度为16字节
*/
- public static byte[] mysqlToUuid(byte[] uuid) {
+ public static byte[] uuidToMysql(byte[] uuid) {
var reuuid = new byte[16];
// 转换时间戳低位部分
reuuid[4] = uuid[0];
@@ -38,12 +38,12 @@ public class MysqlUUIDv1 {
}
/**
- * 将标准UUID格式转换为MySQL格式的UUID
+ * 将MySQL格式的UUID转换为标准UUID格式
*
- * @param uuid 标准UUID格式的字节数组,长度必须为16字节
- * @return MySQL格式的UUID字节数组,长度为16字节
+ * @param uuid MySQL格式的UUID字节数组,长度必须为16字节
+ * @return 标准UUID格式的字节数组,长度为16字节
*/
- public static byte[] uuidToMysql(byte[] uuid) {
+ public static byte[] mysqlToUuid(byte[] uuid) {
var reuuid = new byte[16];
// 转换时间戳高位部分
reuuid[6] = uuid[0];
diff --git a/src/com/mingliqiye/utils/uuid/UUID.java b/src/com/mingliqiye/utils/uuid/UUID.java
index 3db833d..a47b068 100644
--- a/src/com/mingliqiye/utils/uuid/UUID.java
+++ b/src/com/mingliqiye/utils/uuid/UUID.java
@@ -4,13 +4,12 @@ import com.github.f4b6a3.uuid.UuidCreator;
import com.mingliqiye.utils.string.StringUtil;
import com.mingliqiye.utils.time.DateTime;
import com.mingliqiye.utils.time.DateTimeOffset;
-import lombok.Data;
-
import java.io.Serializable;
import java.nio.ByteBuffer;
import java.time.temporal.ChronoUnit;
import java.util.Locale;
import java.util.Objects;
+import lombok.Data;
/**
* UUID 工具类,用于生成、解析和操作 UUID。
diff --git a/src/com/mingliqiye/utils/uuid/typehandlers/UUIDBinaryTypeHandler.java b/src/com/mingliqiye/utils/uuid/typehandlers/UUIDBinaryTypeHandler.java
index d70b2d0..1657d94 100644
--- a/src/com/mingliqiye/utils/uuid/typehandlers/UUIDBinaryTypeHandler.java
+++ b/src/com/mingliqiye/utils/uuid/typehandlers/UUIDBinaryTypeHandler.java
@@ -1,15 +1,14 @@
package com.mingliqiye.utils.uuid.typehandlers;
import com.mingliqiye.utils.uuid.UUID;
-import org.apache.ibatis.type.BaseTypeHandler;
-import org.apache.ibatis.type.JdbcType;
-import org.apache.ibatis.type.MappedJdbcTypes;
-import org.apache.ibatis.type.MappedTypes;
-
import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
+import org.apache.ibatis.type.BaseTypeHandler;
+import org.apache.ibatis.type.JdbcType;
+import org.apache.ibatis.type.MappedJdbcTypes;
+import org.apache.ibatis.type.MappedTypes;
/**
* UUIDBinaryTypeHandler 类用于处理 UUID 类型与数据库 BINARY 类型之间的转换