, Serializable {
/**
* 版本信息
*/
- public static final String _VERSION = "8.0.2";
+ public static final String _VERSION = "8.0.5";
private static final long serialVersionUID = -1L;
private final String version;
@@ -176,7 +176,6 @@ public static Version of(final String v) {
*
* [大版本].[小版本].[发布流水号]
*
- *
* 这里有点说明
*
* - 大版本 - 表示API的版本,如果没有重大变化,基本上同样的大版本号,使用方式是一致的
diff --git a/bus-core/src/main/java/org/miaixz/bus/core/annotation/resolve/AnnotatedElements.java b/bus-core/src/main/java/org/miaixz/bus/core/annotation/resolve/AnnotatedElements.java
index 71f4f64da6..e7ba883691 100644
--- a/bus-core/src/main/java/org/miaixz/bus/core/annotation/resolve/AnnotatedElements.java
+++ b/bus-core/src/main/java/org/miaixz/bus/core/annotation/resolve/AnnotatedElements.java
@@ -44,11 +44,11 @@
import java.util.stream.Stream;
/**
- *
{@link AnnotatedElement}工具类,提供对层级结构中{@link AnnotatedElement}上注解及元注解的访问支持,
+ * {@link AnnotatedElement}工具类,提供对层级结构中{@link AnnotatedElement}上注解及元注解的访问支持,
* 并提供诸如基于{@link Alias}的属性别名、基于父子注解间的属性值覆盖等特殊的属性映射机制支持。
*
- *
搜索层级结构
- *
参考 Spring 中{@code AnnotatedElementUtils},
+ * 搜索层级结构
+ * 参考 Spring 中{@code AnnotatedElementUtils},
* 工具类提供get以及find两种语义的搜索:
*
* - get:表示搜索范围仅限于指定的{@link AnnotatedElement}本身;
@@ -63,8 +63,8 @@
* 则通过getXXX方法将只能获得A上的注解,
* 而通过findXXX方法将能获得A、B、C上的注解。
*
- * 搜索元注解
- *
工具类支持搜索注解的元注解。在所有格式为getXXX或findXXX的静态方法中,
+ * 搜索元注解
+ * 工具类支持搜索注解的元注解。在所有格式为getXXX或findXXX的静态方法中,
* 若不带有directly关键字,则该方法支持搜索元注解,否则不支持搜索元注解。
* eg:
* 若类A分别有父类和父接口B、C,上面分别有注解X与其元注解Y,
@@ -77,8 +77,8 @@
*
* 注意:在当前实例中将无视{@link Inherited}的效果,即通过directly方法将无法获得父类上带有{@link Inherited}的注解。
*
- * 注解属性映射
- *
工具类支持注解对象属性上的一些属性映射机制,即当注解被扫描时,
+ * 注解属性映射
+ * 工具类支持注解对象属性上的一些属性映射机制,即当注解被扫描时,
* 将根据一些属性映射机制“解析”为其他类型的属性,这里支持的机制包括:
*
* -
@@ -125,8 +125,8 @@
*
*
*
- * 可重复注解支持
- *
工具类中格式为findAllXXX或getAllXXX格式的方法,
+ * 可重复注解支持
+ * 工具类中格式为findAllXXX或getAllXXX格式的方法,
* 支持获得{@link AnnotatedElement}上的可重复注解。
* 此处的可重复注解定义包括两方面:
*
*
*
- * 缓存
- *
为了避免注解以及{@link AnnotatedElement}层级结构解析过程中的大量反射调用,
+ * 缓存
+ * 为了避免注解以及{@link AnnotatedElement}层级结构解析过程中的大量反射调用,
* 工具类为{@link AnnotatedElement}及其元注解信息进行了缓存。
* 缓存功能默认基于{@link WeakConcurrentMap}实现,会在gc时自动回收部分缓存数据。
* 但是若有必要,也可以调用{@link #clearCaches()}方法主动清空缓存。
@@ -542,7 +542,7 @@ public static AnnotatedElement toHierarchyMetaElement(final AnnotatedElement ele
}
/**
- *
扫描{@code element}所处层级结构中的{@link AnnotatedElement},
+ * 扫描{@code element}所处层级结构中的{@link AnnotatedElement},
* 并将其全部转为{@link RepeatableMetaAnnotatedElement}后,
* 再把所有对象合并为{@link HierarchicalAnnotatedElements}。
* 得到的对象可访问{@code element}所处层级结构中所有{@link AnnotatedElement}上的直接声明的注解,
@@ -565,7 +565,7 @@ public static AnnotatedElement toHierarchyRepeatableMetaElement(final AnnotatedE
}
/**
- *
扫描{@code element}所处层级结构中的{@link AnnotatedElement},
+ * 扫描{@code element}所处层级结构中的{@link AnnotatedElement},
* 再把所有对象合并为{@link HierarchicalAnnotatedElements}
* 得到的对象可访问{@code element}所处层级结构中所有{@link AnnotatedElement}上的注解。
*
@@ -611,7 +611,7 @@ public static AnnotatedElement toRepeatableMetaElement(final AnnotatedElement el
}
/**
- *
将{@link AnnotatedElement}转为{@link RepeatableMetaAnnotatedElement},
+ * 将{@link AnnotatedElement}转为{@link RepeatableMetaAnnotatedElement},
* 得到的对象可访问{@link AnnotatedElement}上的直接声明的注解,
* 通过{@code collector}从这些注解获得的可重复注解,以及上述注解的所有元注解。
* 注意:方法将不会通过缓存结果,因此每次调用都需要重新通过反射并获得相关注解。
@@ -666,7 +666,7 @@ public static AnnotatedElement emptyElement() {
* @param element {@link AnnotatedElement}
* @return {@link MetaAnnotatedElement}实例
*/
- static MetaAnnotatedElement getResolvedMetaElementCache(final AnnotatedElement element) {
+ public static MetaAnnotatedElement getResolvedMetaElementCache(final AnnotatedElement element) {
return RESOLVED_ELEMENT_CACHE.computeIfAbsent(element, ele -> MetaAnnotatedElement.create(
element, (source, annotation) -> ResolvedAnnotationMapping.create(source, annotation, true)
));
@@ -678,7 +678,7 @@ static MetaAnnotatedElement getResolvedMetaElementCac
* @param element {@link AnnotatedElement}
* @return {@link MetaAnnotatedElement}实例
*/
- static MetaAnnotatedElement getMetaElementCache(final AnnotatedElement element) {
+ public static MetaAnnotatedElement getMetaElementCache(final AnnotatedElement element) {
return ELEMENT_CACHE.computeIfAbsent(element, ele -> MetaAnnotatedElement.create(
element, (source, annotation) -> GenericAnnotationMapping.create(annotation, Objects.isNull(source))
));
@@ -690,7 +690,7 @@ static MetaAnnotatedElement getMetaElementCache(final
* @param element {@link AnnotatedElement}
* @return {@link MetaAnnotatedElement}实例
*/
- static RepeatableMetaAnnotatedElement getResolvedRepeatableMetaElementCache(final AnnotatedElement element) {
+ public static RepeatableMetaAnnotatedElement getResolvedRepeatableMetaElementCache(final AnnotatedElement element) {
return RESOLVED_REPEATABLE_ELEMENT_CACHE.computeIfAbsent(element, ele -> RepeatableMetaAnnotatedElement.create(
element, (source, annotation) -> ResolvedAnnotationMapping.create(source, annotation, true)
));
@@ -702,7 +702,7 @@ static RepeatableMetaAnnotatedElement getResolvedRepe
* @param element {@link AnnotatedElement}
* @return {@link MetaAnnotatedElement}实例
*/
- static RepeatableMetaAnnotatedElement getRepeatableMetaElementCache(final AnnotatedElement element) {
+ public static RepeatableMetaAnnotatedElement getRepeatableMetaElementCache(final AnnotatedElement element) {
return REPEATABLE_ELEMENT_CACHE.computeIfAbsent(element, ele -> RepeatableMetaAnnotatedElement.create(
element, (source, annotation) -> GenericAnnotationMapping.create(annotation, Objects.isNull(source))
));
diff --git a/bus-core/src/main/java/org/miaixz/bus/core/annotation/resolve/AnnotationMappingProxy.java b/bus-core/src/main/java/org/miaixz/bus/core/annotation/resolve/AnnotationMappingProxy.java
index d41fdbb5e4..a7c8e38d38 100644
--- a/bus-core/src/main/java/org/miaixz/bus/core/annotation/resolve/AnnotationMappingProxy.java
+++ b/bus-core/src/main/java/org/miaixz/bus/core/annotation/resolve/AnnotationMappingProxy.java
@@ -189,7 +189,7 @@ private Object getAttributeValue(final String attributeName, final Class> attr
/**
* 表明注解是一个合成的注解
*/
- interface Proxied {
+ public interface Proxied {
/**
* 获取注解映射对象
diff --git a/bus-core/src/main/java/org/miaixz/bus/core/annotation/resolve/GenericAnnotationMapping.java b/bus-core/src/main/java/org/miaixz/bus/core/annotation/resolve/GenericAnnotationMapping.java
index f3aab35813..e1ef3c4c3e 100644
--- a/bus-core/src/main/java/org/miaixz/bus/core/annotation/resolve/GenericAnnotationMapping.java
+++ b/bus-core/src/main/java/org/miaixz/bus/core/annotation/resolve/GenericAnnotationMapping.java
@@ -55,7 +55,7 @@ public class GenericAnnotationMapping implements AnnotationMapping {
* @param annotation 注解对象
* @param isRoot 是否根注解
*/
- GenericAnnotationMapping(final Annotation annotation, final boolean isRoot) {
+ public GenericAnnotationMapping(final Annotation annotation, final boolean isRoot) {
this.annotation = Objects.requireNonNull(annotation);
this.isRoot = isRoot;
this.attributes = AnnoKit.getAnnotationAttributes(annotation.annotationType());
diff --git a/bus-core/src/main/java/org/miaixz/bus/core/annotation/resolve/ResolvedAnnotationMapping.java b/bus-core/src/main/java/org/miaixz/bus/core/annotation/resolve/ResolvedAnnotationMapping.java
index ab2ea88216..0f744a5079 100644
--- a/bus-core/src/main/java/org/miaixz/bus/core/annotation/resolve/ResolvedAnnotationMapping.java
+++ b/bus-core/src/main/java/org/miaixz/bus/core/annotation/resolve/ResolvedAnnotationMapping.java
@@ -146,7 +146,7 @@ public class ResolvedAnnotationMapping implements AnnotationMapping
* 当{@code annotation}包装的注解对象类型为{@code ResolvedAnnotationMapping}时抛出;
*
*/
- ResolvedAnnotationMapping(final ResolvedAnnotationMapping source, final Annotation annotation, final boolean resolveAttribute) {
+ public ResolvedAnnotationMapping(final ResolvedAnnotationMapping source, final Annotation annotation, final boolean resolveAttribute) {
Objects.requireNonNull(annotation);
Assert.isFalse(AnnotationMappingProxy.isProxied(annotation), "annotation has been proxied");
Assert.isFalse(annotation instanceof ResolvedAnnotationMapping, "annotation has been wrapped");
@@ -200,6 +200,7 @@ public static ResolvedAnnotationMapping create(
* 解析属性
*/
private boolean resolveAttributes() {
+ // TODO 支持处理@Ignore,被标记的属性无法被覆写,也不会被别名关联
// 解析同一注解中的别名
resolveAliasAttributes();
// 使用子注解覆写当前注解中的属性
diff --git a/bus-base/src/main/java/org/miaixz/bus/base/advice/ErrorAdvice.java b/bus-core/src/main/java/org/miaixz/bus/core/basics/advice/ErrorAdvice.java
similarity index 97%
rename from bus-base/src/main/java/org/miaixz/bus/base/advice/ErrorAdvice.java
rename to bus-core/src/main/java/org/miaixz/bus/core/basics/advice/ErrorAdvice.java
index 5de6ff07e4..fc0819ae5e 100755
--- a/bus-base/src/main/java/org/miaixz/bus/base/advice/ErrorAdvice.java
+++ b/bus-core/src/main/java/org/miaixz/bus/core/basics/advice/ErrorAdvice.java
@@ -25,9 +25,9 @@
~ ~
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
*/
-package org.miaixz.bus.base.advice;
+package org.miaixz.bus.core.basics.advice;
-import org.miaixz.bus.base.service.ErrorService;
+import org.miaixz.bus.core.basics.service.ErrorService;
import java.util.ServiceLoader;
diff --git a/bus-core/src/main/java/org/miaixz/bus/core/basics/advice/package-info.java b/bus-core/src/main/java/org/miaixz/bus/core/basics/advice/package-info.java
new file mode 100644
index 0000000000..30663762a2
--- /dev/null
+++ b/bus-core/src/main/java/org/miaixz/bus/core/basics/advice/package-info.java
@@ -0,0 +1,34 @@
+/*
+ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
+ ~ ~
+ ~ The MIT License (MIT) ~
+ ~ ~
+ ~ Copyright (c) 2015-2024 miaixz.org and other contributors. ~
+ ~ ~
+ ~ Permission is hereby granted, free of charge, to any person obtaining a copy ~
+ ~ of this software and associated documentation files (the "Software"), to deal ~
+ ~ in the Software without restriction, including without limitation the rights ~
+ ~ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell ~
+ ~ copies of the Software, and to permit persons to whom the Software is ~
+ ~ furnished to do so, subject to the following conditions: ~
+ ~ ~
+ ~ The above copyright notice and this permission notice shall be included in ~
+ ~ all copies or substantial portions of the Software. ~
+ ~ ~
+ ~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR ~
+ ~ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, ~
+ ~ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE ~
+ ~ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER ~
+ ~ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, ~
+ ~ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN ~
+ ~ THE SOFTWARE. ~
+ ~ ~
+ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
+ */
+/**
+ * 异常信息处理
+ *
+ * @author Kimi Liu
+ * @since Java 17+
+ */
+package org.miaixz.bus.core.basics.advice;
diff --git a/bus-core/src/main/java/org/miaixz/bus/core/basics/entity/Entity.java b/bus-core/src/main/java/org/miaixz/bus/core/basics/entity/Entity.java
new file mode 100755
index 0000000000..12db9b6b87
--- /dev/null
+++ b/bus-core/src/main/java/org/miaixz/bus/core/basics/entity/Entity.java
@@ -0,0 +1,111 @@
+/*
+ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
+ ~ ~
+ ~ The MIT License (MIT) ~
+ ~ ~
+ ~ Copyright (c) 2015-2024 miaixz.org and other contributors. ~
+ ~ ~
+ ~ Permission is hereby granted, free of charge, to any person obtaining a copy ~
+ ~ of this software and associated documentation files (the "Software"), to deal ~
+ ~ in the Software without restriction, including without limitation the rights ~
+ ~ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell ~
+ ~ copies of the Software, and to permit persons to whom the Software is ~
+ ~ furnished to do so, subject to the following conditions: ~
+ ~ ~
+ ~ The above copyright notice and this permission notice shall be included in ~
+ ~ all copies or substantial portions of the Software. ~
+ ~ ~
+ ~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR ~
+ ~ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, ~
+ ~ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE ~
+ ~ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER ~
+ ~ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, ~
+ ~ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN ~
+ ~ THE SOFTWARE. ~
+ ~ ~
+ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
+ */
+package org.miaixz.bus.core.basics.entity;
+
+import jakarta.persistence.Id;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+import lombok.experimental.SuperBuilder;
+import org.miaixz.bus.core.lang.Normal;
+import org.miaixz.bus.core.xyz.FieldKit;
+
+import java.io.Serializable;
+
+/**
+ * Entity 实体
+ *
+ * @author Kimi Liu
+ * @since Java 17+
+ */
+@Getter
+@Setter
+@SuperBuilder
+@NoArgsConstructor
+@AllArgsConstructor
+public class Entity implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * 数据主键
+ */
+ @Id
+ protected String id;
+
+ /**
+ * 根据主键属性,判断主键是否值为空
+ *
+ * @param 对象
+ * @param entity 反射对象
+ * @param field 属性
+ * @return 主键为空, 则返回false;主键有值,返回true
+ */
+ public boolean isPKNotNull(T entity, String field) {
+ if (!FieldKit.hasField(entity.getClass(), field)) {
+ return false;
+ }
+ Object value = FieldKit.getFieldValue(entity, field);
+ return null != value && !Normal.EMPTY.equals(value);
+ }
+
+ /**
+ * 依据对象的属性获取对象值
+ *
+ * @param 对象
+ * @param entity 反射对象
+ * @param field 属性数组
+ * @return 返回对象属性值
+ */
+ public Object getValue(T entity, String field) {
+ if (FieldKit.hasField(entity.getClass(), field)) {
+ Object value = FieldKit.getFieldValue(entity, field);
+ return null != value ? value.toString() : null;
+ }
+ return null;
+ }
+
+ /**
+ * 依据对象的属性数组和值数组对进行赋值
+ *
+ * @param 对象
+ * @param entity 反射对象
+ * @param fields 属性数组
+ * @param value 值数组
+ */
+ public void setValue(T entity, String[] fields, Object[] value) {
+ for (int i = 0; i < fields.length; i++) {
+ String field = fields[i];
+ if (FieldKit.hasField(entity.getClass(), field)) {
+ FieldKit.setFieldValue(entity, field, value[i]);
+ }
+ }
+ }
+
+}
diff --git a/bus-base/src/main/java/org/miaixz/bus/base/entity/Message.java b/bus-core/src/main/java/org/miaixz/bus/core/basics/entity/Message.java
similarity index 89%
rename from bus-base/src/main/java/org/miaixz/bus/base/entity/Message.java
rename to bus-core/src/main/java/org/miaixz/bus/core/basics/entity/Message.java
index 296b9087ca..e3a41acaa2 100755
--- a/bus-base/src/main/java/org/miaixz/bus/base/entity/Message.java
+++ b/bus-core/src/main/java/org/miaixz/bus/core/basics/entity/Message.java
@@ -25,35 +25,39 @@
~ ~
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
*/
-package org.miaixz.bus.base.entity;
+package org.miaixz.bus.core.basics.entity;
-import lombok.*;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+import lombok.experimental.SuperBuilder;
/**
- * 返回值公用类
+ * 响应结果
*
* @author Kimi Liu
* @since Java 17+
*/
@Getter
@Setter
-@Builder
+@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
public class Message {
/**
- * 请求返回码
+ * 响应码
*/
public String errcode;
/**
- * 请求返回消息
+ * 提示信息
*/
public String errmsg;
/**
- * 请求返回数据
+ * 数据集
*/
public Object data;
diff --git a/bus-base/src/main/java/org/miaixz/bus/base/entity/OAuth2.java b/bus-core/src/main/java/org/miaixz/bus/core/basics/entity/OAuth2.java
similarity index 90%
rename from bus-base/src/main/java/org/miaixz/bus/base/entity/OAuth2.java
rename to bus-core/src/main/java/org/miaixz/bus/core/basics/entity/OAuth2.java
index 8985a4ea84..c659785ae0 100755
--- a/bus-base/src/main/java/org/miaixz/bus/base/entity/OAuth2.java
+++ b/bus-core/src/main/java/org/miaixz/bus/core/basics/entity/OAuth2.java
@@ -25,22 +25,26 @@
~ ~
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
*/
-package org.miaixz.bus.base.entity;
+package org.miaixz.bus.core.basics.entity;
import jakarta.persistence.Transient;
-import lombok.EqualsAndHashCode;
+import lombok.AllArgsConstructor;
import lombok.Getter;
+import lombok.NoArgsConstructor;
import lombok.Setter;
+import lombok.experimental.SuperBuilder;
/**
- * 授权公用类
+ * 访问授权
*
* @author Kimi Liu
* @since Java 17+
*/
@Getter
@Setter
-@EqualsAndHashCode(callSuper = true)
+@SuperBuilder
+@NoArgsConstructor
+@AllArgsConstructor
public class OAuth2 extends Entity {
private static final long serialVersionUID = 1L;
@@ -51,6 +55,12 @@ public class OAuth2 extends Entity {
@Transient
protected String x_user_id;
+ /**
+ * 当前用户编码
+ */
+ @Transient
+ protected String x_user_code;
+
/**
* 当前用户名称
*/
diff --git a/bus-base/src/main/java/org/miaixz/bus/base/entity/Result.java b/bus-core/src/main/java/org/miaixz/bus/core/basics/entity/Result.java
similarity index 76%
rename from bus-base/src/main/java/org/miaixz/bus/base/entity/Result.java
rename to bus-core/src/main/java/org/miaixz/bus/core/basics/entity/Result.java
index ff47c6124f..ce4f9d55b0 100755
--- a/bus-base/src/main/java/org/miaixz/bus/base/entity/Result.java
+++ b/bus-core/src/main/java/org/miaixz/bus/core/basics/entity/Result.java
@@ -25,66 +25,50 @@
~ ~
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
*/
-package org.miaixz.bus.base.entity;
+package org.miaixz.bus.core.basics.entity;
-import lombok.EqualsAndHashCode;
+import lombok.AllArgsConstructor;
import lombok.Getter;
+import lombok.NoArgsConstructor;
import lombok.Setter;
+import lombok.experimental.SuperBuilder;
import java.util.Collections;
import java.util.List;
/**
- * 返回结果公用
+ * 数据结果
*
* @author Kimi Liu
* @since Java 17+
*/
@Getter
@Setter
-@EqualsAndHashCode(callSuper = true)
-public class Result extends BaseEntity {
+@SuperBuilder
+@NoArgsConstructor
+@AllArgsConstructor
+public class Result {
private static final long serialVersionUID = 1L;
/**
* 总数据
*/
- protected int total;
+ protected long total;
/**
* 查询记录数
*/
protected List rows;
- public Result() {
-
- }
-
- public Result(List rows) {
- this.rows = rows;
- }
-
- public Result(int total, List rows) {
- this.total = total;
- this.rows = rows;
- }
-
- public Result(List rows, int pageSize) {
- if (null == rows || rows.isEmpty()) {
- throw new IllegalArgumentException("data must be not empty!");
- }
- new Result<>(rows, rows.size(), pageSize);
- }
-
- public Result(List rows, int total, int pageSize) {
- this.total = total;
- this.pageSize = pageSize;
- this.rows = rows;
- }
+ /**
+ * 分页页码
+ */
+ protected transient Integer pageNo;
- public static Result Result(List rows, int pageSize) {
- return new Result<>(rows, pageSize);
- }
+ /**
+ * 分页大小
+ */
+ protected transient Integer pageSize;
/**
* 得到分页后的数据
diff --git a/bus-base/src/main/java/org/miaixz/bus/base/entity/Tracer.java b/bus-core/src/main/java/org/miaixz/bus/core/basics/entity/Tracer.java
similarity index 93%
rename from bus-base/src/main/java/org/miaixz/bus/base/entity/Tracer.java
rename to bus-core/src/main/java/org/miaixz/bus/core/basics/entity/Tracer.java
index a72c7c1582..b2205d1c2c 100755
--- a/bus-base/src/main/java/org/miaixz/bus/base/entity/Tracer.java
+++ b/bus-core/src/main/java/org/miaixz/bus/core/basics/entity/Tracer.java
@@ -25,22 +25,26 @@
~ ~
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
*/
-package org.miaixz.bus.base.entity;
+package org.miaixz.bus.core.basics.entity;
import jakarta.persistence.Transient;
-import lombok.EqualsAndHashCode;
+import lombok.AllArgsConstructor;
import lombok.Getter;
+import lombok.NoArgsConstructor;
import lombok.Setter;
+import lombok.experimental.SuperBuilder;
/**
- * 访问链路跟踪
+ * 链路跟踪
*
* @author Kimi Liu
* @since Java 17+
*/
@Getter
@Setter
-@EqualsAndHashCode(callSuper = true)
+@SuperBuilder
+@NoArgsConstructor
+@AllArgsConstructor
public class Tracer extends OAuth2 {
/**
diff --git a/bus-base/src/main/java/org/miaixz/bus/base/entity/package-info.java b/bus-core/src/main/java/org/miaixz/bus/core/basics/entity/package-info.java
similarity index 98%
rename from bus-base/src/main/java/org/miaixz/bus/base/entity/package-info.java
rename to bus-core/src/main/java/org/miaixz/bus/core/basics/entity/package-info.java
index 6798618927..377aa2e3da 100644
--- a/bus-base/src/main/java/org/miaixz/bus/base/entity/package-info.java
+++ b/bus-core/src/main/java/org/miaixz/bus/core/basics/entity/package-info.java
@@ -31,4 +31,4 @@
* @author Kimi Liu
* @since Java 17+
*/
-package org.miaixz.bus.base.entity;
+package org.miaixz.bus.core.basics.entity;
diff --git a/bus-base/src/main/java/org/miaixz/bus/base/normal/Consts.java b/bus-core/src/main/java/org/miaixz/bus/core/basics/normal/Consts.java
similarity index 98%
rename from bus-base/src/main/java/org/miaixz/bus/base/normal/Consts.java
rename to bus-core/src/main/java/org/miaixz/bus/core/basics/normal/Consts.java
index 3e9b0d7b1e..04940a3a49 100755
--- a/bus-base/src/main/java/org/miaixz/bus/base/normal/Consts.java
+++ b/bus-core/src/main/java/org/miaixz/bus/core/basics/normal/Consts.java
@@ -25,13 +25,13 @@
~ ~
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
*/
-package org.miaixz.bus.base.normal;
+package org.miaixz.bus.core.basics.normal;
import org.miaixz.bus.core.lang.Normal;
import org.miaixz.bus.core.lang.Symbol;
/**
- * 公共常量
+ * 业务常量
*
* @author Kimi Liu
* @since Java 17+
diff --git a/bus-base/src/main/java/org/miaixz/bus/base/normal/ErrorCode.java b/bus-core/src/main/java/org/miaixz/bus/core/basics/normal/ErrorCode.java
similarity index 98%
rename from bus-base/src/main/java/org/miaixz/bus/base/normal/ErrorCode.java
rename to bus-core/src/main/java/org/miaixz/bus/core/basics/normal/ErrorCode.java
index 3f2361a39a..bffffbebd0 100755
--- a/bus-base/src/main/java/org/miaixz/bus/base/normal/ErrorCode.java
+++ b/bus-core/src/main/java/org/miaixz/bus/core/basics/normal/ErrorCode.java
@@ -25,7 +25,7 @@
~ ~
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
*/
-package org.miaixz.bus.base.normal;
+package org.miaixz.bus.core.basics.normal;
import org.miaixz.bus.core.lang.Symbol;
import org.miaixz.bus.core.lang.exception.InternalException;
@@ -236,7 +236,7 @@ public class ErrorCode {
/**
* 任务执行失败
*/
- public static String EM_100514 = "100514";
+ public static String EM_100600 = "100600";
/**
* 错误码缓存
@@ -292,7 +292,7 @@ public class ErrorCode {
register(EM_100511, "验证失败!");
register(EM_100512, "数据已存在");
register(EM_100513, "业务处理失败");
- register(EM_100514, "任务执行失败");
+ register(EM_100600, "任务执行失败");
}
/**
diff --git a/bus-base/src/main/java/org/miaixz/bus/base/normal/package-info.java b/bus-core/src/main/java/org/miaixz/bus/core/basics/normal/package-info.java
similarity index 98%
rename from bus-base/src/main/java/org/miaixz/bus/base/normal/package-info.java
rename to bus-core/src/main/java/org/miaixz/bus/core/basics/normal/package-info.java
index 01f914517c..f86ae8128f 100644
--- a/bus-base/src/main/java/org/miaixz/bus/base/normal/package-info.java
+++ b/bus-core/src/main/java/org/miaixz/bus/core/basics/normal/package-info.java
@@ -31,4 +31,4 @@
* @author Kimi Liu
* @since Java 17+
*/
-package org.miaixz.bus.base.normal;
+package org.miaixz.bus.core.basics.normal;
diff --git a/bus-base/src/main/java/org/miaixz/bus/base/service/impl/package-info.java b/bus-core/src/main/java/org/miaixz/bus/core/basics/package-info.java
similarity index 97%
rename from bus-base/src/main/java/org/miaixz/bus/base/service/impl/package-info.java
rename to bus-core/src/main/java/org/miaixz/bus/core/basics/package-info.java
index de98252e9b..8e02eead6c 100644
--- a/bus-base/src/main/java/org/miaixz/bus/base/service/impl/package-info.java
+++ b/bus-core/src/main/java/org/miaixz/bus/core/basics/package-info.java
@@ -26,9 +26,9 @@
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
*/
/**
- * 基础业务实现
+ * 业务基础功能
*
* @author Kimi Liu
* @since Java 17+
*/
-package org.miaixz.bus.base.service.impl;
+package org.miaixz.bus.core.basics;
diff --git a/bus-base/src/main/java/org/miaixz/bus/base/service/ErrorService.java b/bus-core/src/main/java/org/miaixz/bus/core/basics/service/ErrorService.java
similarity index 81%
rename from bus-base/src/main/java/org/miaixz/bus/base/service/ErrorService.java
rename to bus-core/src/main/java/org/miaixz/bus/core/basics/service/ErrorService.java
index 249b34b146..9283ba5aca 100644
--- a/bus-base/src/main/java/org/miaixz/bus/base/service/ErrorService.java
+++ b/bus-core/src/main/java/org/miaixz/bus/core/basics/service/ErrorService.java
@@ -25,27 +25,26 @@
~ ~
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
*/
-package org.miaixz.bus.base.service;
+package org.miaixz.bus.core.basics.service;
-import lombok.NoArgsConstructor;
+import org.miaixz.bus.core.lang.Console;
import org.miaixz.bus.core.xyz.ExceptionKit;
-import org.miaixz.bus.logger.Logger;
/**
* 异常信息处理
* 此类未找到实现的情况下,采用默认实现
- * 可以根据不同业务需求,继承此类实现对应业务逻辑即可
- * 项目中可通过SPI自定义接入
- * 例:META-INF/services/org.miaixz.bus.base.service.ErrorService
+ * 可以根据不同业务需求,重写方法实现对应业务逻辑即可
+ * 项目中可通过SPI形式接入
+ * 例:META-INF/services/org.miaixz.bus.core.basics.service.ErrorService
*
- * org.miaixz.bus.xxx.ErrorService
+ * org.miaixz.bus.xxx.BusinessErrorService
+ * ......
*
*
* @author Kimi Liu
* @since Java 17+
*/
-@NoArgsConstructor
-public class ErrorService {
+public interface ErrorService {
/**
* 完成请求处理前调用
@@ -53,8 +52,8 @@ public class ErrorService {
* @param ex 对象参数
* @return 如果执行链应该继续执行, 则为:true 否则:false
*/
- public boolean before(Exception ex) {
- Logger.error(ExceptionKit.stacktraceToString(ex));
+ default boolean before(Exception ex) {
+ Console.error("Before error of : " + ExceptionKit.stacktraceToString(ex));
return true;
}
@@ -64,7 +63,8 @@ public boolean before(Exception ex) {
* @param ex 对象参数
* @return 如果执行链应该继续执行, 则为:true 否则:false
*/
- public boolean after(Exception ex) {
+ default boolean after(Exception ex) {
+ Console.error("After error of : " + ExceptionKit.stacktraceToString(ex));
return true;
}
diff --git a/bus-base/src/main/java/org/miaixz/bus/base/service/Service.java b/bus-core/src/main/java/org/miaixz/bus/core/basics/service/Service.java
similarity index 98%
rename from bus-base/src/main/java/org/miaixz/bus/base/service/Service.java
rename to bus-core/src/main/java/org/miaixz/bus/core/basics/service/Service.java
index f42a793f3f..a50a1675c3 100755
--- a/bus-base/src/main/java/org/miaixz/bus/base/service/Service.java
+++ b/bus-core/src/main/java/org/miaixz/bus/core/basics/service/Service.java
@@ -25,7 +25,7 @@
~ ~
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
*/
-package org.miaixz.bus.base.service;
+package org.miaixz.bus.core.basics.service;
/**
* Service 接口
diff --git a/bus-core/src/main/java/org/miaixz/bus/core/basics/service/package-info.java b/bus-core/src/main/java/org/miaixz/bus/core/basics/service/package-info.java
new file mode 100644
index 0000000000..94303d6559
--- /dev/null
+++ b/bus-core/src/main/java/org/miaixz/bus/core/basics/service/package-info.java
@@ -0,0 +1,34 @@
+/*
+ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
+ ~ ~
+ ~ The MIT License (MIT) ~
+ ~ ~
+ ~ Copyright (c) 2015-2024 miaixz.org and other contributors. ~
+ ~ ~
+ ~ Permission is hereby granted, free of charge, to any person obtaining a copy ~
+ ~ of this software and associated documentation files (the "Software"), to deal ~
+ ~ in the Software without restriction, including without limitation the rights ~
+ ~ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell ~
+ ~ copies of the Software, and to permit persons to whom the Software is ~
+ ~ furnished to do so, subject to the following conditions: ~
+ ~ ~
+ ~ The above copyright notice and this permission notice shall be included in ~
+ ~ all copies or substantial portions of the Software. ~
+ ~ ~
+ ~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR ~
+ ~ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, ~
+ ~ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE ~
+ ~ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER ~
+ ~ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, ~
+ ~ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN ~
+ ~ THE SOFTWARE. ~
+ ~ ~
+ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
+ */
+/**
+ * 业务接口
+ *
+ * @author Kimi Liu
+ * @since Java 17+
+ */
+package org.miaixz.bus.core.basics.service;
diff --git a/bus-base/src/main/java/org/miaixz/bus/base/spring/Controller.java b/bus-core/src/main/java/org/miaixz/bus/core/basics/spring/Controller.java
similarity index 97%
rename from bus-base/src/main/java/org/miaixz/bus/base/spring/Controller.java
rename to bus-core/src/main/java/org/miaixz/bus/core/basics/spring/Controller.java
index 7786d7a159..309e6dcdaf 100755
--- a/bus-base/src/main/java/org/miaixz/bus/base/spring/Controller.java
+++ b/bus-core/src/main/java/org/miaixz/bus/core/basics/spring/Controller.java
@@ -25,10 +25,10 @@
~ ~
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
*/
-package org.miaixz.bus.base.spring;
+package org.miaixz.bus.core.basics.spring;
-import org.miaixz.bus.base.entity.Message;
-import org.miaixz.bus.base.normal.ErrorCode;
+import org.miaixz.bus.core.basics.entity.Message;
+import org.miaixz.bus.core.basics.normal.ErrorCode;
import org.miaixz.bus.core.xyz.StringKit;
/**
diff --git a/bus-core/src/main/java/org/miaixz/bus/core/basics/spring/package-info.java b/bus-core/src/main/java/org/miaixz/bus/core/basics/spring/package-info.java
new file mode 100644
index 0000000000..864518fe78
--- /dev/null
+++ b/bus-core/src/main/java/org/miaixz/bus/core/basics/spring/package-info.java
@@ -0,0 +1,34 @@
+/*
+ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
+ ~ ~
+ ~ The MIT License (MIT) ~
+ ~ ~
+ ~ Copyright (c) 2015-2024 miaixz.org and other contributors. ~
+ ~ ~
+ ~ Permission is hereby granted, free of charge, to any person obtaining a copy ~
+ ~ of this software and associated documentation files (the "Software"), to deal ~
+ ~ in the Software without restriction, including without limitation the rights ~
+ ~ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell ~
+ ~ copies of the Software, and to permit persons to whom the Software is ~
+ ~ furnished to do so, subject to the following conditions: ~
+ ~ ~
+ ~ The above copyright notice and this permission notice shall be included in ~
+ ~ all copies or substantial portions of the Software. ~
+ ~ ~
+ ~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR ~
+ ~ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, ~
+ ~ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE ~
+ ~ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER ~
+ ~ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, ~
+ ~ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN ~
+ ~ THE SOFTWARE. ~
+ ~ ~
+ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
+ */
+/**
+ * 业务控制器
+ *
+ * @author Kimi Liu
+ * @since Java 17+
+ */
+package org.miaixz.bus.core.basics.spring;
diff --git a/bus-core/src/main/java/org/miaixz/bus/core/beans/BeanDescCache.java b/bus-core/src/main/java/org/miaixz/bus/core/beans/BeanDescCache.java
index 3c68580b3d..763927788b 100644
--- a/bus-core/src/main/java/org/miaixz/bus/core/beans/BeanDescCache.java
+++ b/bus-core/src/main/java/org/miaixz/bus/core/beans/BeanDescCache.java
@@ -27,9 +27,10 @@
*/
package org.miaixz.bus.core.beans;
-import org.miaixz.bus.core.center.function.SupplierX;
import org.miaixz.bus.core.center.map.reference.WeakConcurrentMap;
+import java.util.function.Supplier;
+
/**
* Bean属性缓存
* 缓存用于防止多次反射造成的性能问题
@@ -44,17 +45,18 @@ public enum BeanDescCache {
*/
INSTANCE;
- private final WeakConcurrentMap, StrictBeanDesc> bdCache = new WeakConcurrentMap<>();
+ private final WeakConcurrentMap, BeanDesc> bdCache = new WeakConcurrentMap<>();
/**
- * 获得属性名和{@link StrictBeanDesc}Map映射
+ * 获得属性名和{@link BeanDesc}Map映射
*
* @param beanClass Bean的类
* @param supplier 对象不存在时创建对象的函数
- * @return 属性名和 {@link StrictBeanDesc}映射
+ * @param BeanDesc子类
+ * @return 属性名和 {@link BeanDesc}映射
*/
- public StrictBeanDesc getBeanDesc(final Class> beanClass, final SupplierX supplier) {
- return bdCache.computeIfAbsent(beanClass, (key) -> supplier.get());
+ public T getBeanDesc(final Class> beanClass, final Supplier supplier) {
+ return (T) bdCache.computeIfAbsent(beanClass, (key) -> supplier.get());
}
/**
diff --git a/bus-core/src/main/java/org/miaixz/bus/core/cache/provider/AbstractCache.java b/bus-core/src/main/java/org/miaixz/bus/core/cache/provider/AbstractCache.java
index 010e63495e..b431e34cb7 100644
--- a/bus-core/src/main/java/org/miaixz/bus/core/cache/provider/AbstractCache.java
+++ b/bus-core/src/main/java/org/miaixz/bus/core/cache/provider/AbstractCache.java
@@ -111,10 +111,18 @@ protected void putWithoutLock(final K key, final V object, final long timeout) {
if (timeout != 0) {
existCustomTimeout = true;
}
- if (isFull()) {
- pruneCache();
+ final MutableObject mKey = MutableObject.of(key);
+
+ // 对于替换的键值对,不做满队列检查和清除
+ if (cacheMap.containsKey(mKey)) {
+ // 存在相同key,覆盖之
+ cacheMap.put(mKey, co);
+ } else {
+ if (isFull()) {
+ pruneCache();
+ }
+ cacheMap.put(mKey, co);
}
- cacheMap.put(MutableObject.of(key), co);
}
/**
diff --git a/bus-storage/src/main/java/org/miaixz/bus/storage/magic/Message.java b/bus-core/src/main/java/org/miaixz/bus/core/center/BoundedCollection.java
old mode 100755
new mode 100644
similarity index 83%
rename from bus-storage/src/main/java/org/miaixz/bus/storage/magic/Message.java
rename to bus-core/src/main/java/org/miaixz/bus/core/center/BoundedCollection.java
index e6266c399f..758bd3e052
--- a/bus-storage/src/main/java/org/miaixz/bus/storage/magic/Message.java
+++ b/bus-core/src/main/java/org/miaixz/bus/core/center/BoundedCollection.java
@@ -25,34 +25,31 @@
~ ~
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
*/
-package org.miaixz.bus.storage.magic;
+package org.miaixz.bus.core.center;
-import lombok.Builder;
-import lombok.Getter;
+import java.util.Collection;
/**
- * 响应结果
+ * 有边界限制的集合,边界集合有最大容量限制
*
+ * @param 元素类型
* @author Kimi Liu
* @since Java 17+
*/
-@Getter
-@Builder
-public class Message {
+public interface BoundedCollection extends Collection {
/**
- * 请求返回码,正确为 0
+ * 是否已满,如果集合已满,不允许新增元素
+ *
+ * @return 是否已满
*/
- public String errcode;
+ boolean isFull();
/**
- * 请求返回消息
+ * 获取集合最大允许容量
+ *
+ * @return 容量
*/
- public String errmsg;
-
- /**
- * 请求返回数据
- */
- public Object data;
+ int maxSize();
}
diff --git a/bus-core/src/main/java/org/miaixz/bus/core/center/CollectionOperation.java b/bus-core/src/main/java/org/miaixz/bus/core/center/CollectionOperation.java
index 2a5122f2c8..2c4cc704d2 100644
--- a/bus-core/src/main/java/org/miaixz/bus/core/center/CollectionOperation.java
+++ b/bus-core/src/main/java/org/miaixz/bus/core/center/CollectionOperation.java
@@ -44,7 +44,7 @@
* 求集合的差集
*
*
- * @param 集合元素类型
+ * @param 元素类型
* @author Kimi Liu
* @since Java 17+
*/
diff --git a/bus-core/src/main/java/org/miaixz/bus/core/center/TransCollection.java b/bus-core/src/main/java/org/miaixz/bus/core/center/TransCollection.java
index e09a6fdebf..d60ac30d4e 100644
--- a/bus-core/src/main/java/org/miaixz/bus/core/center/TransCollection.java
+++ b/bus-core/src/main/java/org/miaixz/bus/core/center/TransCollection.java
@@ -48,17 +48,17 @@
*/
public class TransCollection extends AbstractCollection {
- private final Collection fromCollection;
+ private final Collection from;
private final Function super F, ? extends T> function;
/**
* 构造
*
- * @param fromCollection 源集合
+ * @param from 源集合
* @param function 转换函数
*/
- public TransCollection(final Collection fromCollection, final Function super F, ? extends T> function) {
- this.fromCollection = Assert.notNull(fromCollection);
+ public TransCollection(final Collection from, final Function super F, ? extends T> function) {
+ this.from = Assert.notNull(from);
this.function = Assert.notNull(function);
}
@@ -67,49 +67,49 @@ public TransCollection(final Collection fromCollection, final Function supe
*
* @param 源元素类型
* @param 目标元素类型
- * @param fromSpliterator 源{@link Spliterator}
+ * @param from 源{@link Spliterator}
* @param function 转换函数
* @return 新类型的{@link Spliterator}
*/
- public static Spliterator trans(final Spliterator fromSpliterator, final Function super F, ? extends T> function) {
- return new TransSpliterator<>(fromSpliterator, function);
+ public static Spliterator trans(final Spliterator from, final Function super F, ? extends T> function) {
+ return new TransSpliterator<>(from, function);
}
@Override
public Iterator iterator() {
- return IteratorKit.trans(fromCollection.iterator(), function);
+ return IteratorKit.trans(from.iterator(), function);
}
@Override
public void clear() {
- fromCollection.clear();
+ from.clear();
}
@Override
public boolean isEmpty() {
- return fromCollection.isEmpty();
+ return from.isEmpty();
}
@Override
public void forEach(final Consumer super T> action) {
Assert.notNull(action);
- fromCollection.forEach((f) -> action.accept(function.apply(f)));
+ from.forEach((f) -> action.accept(function.apply(f)));
}
@Override
public boolean removeIf(final Predicate super T> filter) {
Assert.notNull(filter);
- return fromCollection.removeIf(element -> filter.test(function.apply(element)));
+ return from.removeIf(element -> filter.test(function.apply(element)));
}
@Override
public Spliterator spliterator() {
- return trans(fromCollection.spliterator(), function);
+ return trans(from.spliterator(), function);
}
@Override
public int size() {
- return fromCollection.size();
+ return from.size();
}
}
diff --git a/bus-core/src/main/java/org/miaixz/bus/core/center/TransSpliterator.java b/bus-core/src/main/java/org/miaixz/bus/core/center/TransSpliterator.java
index d9aa060e7d..a812524ccf 100644
--- a/bus-core/src/main/java/org/miaixz/bus/core/center/TransSpliterator.java
+++ b/bus-core/src/main/java/org/miaixz/bus/core/center/TransSpliterator.java
@@ -41,45 +41,45 @@
*/
public class TransSpliterator implements Spliterator {
- private final Spliterator fromSpliterator;
+ private final Spliterator from;
private final Function super F, ? extends T> function;
/**
* 构造
*
- * @param fromSpliterator 源iterator
+ * @param from 源iterator
* @param function 函数
*/
- public TransSpliterator(final Spliterator fromSpliterator, final Function super F, ? extends T> function) {
- this.fromSpliterator = fromSpliterator;
+ public TransSpliterator(final Spliterator from, final Function super F, ? extends T> function) {
+ this.from = from;
this.function = function;
}
@Override
public boolean tryAdvance(final Consumer super T> action) {
- return fromSpliterator.tryAdvance(
+ return from.tryAdvance(
fromElement -> action.accept(function.apply(fromElement)));
}
@Override
public void forEachRemaining(final Consumer super T> action) {
- fromSpliterator.forEachRemaining(fromElement -> action.accept(function.apply(fromElement)));
+ from.forEachRemaining(fromElement -> action.accept(function.apply(fromElement)));
}
@Override
public Spliterator trySplit() {
- final Spliterator fromSplit = fromSpliterator.trySplit();
+ final Spliterator fromSplit = from.trySplit();
return (fromSplit != null) ? new TransSpliterator<>(fromSplit, function) : null;
}
@Override
public long estimateSize() {
- return fromSpliterator.estimateSize();
+ return from.estimateSize();
}
@Override
public int characteristics() {
- return fromSpliterator.characteristics()
+ return from.characteristics()
& ~(Spliterator.DISTINCT | Spliterator.NONNULL | Spliterator.SORTED);
}
diff --git a/bus-core/src/main/java/org/miaixz/bus/core/center/date/builder/DateBuilder.java b/bus-core/src/main/java/org/miaixz/bus/core/center/date/builder/DateBuilder.java
index 8c615f4c4c..54de95170e 100644
--- a/bus-core/src/main/java/org/miaixz/bus/core/center/date/builder/DateBuilder.java
+++ b/bus-core/src/main/java/org/miaixz/bus/core/center/date/builder/DateBuilder.java
@@ -495,7 +495,7 @@ public Calendar toCalendar() {
*
* @return LocalDateTime 表示当前对象日期时间的LocalDateTime实例。
*/
- LocalDateTime toLocalDateTime() {
+ public LocalDateTime toLocalDateTime() {
this.prepare();
// 如果unixsecond大于0,使用unix时间戳创建LocalDateTime
@@ -532,7 +532,7 @@ LocalDateTime toLocalDateTime() {
*
* @return OffsetDateTime 表示当前时间的 OffsetDateTime 对象。
*/
- OffsetDateTime toOffsetDateTime() {
+ public OffsetDateTime toOffsetDateTime() {
// 准备工作,可能涉及一些初始化或数据处理
this.prepare();
diff --git a/bus-core/src/main/java/org/miaixz/bus/core/center/date/culture/Galaxy.java b/bus-core/src/main/java/org/miaixz/bus/core/center/date/culture/Galaxy.java
index 2057f06976..f8f82b5432 100644
--- a/bus-core/src/main/java/org/miaixz/bus/core/center/date/culture/Galaxy.java
+++ b/bus-core/src/main/java/org/miaixz/bus/core/center/date/culture/Galaxy.java
@@ -658,10 +658,7 @@ public static double qiAccurate2(double jd) {
if (a - jd > 5) {
return qiAccurate(w - d);
}
- if (a - jd < -5) {
- return qiAccurate(w + d);
- }
- return a;
+ return a - jd < -5 ? qiAccurate(w + d) : a;
}
}
diff --git a/bus-core/src/main/java/org/miaixz/bus/core/center/date/culture/Holiday.java b/bus-core/src/main/java/org/miaixz/bus/core/center/date/culture/Holiday.java
index 7c91ac7c74..2269c17a0e 100755
--- a/bus-core/src/main/java/org/miaixz/bus/core/center/date/culture/Holiday.java
+++ b/bus-core/src/main/java/org/miaixz/bus/core/center/date/culture/Holiday.java
@@ -280,12 +280,10 @@ public Holiday(int year, int month, int day, String data) {
public static Holiday fromYmd(int year, int month, int day) {
Matcher matcher = Pattern.compile(String.format("%04d%02d%02d[0-1][0-8][\\+|-]\\d{2}", year, month, day)).matcher(DATA);
- if (!matcher.find()) {
- return null;
- }
- return new Holiday(year, month, day, matcher.group());
+ return !matcher.find() ? null : new Holiday(year, month, day, matcher.group());
}
+
public Holiday next(int n) {
SolarMonth m = day.getMonth();
int year = m.getYear().getYear();
diff --git a/bus-core/src/main/java/org/miaixz/bus/core/center/date/culture/cn/birth/Fortune.java b/bus-core/src/main/java/org/miaixz/bus/core/center/date/culture/cn/birth/Fortune.java
index 5f33449c14..49575631b9 100755
--- a/bus-core/src/main/java/org/miaixz/bus/core/center/date/culture/cn/birth/Fortune.java
+++ b/bus-core/src/main/java/org/miaixz/bus/core/center/date/culture/cn/birth/Fortune.java
@@ -59,7 +59,7 @@ public Fortune(ChildLimit childLimit, int index) {
*
* @param childLimit 童限
* @param index 序号
- * @return 大运
+ * @return 小运
*/
public static Fortune fromChildLimit(ChildLimit childLimit, int index) {
return new Fortune(childLimit, index);
diff --git a/bus-core/src/main/java/org/miaixz/bus/core/center/date/culture/cn/plumrain/PlumRain.java b/bus-core/src/main/java/org/miaixz/bus/core/center/date/culture/cn/plumrain/PlumRain.java
new file mode 100755
index 0000000000..a2221631e1
--- /dev/null
+++ b/bus-core/src/main/java/org/miaixz/bus/core/center/date/culture/cn/plumrain/PlumRain.java
@@ -0,0 +1,74 @@
+/*
+ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
+ ~ ~
+ ~ The MIT License (MIT) ~
+ ~ ~
+ ~ Copyright (c) 2015-2024 miaixz.org 6tail and other contributors. ~
+ ~ ~
+ ~ Permission is hereby granted, free of charge, to any person obtaining a copy ~
+ ~ of this software and associated documentation files (the "Software"), to deal ~
+ ~ in the Software without restriction, including without limitation the rights ~
+ ~ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell ~
+ ~ copies of the Software, and to permit persons to whom the Software is ~
+ ~ furnished to do so, subject to the following conditions: ~
+ ~ ~
+ ~ The above copyright notice and this permission notice shall be included in ~
+ ~ all copies or substantial portions of the Software. ~
+ ~ ~
+ ~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR ~
+ ~ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, ~
+ ~ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE ~
+ ~ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER ~
+ ~ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, ~
+ ~ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN ~
+ ~ THE SOFTWARE. ~
+ ~ ~
+ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
+*/
+package org.miaixz.bus.core.center.date.culture.cn.plumrain;
+
+import org.miaixz.bus.core.center.date.culture.Samsara;
+
+/**
+ * 梅雨
+ *
+ * @author Kimi Liu
+ * @since Java 17+
+ */
+public class PlumRain extends Samsara {
+
+ public static final String[] NAMES = {"入梅", "出梅"};
+
+ public PlumRain(String name) {
+ super(NAMES, name);
+ }
+
+ public PlumRain(int index) {
+ super(NAMES, index);
+ }
+
+ /**
+ * 从名称初始化
+ *
+ * @param name 名称
+ * @return 梅雨
+ */
+ public static PlumRain fromName(String name) {
+ return new PlumRain(name);
+ }
+
+ /**
+ * 从索引初始化
+ *
+ * @param index 索引
+ * @return 梅雨
+ */
+ public static PlumRain fromIndex(int index) {
+ return new PlumRain(index);
+ }
+
+ public PlumRain next(int n) {
+ return fromIndex(nextIndex(n));
+ }
+
+}
diff --git a/bus-core/src/main/java/org/miaixz/bus/core/lang/thread/threadlocal/NamedInheritableThreadLocal.java b/bus-core/src/main/java/org/miaixz/bus/core/center/date/culture/cn/plumrain/PlumRainDay.java
old mode 100644
new mode 100755
similarity index 79%
rename from bus-core/src/main/java/org/miaixz/bus/core/lang/thread/threadlocal/NamedInheritableThreadLocal.java
rename to bus-core/src/main/java/org/miaixz/bus/core/center/date/culture/cn/plumrain/PlumRainDay.java
index f5187e4c7f..b50a170c4a
--- a/bus-core/src/main/java/org/miaixz/bus/core/lang/thread/threadlocal/NamedInheritableThreadLocal.java
+++ b/bus-core/src/main/java/org/miaixz/bus/core/center/date/culture/cn/plumrain/PlumRainDay.java
@@ -3,7 +3,7 @@
~ ~
~ The MIT License (MIT) ~
~ ~
- ~ Copyright (c) 2015-2024 miaixz.org and other contributors. ~
+ ~ Copyright (c) 2015-2024 miaixz.org 6tail and other contributors. ~
~ ~
~ Permission is hereby granted, free of charge, to any person obtaining a copy ~
~ of this software and associated documentation files (the "Software"), to deal ~
@@ -24,32 +24,35 @@
~ THE SOFTWARE. ~
~ ~
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
- */
-package org.miaixz.bus.core.lang.thread.threadlocal;
+*/
+package org.miaixz.bus.core.center.date.culture.cn.plumrain;
+
+import org.miaixz.bus.core.center.date.culture.Replenish;
/**
- * 带有Name标识的 {@link InheritableThreadLocal},调用toString返回name
+ * 梅雨天
*
- * @param 值类型
* @author Kimi Liu
* @since Java 17+
*/
-public class NamedInheritableThreadLocal extends InheritableThreadLocal {
+public class PlumRainDay extends Replenish {
- private final String name;
+ public PlumRainDay(PlumRain plumRain, int dayIndex) {
+ super(plumRain, dayIndex);
+ }
/**
- * 构造
+ * 梅雨
*
- * @param name 名字
+ * @return 梅雨
*/
- public NamedInheritableThreadLocal(final String name) {
- this.name = name;
+ public PlumRain getPlumRain() {
+ return (PlumRain) tradition;
}
@Override
public String toString() {
- return this.name;
+ return getPlumRain().getIndex() == 0 ? super.toString() : tradition.getName();
}
}
diff --git a/bus-core/src/main/java/org/miaixz/bus/core/center/date/culture/cn/plumrain/package-info.java b/bus-core/src/main/java/org/miaixz/bus/core/center/date/culture/cn/plumrain/package-info.java
new file mode 100644
index 0000000000..83c6146538
--- /dev/null
+++ b/bus-core/src/main/java/org/miaixz/bus/core/center/date/culture/cn/plumrain/package-info.java
@@ -0,0 +1,34 @@
+/*
+ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
+ ~ ~
+ ~ The MIT License (MIT) ~
+ ~ ~
+ ~ Copyright (c) 2015-2024 miaixz.org and other contributors. ~
+ ~ ~
+ ~ Permission is hereby granted, free of charge, to any person obtaining a copy ~
+ ~ of this software and associated documentation files (the "Software"), to deal ~
+ ~ in the Software without restriction, including without limitation the rights ~
+ ~ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell ~
+ ~ copies of the Software, and to permit persons to whom the Software is ~
+ ~ furnished to do so, subject to the following conditions: ~
+ ~ ~
+ ~ The above copyright notice and this permission notice shall be included in ~
+ ~ all copies or substantial portions of the Software. ~
+ ~ ~
+ ~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR ~
+ ~ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, ~
+ ~ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE ~
+ ~ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER ~
+ ~ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, ~
+ ~ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN ~
+ ~ THE SOFTWARE. ~
+ ~ ~
+ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
+ */
+/**
+ * 梅雨
+ *
+ * @author Kimi Liu
+ * @since Java 17+
+ */
+package org.miaixz.bus.core.center.date.culture.cn.plumrain;
diff --git a/bus-core/src/main/java/org/miaixz/bus/core/lang/thread/threadlocal/NamedThreadLocal.java b/bus-core/src/main/java/org/miaixz/bus/core/center/date/culture/cn/star/six/SixStar.java
old mode 100644
new mode 100755
similarity index 72%
rename from bus-core/src/main/java/org/miaixz/bus/core/lang/thread/threadlocal/NamedThreadLocal.java
rename to bus-core/src/main/java/org/miaixz/bus/core/center/date/culture/cn/star/six/SixStar.java
index 4034bb9eaa..81ce893cae
--- a/bus-core/src/main/java/org/miaixz/bus/core/lang/thread/threadlocal/NamedThreadLocal.java
+++ b/bus-core/src/main/java/org/miaixz/bus/core/center/date/culture/cn/star/six/SixStar.java
@@ -3,7 +3,7 @@
~ ~
~ The MIT License (MIT) ~
~ ~
- ~ Copyright (c) 2015-2024 miaixz.org and other contributors. ~
+ ~ Copyright (c) 2015-2024 miaixz.org 6tail and other contributors. ~
~ ~
~ Permission is hereby granted, free of charge, to any person obtaining a copy ~
~ of this software and associated documentation files (the "Software"), to deal ~
@@ -24,32 +24,39 @@
~ THE SOFTWARE. ~
~ ~
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
- */
-package org.miaixz.bus.core.lang.thread.threadlocal;
+*/
+package org.miaixz.bus.core.center.date.culture.cn.star.six;
+
+import org.miaixz.bus.core.center.date.culture.Samsara;
/**
- * 带有Name标识的 {@link ThreadLocal},调用toString返回name
+ * 六曜(孔明六曜星、小六壬)
*
- * @param 值类型
* @author Kimi Liu
* @since Java 17+
*/
-public class NamedThreadLocal extends ThreadLocal {
+public class SixStar extends Samsara {
+
+ public static final String[] NAMES = {"先胜", "友引", "先负", "佛灭", "大安", "赤口"};
+
+ public SixStar(int index) {
+ super(NAMES, index);
+ }
+
+ public SixStar(String name) {
+ super(NAMES, name);
+ }
- private final String name;
+ public static SixStar fromIndex(int index) {
+ return new SixStar(index);
+ }
- /**
- * 构造
- *
- * @param name 名字
- */
- public NamedThreadLocal(final String name) {
- this.name = name;
+ public static SixStar fromName(String name) {
+ return new SixStar(name);
}
- @Override
- public String toString() {
- return this.name;
+ public SixStar next(int n) {
+ return fromIndex(nextIndex(n));
}
}
diff --git a/bus-core/src/main/java/org/miaixz/bus/core/center/date/culture/cn/star/six/package-info.java b/bus-core/src/main/java/org/miaixz/bus/core/center/date/culture/cn/star/six/package-info.java
new file mode 100644
index 0000000000..d4c13a2ff7
--- /dev/null
+++ b/bus-core/src/main/java/org/miaixz/bus/core/center/date/culture/cn/star/six/package-info.java
@@ -0,0 +1,34 @@
+/*
+ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
+ ~ ~
+ ~ The MIT License (MIT) ~
+ ~ ~
+ ~ Copyright (c) 2015-2024 miaixz.org and other contributors. ~
+ ~ ~
+ ~ Permission is hereby granted, free of charge, to any person obtaining a copy ~
+ ~ of this software and associated documentation files (the "Software"), to deal ~
+ ~ in the Software without restriction, including without limitation the rights ~
+ ~ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell ~
+ ~ copies of the Software, and to permit persons to whom the Software is ~
+ ~ furnished to do so, subject to the following conditions: ~
+ ~ ~
+ ~ The above copyright notice and this permission notice shall be included in ~
+ ~ all copies or substantial portions of the Software. ~
+ ~ ~
+ ~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR ~
+ ~ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, ~
+ ~ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE ~
+ ~ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER ~
+ ~ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, ~
+ ~ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN ~
+ ~ THE SOFTWARE. ~
+ ~ ~
+ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
+ */
+/**
+ * 六曜(孔明六曜星、小六壬)
+ *
+ * @author Kimi Liu
+ * @since Java 17+
+ */
+package org.miaixz.bus.core.center.date.culture.cn.star.six;
diff --git a/bus-core/src/main/java/org/miaixz/bus/core/center/date/culture/lunar/LunarDay.java b/bus-core/src/main/java/org/miaixz/bus/core/center/date/culture/lunar/LunarDay.java
index 4dbd7998b5..efad450622 100755
--- a/bus-core/src/main/java/org/miaixz/bus/core/center/date/culture/lunar/LunarDay.java
+++ b/bus-core/src/main/java/org/miaixz/bus/core/center/date/culture/lunar/LunarDay.java
@@ -37,6 +37,7 @@
import org.miaixz.bus.core.center.date.culture.cn.sixty.HeavenStem;
import org.miaixz.bus.core.center.date.culture.cn.sixty.SixtyCycle;
import org.miaixz.bus.core.center.date.culture.cn.star.nine.NineStar;
+import org.miaixz.bus.core.center.date.culture.cn.star.six.SixStar;
import org.miaixz.bus.core.center.date.culture.cn.star.twelve.TwelveStar;
import org.miaixz.bus.core.center.date.culture.cn.star.twentyeight.TwentyEightStar;
import org.miaixz.bus.core.center.date.culture.solar.SolarDay;
@@ -125,21 +126,21 @@ public LunarDay next(int n) {
return fromYmd(month.getYear().getYear(), month.getMonthWithLeap(), day);
}
int d = day + n;
- LunarMonth lm = month;
- int daysInMonth = lm.getDayCount();
+ LunarMonth m = month;
+ int daysInMonth = m.getDayCount();
boolean forward = n > 0;
int add = forward ? 1 : -1;
while (forward ? (d > daysInMonth) : (d <= 0)) {
if (forward) {
d -= daysInMonth;
}
- lm = lm.next(add);
- daysInMonth = lm.getDayCount();
+ m = m.next(add);
+ daysInMonth = m.getDayCount();
if (!forward) {
d += daysInMonth;
}
}
- return fromYmd(lm.getYear().getYear(), lm.getMonthWithLeap(), d);
+ return fromYmd(m.getYear().getYear(), m.getMonthWithLeap(), d);
}
/**
@@ -149,21 +150,19 @@ public LunarDay next(int n) {
* @return true/false
*/
public boolean isBefore(LunarDay target) {
+ LunarMonth bMonth = target.getMonth();
int aYear = month.getYear().getYear();
- LunarMonth targetMonth = target.getMonth();
- int bYear = targetMonth.getYear().getYear();
- if (aYear == bYear) {
- int aMonth = month.getMonth();
- int bMonth = targetMonth.getMonth();
- if (aMonth == bMonth) {
- if (month.isLeap() && !targetMonth.isLeap()) {
- return false;
- }
- return day < target.getDay();
- }
- return aMonth < bMonth;
+ int bYear = bMonth.getYear().getYear();
+ if (aYear != bYear) {
+ return aYear < bYear;
+ }
+ if (month.getMonth() != bMonth.getMonth()) {
+ return month.getMonth() < bMonth.getMonth();
+ }
+ if (month.isLeap() && !bMonth.isLeap()) {
+ return false;
}
- return aYear < bYear;
+ return day < target.getDay();
}
/**
@@ -173,21 +172,19 @@ public boolean isBefore(LunarDay target) {
* @return true/false
*/
public boolean isAfter(LunarDay target) {
+ LunarMonth bMonth = target.getMonth();
int aYear = month.getYear().getYear();
- LunarMonth targetMonth = target.getMonth();
- int bYear = targetMonth.getYear().getYear();
- if (aYear == bYear) {
- int aMonth = month.getMonth();
- int bMonth = targetMonth.getMonth();
- if (aMonth == bMonth) {
- if (month.isLeap() && !targetMonth.isLeap()) {
- return true;
- }
- return day > target.getDay();
- }
- return aMonth > bMonth;
+ int bYear = bMonth.getYear().getYear();
+ if (aYear != bYear) {
+ return aYear > bYear;
+ }
+ if (month.getMonth() != bMonth.getMonth()) {
+ return month.getMonth() > bMonth.getMonth();
+ }
+ if (month.isLeap() && !bMonth.isLeap()) {
+ return true;
}
- return aYear > bYear;
+ return day > target.getDay();
}
/**
@@ -196,11 +193,11 @@ public boolean isAfter(LunarDay target) {
* @return 星期
*/
public Week getWeek() {
- return getSolarDay().getJulianDay().getWeek();
+ return getSolarDay().getWeek();
}
/**
- * 当天的年干支
+ * 当天的年干支(立春换)
*
* @return 干支
*/
@@ -224,7 +221,7 @@ public SixtyCycle getYearSixtyCycle() {
}
/**
- * 当天的月干支
+ * 当天的月干支(节气换)
*
* @return 干支
*/
@@ -306,10 +303,7 @@ public NineStar getNineStar() {
*/
public Direction getJupiterDirection() {
int index = getSixtyCycle().getIndex();
- if (index % 12 < 6) {
- return Direction.fromIndex(new int[]{2, 8, 4, 6, 0}[index / 12]);
- }
- return month.getYear().getJupiterDirection();
+ return index % 12 < 6 ? Direction.fromIndex(new int[]{2, 8, 4, 6, 0}[index / 12]) : month.getYear().getJupiterDirection();
}
/**
@@ -330,6 +324,15 @@ public Phase getPhase() {
return Phase.fromIndex(day - 1);
}
+ /**
+ * 六曜
+ *
+ * @return 六曜
+ */
+ public SixStar getSixStar() {
+ return SixStar.fromIndex((month.getMonth() + day - 2) % 6);
+ }
+
/**
* 公历日
*
@@ -354,10 +357,10 @@ public TwentyEightStar getTwentyEightStar() {
* @return 农历传统节日
*/
public LunarFestival getFestival() {
- LunarMonth m = getMonth();
- return LunarFestival.fromYmd(m.getYear().getYear(), m.getMonthWithLeap(), day);
+ return LunarFestival.fromYmd(month.getYear().getYear(), month.getMonthWithLeap(), day);
}
+
@Override
public boolean equals(Object o) {
if (!(o instanceof LunarDay)) {
diff --git a/bus-core/src/main/java/org/miaixz/bus/core/center/date/culture/lunar/LunarFestival.java b/bus-core/src/main/java/org/miaixz/bus/core/center/date/culture/lunar/LunarFestival.java
index 58696efc87..b6877ab136 100755
--- a/bus-core/src/main/java/org/miaixz/bus/core/center/date/culture/lunar/LunarFestival.java
+++ b/bus-core/src/main/java/org/miaixz/bus/core/center/date/culture/lunar/LunarFestival.java
@@ -87,21 +87,22 @@ public static LunarFestival fromIndex(int year, int index) {
throw new IllegalArgumentException(String.format("illegal index: %d", index));
}
Matcher matcher = Pattern.compile(String.format("@%02d\\d+", index)).matcher(DATA);
- if (matcher.find()) {
- String data = matcher.group();
- EnumMap.Festival type = EnumMap.Festival.fromCode(data.charAt(3) - '0');
- switch (type) {
- case DAY:
- return new LunarFestival(type, LunarDay.fromYmd(year, Integer.parseInt(data.substring(4, 6), 10), Integer.parseInt(data.substring(6), 10)), null, data);
- case TERM:
- SolarTerms solarTerms = SolarTerms.fromIndex(year, Integer.parseInt(data.substring(4), 10));
- return new LunarFestival(type, solarTerms.getJulianDay().getSolarDay().getLunarDay(), solarTerms, data);
- case EVE:
- return new LunarFestival(type, LunarDay.fromYmd(year + 1, 1, 1).next(-1), null, data);
- default:
- }
+ if (!matcher.find()) {
+ return null;
+ }
+ String data = matcher.group();
+ EnumMap.Festival type = EnumMap.Festival.fromCode(data.charAt(3) - '0');
+ switch (type) {
+ case DAY:
+ return new LunarFestival(type, LunarDay.fromYmd(year, Integer.parseInt(data.substring(4, 6), 10), Integer.parseInt(data.substring(6), 10)), null, data);
+ case TERM:
+ SolarTerms solarTerm = SolarTerms.fromIndex(year, Integer.parseInt(data.substring(4), 10));
+ return new LunarFestival(type, solarTerm.getJulianDay().getSolarDay().getLunarDay(), solarTerm, data);
+ case EVE:
+ return new LunarFestival(type, LunarDay.fromYmd(year + 1, 1, 1).next(-1), null, data);
+ default:
+ return null;
}
- return null;
}
public static LunarFestival fromYmd(int year, int month, int day) {
@@ -120,14 +121,12 @@ public static LunarFestival fromYmd(int year, int month, int day) {
}
}
matcher = Pattern.compile("@\\d{2}2").matcher(DATA);
- if (matcher.find()) {
- LunarDay lunarDay = LunarDay.fromYmd(year, month, day);
- LunarDay nextDay = lunarDay.next(1);
- if (nextDay.getMonth().getMonth() == 1 && nextDay.getDay() == 1) {
- return new LunarFestival(EnumMap.Festival.EVE, lunarDay, null, matcher.group());
- }
+ if (!matcher.find()) {
+ return null;
}
- return null;
+ LunarDay lunarDay = LunarDay.fromYmd(year, month, day);
+ LunarDay nextDay = lunarDay.next(1);
+ return nextDay.getMonth().getMonth() == 1 && nextDay.getDay() == 1 ? new LunarFestival(EnumMap.Festival.EVE, lunarDay, null, matcher.group()) : null;
}
public LunarFestival next(int n) {
diff --git a/bus-core/src/main/java/org/miaixz/bus/core/center/date/culture/lunar/LunarHour.java b/bus-core/src/main/java/org/miaixz/bus/core/center/date/culture/lunar/LunarHour.java
index 709bfd41a2..db4564f293 100755
--- a/bus-core/src/main/java/org/miaixz/bus/core/center/date/culture/lunar/LunarHour.java
+++ b/bus-core/src/main/java/org/miaixz/bus/core/center/date/culture/lunar/LunarHour.java
@@ -151,6 +151,11 @@ public String toString() {
return day + getSixtyCycle().getName() + "时";
}
+ /**
+ * 位于当天的索引
+ *
+ * @return 索引
+ */
public int getIndexInDay() {
return (hour + 1) / 2;
}
@@ -166,8 +171,8 @@ public LunarHour next(int n) {
days--;
}
LunarDay d = day.next(days);
- LunarMonth month = d.getMonth();
- return fromYmdHms(month.getYear().getYear(), month.getMonthWithLeap(), d.getDay(), hour, minute, second);
+ LunarMonth m = d.getMonth();
+ return fromYmdHms(m.getYear().getYear(), m.getMonthWithLeap(), d.getDay(), hour, minute, second);
}
/**
@@ -180,12 +185,10 @@ public boolean isBefore(LunarHour target) {
if (!day.equals(target.getDay())) {
return day.isBefore(target.getDay());
}
- int bHour = target.getHour();
- if (hour == bHour) {
- int bMinute = target.getMinute();
- return minute == bMinute ? second < target.getSecond() : minute < bMinute;
+ if (hour != target.getHour()) {
+ return hour < target.getHour();
}
- return hour < bHour;
+ return minute != target.getMinute() ? minute < target.getMinute() : second < target.getSecond();
}
/**
@@ -198,16 +201,14 @@ public boolean isAfter(LunarHour target) {
if (!day.equals(target.getDay())) {
return day.isAfter(target.getDay());
}
- int bHour = target.getHour();
- if (hour == bHour) {
- int bMinute = target.getMinute();
- return minute == bMinute ? second > target.getSecond() : minute > bMinute;
+ if (hour != target.getHour()) {
+ return hour > target.getHour();
}
- return hour > bHour;
+ return minute != target.getMinute() ? minute > target.getMinute() : second > target.getSecond();
}
/**
- * 当时的年干支
+ * 当时的年干支(立春换)
*
* @return 干支
*/
@@ -231,7 +232,7 @@ public SixtyCycle getYearSixtyCycle() {
}
/**
- * 当时的月干支
+ * 当时的月干支(节气换)
*
* @return 干支
*/
@@ -253,7 +254,7 @@ public SixtyCycle getMonthSixtyCycle() {
*/
public SixtyCycle getDaySixtyCycle() {
SixtyCycle d = day.getSixtyCycle();
- return hour > 22 ? d.next(1) : d;
+ return hour < 23 ? d : d.next(1);
}
/**
diff --git a/bus-core/src/main/java/org/miaixz/bus/core/center/date/culture/lunar/LunarMonth.java b/bus-core/src/main/java/org/miaixz/bus/core/center/date/culture/lunar/LunarMonth.java
index 6dfeaff76f..ccad062c23 100755
--- a/bus-core/src/main/java/org/miaixz/bus/core/center/date/culture/lunar/LunarMonth.java
+++ b/bus-core/src/main/java/org/miaixz/bus/core/center/date/culture/lunar/LunarMonth.java
@@ -106,15 +106,11 @@ public LunarMonth(int year, int month) {
w -= 29.53;
}
- // 计算正月初一的偏移
- LunarYear prevYear = LunarYear.fromYear(year - 1);
- int prevLeapMonth = prevYear.getLeapMonth();
-
// 正常情况正月初一为第3个朔日,但有些特殊的
int offset = 2;
if (year > 8 && year < 24) {
offset = 1;
- } else if (prevLeapMonth > 10 && year != 239 && year != 240) {
+ } else if (LunarYear.fromYear(year - 1).getLeapMonth() > 10 && year != 239 && year != 240) {
offset = 3;
}
diff --git a/bus-core/src/main/java/org/miaixz/bus/core/center/date/culture/lunar/LunarWeek.java b/bus-core/src/main/java/org/miaixz/bus/core/center/date/culture/lunar/LunarWeek.java
index a26b924f1f..4306576b2f 100755
--- a/bus-core/src/main/java/org/miaixz/bus/core/center/date/culture/lunar/LunarWeek.java
+++ b/bus-core/src/main/java/org/miaixz/bus/core/center/date/culture/lunar/LunarWeek.java
@@ -159,8 +159,7 @@ public LunarWeek next(int n) {
* @return 农历日
*/
public LunarDay getFirstDay() {
- LunarMonth m = getMonth();
- LunarDay firstDay = LunarDay.fromYmd(m.getYear().getYear(), m.getMonthWithLeap(), 1);
+ LunarDay firstDay = LunarDay.fromYmd(month.getYear().getYear(), month.getMonthWithLeap(), 1);
return firstDay.next(index * 7 - indexOf(firstDay.getWeek().getIndex() - start.getIndex(), 7));
}
diff --git a/bus-core/src/main/java/org/miaixz/bus/core/center/date/culture/solar/SolarDay.java b/bus-core/src/main/java/org/miaixz/bus/core/center/date/culture/solar/SolarDay.java
index 41849a68fa..9d846eff5f 100755
--- a/bus-core/src/main/java/org/miaixz/bus/core/center/date/culture/solar/SolarDay.java
+++ b/bus-core/src/main/java/org/miaixz/bus/core/center/date/culture/solar/SolarDay.java
@@ -37,6 +37,8 @@
import org.miaixz.bus.core.center.date.culture.cn.dog.DogDay;
import org.miaixz.bus.core.center.date.culture.cn.nine.Nine;
import org.miaixz.bus.core.center.date.culture.cn.nine.NineDay;
+import org.miaixz.bus.core.center.date.culture.cn.plumrain.PlumRain;
+import org.miaixz.bus.core.center.date.culture.cn.plumrain.PlumRainDay;
import org.miaixz.bus.core.center.date.culture.en.Constellation;
import org.miaixz.bus.core.center.date.culture.lunar.LunarDay;
import org.miaixz.bus.core.center.date.culture.lunar.LunarMonth;
@@ -173,15 +175,13 @@ public SolarDay next(int n) {
* @return true/false
*/
public boolean isBefore(SolarDay target) {
+ SolarMonth bMonth = target.getMonth();
int aYear = month.getYear().getYear();
- SolarMonth targetMonth = target.getMonth();
- int bYear = targetMonth.getYear().getYear();
- if (aYear == bYear) {
- int aMonth = month.getMonth();
- int bMonth = targetMonth.getMonth();
- return aMonth == bMonth ? day < target.getDay() : aMonth < bMonth;
+ int bYear = bMonth.getYear().getYear();
+ if (aYear != bYear) {
+ return aYear < bYear;
}
- return aYear < bYear;
+ return month.getMonth() != bMonth.getMonth() ? month.getMonth() < bMonth.getMonth() : day < target.getDay();
}
/**
@@ -191,15 +191,13 @@ public boolean isBefore(SolarDay target) {
* @return true/false
*/
public boolean isAfter(SolarDay target) {
+ SolarMonth bMonth = target.getMonth();
int aYear = month.getYear().getYear();
- SolarMonth targetMonth = target.getMonth();
- int bYear = targetMonth.getYear().getYear();
- if (aYear == bYear) {
- int aMonth = month.getMonth();
- int bMonth = targetMonth.getMonth();
- return aMonth == bMonth ? day > target.getDay() : aMonth > bMonth;
+ int bYear = bMonth.getYear().getYear();
+ if (aYear != bYear) {
+ return aYear > bYear;
}
- return aYear > bYear;
+ return month.getMonth() != bMonth.getMonth() ? month.getMonth() > bMonth.getMonth() : day > target.getDay();
}
/**
@@ -235,7 +233,7 @@ public SolarTermDay getTermDay() {
public SolarWeek getSolarWeek(int start) {
int y = month.getYear().getYear();
int m = month.getMonth();
- return SolarWeek.fromYm(y, m, (int) Math.ceil((day + SolarDay.fromYmd(y, m, 1).getWeek().next(-start).getIndex()) / 7D) - 1, start);
+ return SolarWeek.fromYm(y, m, (int) Math.ceil((day + fromYmd(y, m, 1).getWeek().next(-start).getIndex()) / 7D) - 1, start);
}
/**
@@ -243,7 +241,7 @@ public SolarWeek getSolarWeek(int start) {
*
* @return 七十二候
*/
- public ClimateDay getPhenologyDay() {
+ public ClimateDay getClimateDay() {
SolarTerms term = getTerm();
int dayIndex = subtract(term.getJulianDay().getSolarDay());
int index = dayIndex / 5;
@@ -295,10 +293,7 @@ public DogDay getDogDay() {
start = start.next(10);
days = subtract(start);
}
- if (days < 10) {
- return new DogDay(Dog.fromIndex(2), days);
- }
- return null;
+ return days >= 10 ? null : new DogDay(Dog.fromIndex(2), days);
}
/**
@@ -320,25 +315,45 @@ public NineDay getNineDay() {
return new NineDay(Nine.fromIndex(days / 9), days % 9);
}
+ /**
+ * 梅雨天(芒种后的第1个丙日入梅,小暑后的第1个未日出梅)
+ *
+ * @return 梅雨天
+ */
+ public PlumRainDay getPlumRainDay() {
+ // 芒种
+ SolarTerms grainInEar = SolarTerms.fromIndex(month.getYear().getYear(), 11);
+ SolarDay start = grainInEar.getJulianDay().getSolarDay();
+ int add = 2 - start.getLunarDay().getSixtyCycle().getHeavenStem().getIndex();
+ if (add < 0) {
+ add += 10;
+ }
+ // 芒种后的第1个丙日
+ start = start.next(add);
+
+ // 小暑
+ SolarTerms slightHeat = grainInEar.next(2);
+ SolarDay end = slightHeat.getJulianDay().getSolarDay();
+ add = 7 - end.getLunarDay().getSixtyCycle().getEarthBranch().getIndex();
+ if (add < 0) {
+ add += 12;
+ }
+ // 小暑后的第1个未日
+ end = end.next(add);
+
+ if (isBefore(start) || isAfter(end)) {
+ return null;
+ }
+ return equals(end) ? new PlumRainDay(PlumRain.fromIndex(1), 0) : new PlumRainDay(PlumRain.fromIndex(0), subtract(start));
+ }
+
/**
* 位于当年的索引
*
* @return 索引
*/
public int getIndexInYear() {
- int m = month.getMonth();
- int y = month.getYear().getYear();
- int days = 0;
- for (int i = 1; i < m; i++) {
- days += SolarMonth.fromYm(y, i).getDayCount();
- }
- int d = day;
- if (1582 == y && 10 == m) {
- if (d >= 15) {
- d -= 10;
- }
- }
- return days + d - 1;
+ return subtract(fromYmd(month.getYear().getYear(), 1, 1));
}
/**
@@ -380,9 +395,8 @@ public LunarDay getLunarDay() {
*
* @return 法定假日
*/
- public Holiday getLegalHoliday() {
- SolarMonth m = getMonth();
- return Holiday.fromYmd(m.getYear().getYear(), m.getMonth(), day);
+ public Holiday getHoliday() {
+ return Holiday.fromYmd(month.getYear().getYear(), month.getMonth(), day);
}
/**
@@ -391,8 +405,7 @@ public Holiday getLegalHoliday() {
* @return 公历现代节日
*/
public SolarFestival getFestival() {
- SolarMonth m = getMonth();
- return SolarFestival.fromYmd(m.getYear().getYear(), m.getMonth(), day);
+ return SolarFestival.fromYmd(month.getYear().getYear(), month.getMonth(), day);
}
}
diff --git a/bus-core/src/main/java/org/miaixz/bus/core/center/date/culture/solar/SolarFestival.java b/bus-core/src/main/java/org/miaixz/bus/core/center/date/culture/solar/SolarFestival.java
index a1863e5cc5..72368275a3 100755
--- a/bus-core/src/main/java/org/miaixz/bus/core/center/date/culture/solar/SolarFestival.java
+++ b/bus-core/src/main/java/org/miaixz/bus/core/center/date/culture/solar/SolarFestival.java
@@ -86,29 +86,26 @@ public static SolarFestival fromIndex(int year, int index) {
throw new IllegalArgumentException(String.format("illegal index: %d", index));
}
Matcher matcher = Pattern.compile(String.format("@%02d\\d+", index)).matcher(DATA);
- if (matcher.find()) {
- String data = matcher.group();
- EnumMap.Festival type = EnumMap.Festival.fromCode(data.charAt(3) - '0');
- if (type == EnumMap.Festival.DAY) {
- int startYear = Integer.parseInt(data.substring(8), 10);
- if (year >= startYear) {
- return new SolarFestival(type, SolarDay.fromYmd(year, Integer.parseInt(data.substring(4, 6), 10), Integer.parseInt(data.substring(6, 8), 10)), startYear, data);
- }
- }
+ if (!matcher.find()) {
+ return null;
}
- return null;
+ String data = matcher.group();
+ EnumMap.Festival type = EnumMap.Festival.fromCode(data.charAt(3) - '0');
+ if (type != EnumMap.Festival.DAY) {
+ return null;
+ }
+ int startYear = Integer.parseInt(data.substring(8), 10);
+ return year < startYear ? null : new SolarFestival(type, SolarDay.fromYmd(year, Integer.parseInt(data.substring(4, 6), 10), Integer.parseInt(data.substring(6, 8), 10)), startYear, data);
}
public static SolarFestival fromYmd(int year, int month, int day) {
Matcher matcher = Pattern.compile(String.format("@\\d{2}0%02d%02d\\d+", month, day)).matcher(DATA);
- if (matcher.find()) {
- String data = matcher.group();
- int startYear = Integer.parseInt(data.substring(8), 10);
- if (year >= startYear) {
- return new SolarFestival(EnumMap.Festival.DAY, SolarDay.fromYmd(year, month, day), startYear, data);
- }
+ if (!matcher.find()) {
+ return null;
}
- return null;
+ String data = matcher.group();
+ int startYear = Integer.parseInt(data.substring(8), 10);
+ return year < startYear ? null : new SolarFestival(EnumMap.Festival.DAY, SolarDay.fromYmd(year, month, day), startYear, data);
}
public SolarFestival next(int n) {
diff --git a/bus-core/src/main/java/org/miaixz/bus/core/center/date/culture/solar/SolarHalfYear.java b/bus-core/src/main/java/org/miaixz/bus/core/center/date/culture/solar/SolarHalfYear.java
index da2a8fb33e..0144032100 100755
--- a/bus-core/src/main/java/org/miaixz/bus/core/center/date/culture/solar/SolarHalfYear.java
+++ b/bus-core/src/main/java/org/miaixz/bus/core/center/date/culture/solar/SolarHalfYear.java
@@ -59,10 +59,10 @@ public class SolarHalfYear extends Loops {
* @param index 索引,0-1
*/
public SolarHalfYear(int year, int index) {
- this.year = SolarYear.fromYear(year);
if (index < 0 || index > 1) {
throw new IllegalArgumentException(String.format("illegal solar half year index: %d", index));
}
+ this.year = SolarYear.fromYear(year);
this.index = index;
}
diff --git a/bus-core/src/main/java/org/miaixz/bus/core/center/date/culture/solar/SolarMonth.java b/bus-core/src/main/java/org/miaixz/bus/core/center/date/culture/solar/SolarMonth.java
index e7413e01c7..40cb99aab0 100755
--- a/bus-core/src/main/java/org/miaixz/bus/core/center/date/culture/solar/SolarMonth.java
+++ b/bus-core/src/main/java/org/miaixz/bus/core/center/date/culture/solar/SolarMonth.java
@@ -67,10 +67,10 @@ public class SolarMonth extends Loops {
* @param month 月
*/
public SolarMonth(int year, int month) {
- this.year = SolarYear.fromYear(year);
if (month < 1 || month > 12) {
throw new IllegalArgumentException(String.format("illegal solar month: %d", month));
}
+ this.year = SolarYear.fromYear(year);
this.month = month;
}
diff --git a/bus-core/src/main/java/org/miaixz/bus/core/center/date/culture/solar/SolarQuarter.java b/bus-core/src/main/java/org/miaixz/bus/core/center/date/culture/solar/SolarQuarter.java
index 14630f9ddf..9b5b38068f 100755
--- a/bus-core/src/main/java/org/miaixz/bus/core/center/date/culture/solar/SolarQuarter.java
+++ b/bus-core/src/main/java/org/miaixz/bus/core/center/date/culture/solar/SolarQuarter.java
@@ -58,10 +58,10 @@ public class SolarQuarter extends Loops {
* @param index 索引,0-3
*/
public SolarQuarter(int year, int index) {
- this.year = SolarYear.fromYear(year);
if (index < 0 || index > 3) {
throw new IllegalArgumentException(String.format("illegal solar season index: %d", index));
}
+ this.year = SolarYear.fromYear(year);
this.index = index;
}
diff --git a/bus-core/src/main/java/org/miaixz/bus/core/center/date/culture/solar/SolarTerms.java b/bus-core/src/main/java/org/miaixz/bus/core/center/date/culture/solar/SolarTerms.java
index b07ad7de15..ba35a1041f 100755
--- a/bus-core/src/main/java/org/miaixz/bus/core/center/date/culture/solar/SolarTerms.java
+++ b/bus-core/src/main/java/org/miaixz/bus/core/center/date/culture/solar/SolarTerms.java
@@ -85,7 +85,7 @@ public SolarTerms next(int n) {
}
/**
- * 是否节
+ * 是否节令
*
* @return true/false
*/
@@ -94,7 +94,7 @@ public boolean isJie() {
}
/**
- * 是否气
+ * 是否气令
*
* @return true/false
*/
diff --git a/bus-core/src/main/java/org/miaixz/bus/core/center/date/culture/solar/SolarTime.java b/bus-core/src/main/java/org/miaixz/bus/core/center/date/culture/solar/SolarTime.java
index 9d7f35c3c8..4b63fc865d 100755
--- a/bus-core/src/main/java/org/miaixz/bus/core/center/date/culture/solar/SolarTime.java
+++ b/bus-core/src/main/java/org/miaixz/bus/core/center/date/culture/solar/SolarTime.java
@@ -146,12 +146,10 @@ public boolean isBefore(SolarTime target) {
if (!day.equals(target.getDay())) {
return day.isBefore(target.getDay());
}
- int bHour = target.getHour();
- if (hour == bHour) {
- int bMinute = target.getMinute();
- return minute == bMinute ? second < target.getSecond() : minute < bMinute;
+ if (hour != target.getHour()) {
+ return hour < target.getHour();
}
- return hour < bHour;
+ return minute != target.getMinute() ? minute < target.getMinute() : second < target.getSecond();
}
/**
@@ -164,12 +162,10 @@ public boolean isAfter(SolarTime target) {
if (!day.equals(target.getDay())) {
return day.isAfter(target.getDay());
}
- int bHour = target.getHour();
- if (hour == bHour) {
- int bMinute = target.getMinute();
- return minute == bMinute ? second > target.getSecond() : minute > bMinute;
+ if (hour != target.getHour()) {
+ return hour > target.getHour();
}
- return hour > bHour;
+ return minute != target.getMinute() ? minute > target.getMinute() : second > target.getSecond();
}
/**
@@ -191,8 +187,8 @@ public SolarTerms getTerm() {
* @return 儒略日
*/
public JulianDay getJulianDay() {
- SolarMonth month = day.getMonth();
- return JulianDay.fromYmdHms(month.getYear().getYear(), month.getMonth(), day.getDay(), hour, minute, second);
+ SolarMonth m = day.getMonth();
+ return JulianDay.fromYmdHms(m.getYear().getYear(), m.getMonth(), day.getDay(), hour, minute, second);
}
/**
@@ -222,8 +218,8 @@ public int subtract(SolarTime target) {
*/
public SolarTime next(int n) {
if (n == 0) {
- SolarMonth month = day.getMonth();
- return SolarTime.fromYmdHms(month.getYear().getYear(), month.getMonth(), day.getDay(), hour, minute, second);
+ SolarMonth m = day.getMonth();
+ return SolarTime.fromYmdHms(m.getYear().getYear(), m.getMonth(), day.getDay(), hour, minute, second);
}
int ts = second + n;
int tm = minute + ts / 60;
@@ -246,7 +242,7 @@ public SolarTime next(int n) {
}
SolarDay d = day.next(td);
- SolarMonth m = d.getMonth();
+ SolarMonth m = day.getMonth();
return SolarTime.fromYmdHms(m.getYear().getYear(), m.getMonth(), d.getDay(), th, tm, ts);
}
diff --git a/bus-core/src/main/java/org/miaixz/bus/core/center/date/culture/solar/SolarWeek.java b/bus-core/src/main/java/org/miaixz/bus/core/center/date/culture/solar/SolarWeek.java
index 101e720578..4d219f761f 100755
--- a/bus-core/src/main/java/org/miaixz/bus/core/center/date/culture/solar/SolarWeek.java
+++ b/bus-core/src/main/java/org/miaixz/bus/core/center/date/culture/solar/SolarWeek.java
@@ -149,8 +149,7 @@ public SolarWeek next(int n) {
while (forward ? (d >= weeksInMonth) : (d < 0)) {
if (forward) {
d -= weeksInMonth;
- }
- if (!forward) {
+ } else {
if (!SolarDay.fromYmd(m.getYear().getYear(), m.getMonth(), 1).getWeek().equals(start)) {
d += add;
}
diff --git a/bus-core/src/main/java/org/miaixz/bus/core/center/date/format/FormatPeriod.java b/bus-core/src/main/java/org/miaixz/bus/core/center/date/format/FormatPeriod.java
index fb9bb409ec..cdd7ff615d 100644
--- a/bus-core/src/main/java/org/miaixz/bus/core/center/date/format/FormatPeriod.java
+++ b/bus-core/src/main/java/org/miaixz/bus/core/center/date/format/FormatPeriod.java
@@ -28,9 +28,11 @@
package org.miaixz.bus.core.center.date.format;
import org.miaixz.bus.core.center.date.culture.en.Units;
+import org.miaixz.bus.core.lang.Normal;
import org.miaixz.bus.core.xyz.StringKit;
import java.io.Serializable;
+import java.util.function.Function;
/**
* 时长格式化器,用于格式化输出两个日期相差的时长
@@ -47,6 +49,7 @@
public class FormatPeriod implements Serializable {
private static final long serialVersionUID = -1L;
+
/**
* 格式化级别的最大个数
*/
@@ -59,11 +62,20 @@ public class FormatPeriod implements Serializable {
* 格式化级别
*/
private Level level;
+ /**
+ * 格式化器
+ */
+ private Function formatter = Level::getName;
/**
* 是否为简化模式,此标记用于自定义是否输出各个位数中间为0的部分
* 如为{@code true},输出 1小时3秒,为{@code false}输出 1小时0分3秒
*/
private boolean simpleMode = true;
+ /**
+ * 分隔符,默认为""
+ * 通过{@link #setSeparator(String)}进行调整
+ */
+ private String separator = Normal.EMPTY;
/**
* 构造
@@ -122,14 +134,14 @@ public String format() {
// 天
if (isLevelCountValid(levelCount) && day > 0) {
- sb.append(day).append(Level.DAY.name);
+ sb.append(day).append(formatter.apply(Level.DAY)).append(separator);
levelCount++;
}
// 时
if (isLevelCountValid(levelCount) && level >= Level.HOUR.ordinal()) {
if (hour > 0 || (!this.simpleMode && StringKit.isNotEmpty(sb))) {
- sb.append(hour).append(Level.HOUR.name);
+ sb.append(hour).append(formatter.apply(Level.HOUR)).append(separator);
levelCount++;
}
}
@@ -137,7 +149,7 @@ public String format() {
// 分
if (isLevelCountValid(levelCount) && level >= Level.MINUTE.ordinal()) {
if (minute > 0 || (!this.simpleMode && StringKit.isNotEmpty(sb))) {
- sb.append(minute).append(Level.MINUTE.name);
+ sb.append(minute).append(formatter.apply(Level.MINUTE)).append(separator);
levelCount++;
}
}
@@ -145,23 +157,24 @@ public String format() {
// 秒
if (isLevelCountValid(levelCount) && level >= Level.SECOND.ordinal()) {
if (second > 0 || (!this.simpleMode && StringKit.isNotEmpty(sb))) {
- sb.append(second).append(Level.SECOND.name);
+ sb.append(second).append(formatter.apply(Level.SECOND)).append(separator);
levelCount++;
}
}
// 毫秒
if (isLevelCountValid(levelCount) && millisecond > 0 && level >= Level.MILLISECOND.ordinal()) {
- sb.append(millisecond).append(Level.MILLISECOND.name);
- // levelCount++;
+ sb.append(millisecond).append(formatter.apply(Level.MILLISECOND)).append(separator);
}
}
if (StringKit.isEmpty(sb)) {
- sb.append(0).append(this.level.name);
+ sb.append(0).append(formatter.apply(this.level));
+ } else if (StringKit.isNotEmpty(separator)) {
+ sb.delete(sb.length() - separator.length(), sb.length());
}
-
- return sb.toString();
+ // 自定义实现最后可能存在空格
+ return sb.toString().trim();
}
/**
@@ -216,6 +229,28 @@ public FormatPeriod setSimpleMode(final boolean simpleMode) {
return this;
}
+ /**
+ * 设置级别格式化器
+ *
+ * @param formatter 级别格式化器
+ * @return this
+ */
+ public FormatPeriod setFormatter(final Function formatter) {
+ this.formatter = formatter;
+ return this;
+ }
+
+ /**
+ * 设置分隔符
+ *
+ * @param separator 分割符
+ * @return this
+ */
+ public FormatPeriod setSeparator(final String separator) {
+ this.separator = StringKit.emptyIfNull(separator);
+ return this;
+ }
+
@Override
public String toString() {
return format();
diff --git a/bus-core/src/main/java/org/miaixz/bus/core/center/list/BoundedList.java b/bus-core/src/main/java/org/miaixz/bus/core/center/list/BoundedList.java
new file mode 100644
index 0000000000..e16db06509
--- /dev/null
+++ b/bus-core/src/main/java/org/miaixz/bus/core/center/list/BoundedList.java
@@ -0,0 +1,107 @@
+/*
+ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
+ ~ ~
+ ~ The MIT License (MIT) ~
+ ~ ~
+ ~ Copyright (c) 2015-2024 miaixz.org and other contributors. ~
+ ~ ~
+ ~ Permission is hereby granted, free of charge, to any person obtaining a copy ~
+ ~ of this software and associated documentation files (the "Software"), to deal ~
+ ~ in the Software without restriction, including without limitation the rights ~
+ ~ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell ~
+ ~ copies of the Software, and to permit persons to whom the Software is ~
+ ~ furnished to do so, subject to the following conditions: ~
+ ~ ~
+ ~ The above copyright notice and this permission notice shall be included in ~
+ ~ all copies or substantial portions of the Software. ~
+ ~ ~
+ ~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR ~
+ ~ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, ~
+ ~ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE ~
+ ~ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER ~
+ ~ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, ~
+ ~ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN ~
+ ~ THE SOFTWARE. ~
+ ~ ~
+ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
+ */
+package org.miaixz.bus.core.center.list;
+
+import org.miaixz.bus.core.center.BoundedCollection;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+/**
+ * 指定边界大小的List
+ * 通过指定边界,可以限制List的最大容量
+ *
+ * @param 元素类型
+ * @author Kimi Liu
+ * @since Java 17+
+ */
+public class BoundedList extends ListWrapper implements BoundedCollection {
+
+ private final int maxSize;
+
+ /**
+ * 构造
+ *
+ * @param maxSize 最大容量
+ */
+ public BoundedList(final int maxSize) {
+ this(new ArrayList<>(maxSize), maxSize);
+ }
+
+ /**
+ * 构造,限制集合的最大容量为提供的List
+ *
+ * @param raw 原始对象
+ * @param maxSize 最大容量
+ */
+ public BoundedList(final List raw, final int maxSize) {
+ super(raw);
+ this.maxSize = maxSize;
+ }
+
+ @Override
+ public boolean isFull() {
+ return size() == this.maxSize;
+ }
+
+ @Override
+ public int maxSize() {
+ return this.maxSize;
+ }
+
+ @Override
+ public boolean add(final E e) {
+ checkFull(1);
+ return super.add(e);
+ }
+
+ @Override
+ public void add(final int index, final E element) {
+ checkFull(1);
+ super.add(index, element);
+ }
+
+ @Override
+ public boolean addAll(final Collection extends E> c) {
+ checkFull(c.size());
+ return super.addAll(c);
+ }
+
+ @Override
+ public boolean addAll(final int index, final Collection extends E> c) {
+ checkFull(c.size());
+ return super.addAll(index, c);
+ }
+
+ private void checkFull(final int addSize) {
+ if (size() + addSize > this.maxSize) {
+ throw new IndexOutOfBoundsException("List is no space to add " + addSize + " elements!");
+ }
+ }
+}
diff --git a/bus-core/src/main/java/org/miaixz/bus/core/center/list/ListWrapper.java b/bus-core/src/main/java/org/miaixz/bus/core/center/list/ListWrapper.java
new file mode 100644
index 0000000000..dc3c5f68af
--- /dev/null
+++ b/bus-core/src/main/java/org/miaixz/bus/core/center/list/ListWrapper.java
@@ -0,0 +1,209 @@
+/*
+ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
+ ~ ~
+ ~ The MIT License (MIT) ~
+ ~ ~
+ ~ Copyright (c) 2015-2024 miaixz.org and other contributors. ~
+ ~ ~
+ ~ Permission is hereby granted, free of charge, to any person obtaining a copy ~
+ ~ of this software and associated documentation files (the "Software"), to deal ~
+ ~ in the Software without restriction, including without limitation the rights ~
+ ~ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell ~
+ ~ copies of the Software, and to permit persons to whom the Software is ~
+ ~ furnished to do so, subject to the following conditions: ~
+ ~ ~
+ ~ The above copyright notice and this permission notice shall be included in ~
+ ~ all copies or substantial portions of the Software. ~
+ ~ ~
+ ~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR ~
+ ~ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, ~
+ ~ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE ~
+ ~ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER ~
+ ~ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, ~
+ ~ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN ~
+ ~ THE SOFTWARE. ~
+ ~ ~
+ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
+ */
+package org.miaixz.bus.core.center.list;
+
+import org.miaixz.bus.core.lang.wrapper.SimpleWrapper;
+
+import java.util.*;
+import java.util.function.Consumer;
+import java.util.function.Predicate;
+import java.util.function.UnaryOperator;
+import java.util.stream.Stream;
+
+/**
+ * 列表包装类
+ * 提供列表包装,用于在执行列表方法前后自定义处理逻辑
+ *
+ * @param 元素类型
+ * @author Kimi Liu
+ * @since Java 17+
+ */
+public class ListWrapper extends SimpleWrapper> implements List {
+
+ /**
+ * 构造
+ *
+ * @param raw 原始对象
+ */
+ public ListWrapper(final List raw) {
+ super(raw);
+ }
+
+
+ @Override
+ public int size() {
+ return raw.size();
+ }
+
+ @Override
+ public boolean isEmpty() {
+ return raw.isEmpty();
+ }
+
+ @Override
+ public boolean contains(final Object o) {
+ return raw.contains(o);
+ }
+
+ @Override
+ public Iterator iterator() {
+ return raw.iterator();
+ }
+
+ @Override
+ public void forEach(final Consumer super E> action) {
+ raw.forEach(action);
+ }
+
+ @Override
+ public Object[] toArray() {
+ return raw.toArray();
+ }
+
+ @Override
+ public T[] toArray(final T[] a) {
+ return raw.toArray(a);
+ }
+
+ @Override
+ public boolean add(final E e) {
+ return raw.add(e);
+ }
+
+ @Override
+ public boolean remove(final Object o) {
+ return raw.remove(o);
+ }
+
+ @SuppressWarnings("SlowListContainsAll")
+ @Override
+ public boolean containsAll(final Collection> c) {
+ return raw.containsAll(c);
+ }
+
+ @Override
+ public boolean addAll(final Collection extends E> c) {
+ return raw.addAll(c);
+ }
+
+ @Override
+ public boolean addAll(final int index, final Collection extends E> c) {
+ return raw.addAll(index, c);
+ }
+
+ @Override
+ public boolean removeAll(final Collection> c) {
+ return raw.removeAll(c);
+ }
+
+ @Override
+ public boolean removeIf(final Predicate super E> filter) {
+ return raw.removeIf(filter);
+ }
+
+ @Override
+ public boolean retainAll(final Collection> c) {
+ return raw.retainAll(c);
+ }
+
+ @Override
+ public void replaceAll(final UnaryOperator operator) {
+ raw.replaceAll(operator);
+ }
+
+ @Override
+ public void sort(final Comparator super E> c) {
+ raw.sort(c);
+ }
+
+ @Override
+ public void clear() {
+ raw.clear();
+ }
+
+ @Override
+ public E get(final int index) {
+ return raw.get(index);
+ }
+
+ @Override
+ public E set(final int index, final E element) {
+ return raw.set(index, element);
+ }
+
+ @Override
+ public void add(final int index, final E element) {
+ raw.add(index, element);
+ }
+
+ @Override
+ public E remove(final int index) {
+ return raw.remove(index);
+ }
+
+ @Override
+ public int indexOf(final Object o) {
+ return raw.indexOf(o);
+ }
+
+ @Override
+ public int lastIndexOf(final Object o) {
+ return raw.lastIndexOf(o);
+ }
+
+ @Override
+ public ListIterator listIterator() {
+ return raw.listIterator();
+ }
+
+ @Override
+ public ListIterator listIterator(final int index) {
+ return raw.listIterator(index);
+ }
+
+ @Override
+ public List subList(final int fromIndex, final int toIndex) {
+ return raw.subList(fromIndex, toIndex);
+ }
+
+ @Override
+ public Spliterator spliterator() {
+ return raw.spliterator();
+ }
+
+ @Override
+ public Stream stream() {
+ return raw.stream();
+ }
+
+ @Override
+ public Stream parallelStream() {
+ return raw.parallelStream();
+ }
+
+}
diff --git a/bus-core/src/main/java/org/miaixz/bus/core/center/map/CamelCaseMap.java b/bus-core/src/main/java/org/miaixz/bus/core/center/map/CamelCaseMap.java
index 7c3d97cd1c..43d6d5deaa 100644
--- a/bus-core/src/main/java/org/miaixz/bus/core/center/map/CamelCaseMap.java
+++ b/bus-core/src/main/java/org/miaixz/bus/core/center/map/CamelCaseMap.java
@@ -44,7 +44,7 @@
* @author Kimi Liu
* @since Java 17+
*/
-public class CamelCaseMap extends FuncKeyMap {
+public class CamelCaseMap extends FunctionKeyMap {
private static final long serialVersionUID = -1L;
diff --git a/bus-core/src/main/java/org/miaixz/bus/core/center/map/CaseInsensitiveMap.java b/bus-core/src/main/java/org/miaixz/bus/core/center/map/CaseInsensitiveMap.java
index e9e66f9722..ceda483106 100644
--- a/bus-core/src/main/java/org/miaixz/bus/core/center/map/CaseInsensitiveMap.java
+++ b/bus-core/src/main/java/org/miaixz/bus/core/center/map/CaseInsensitiveMap.java
@@ -43,7 +43,7 @@
* @author Kimi Liu
* @since Java 17+
*/
-public class CaseInsensitiveMap extends FuncKeyMap {
+public class CaseInsensitiveMap extends FunctionKeyMap {
private static final long serialVersionUID = -1L;
diff --git a/bus-core/src/main/java/org/miaixz/bus/core/center/map/FuncKeyMap.java b/bus-core/src/main/java/org/miaixz/bus/core/center/map/FunctionKeyMap.java
similarity index 95%
rename from bus-core/src/main/java/org/miaixz/bus/core/center/map/FuncKeyMap.java
rename to bus-core/src/main/java/org/miaixz/bus/core/center/map/FunctionKeyMap.java
index 78c2d97392..87a0dd5e85 100644
--- a/bus-core/src/main/java/org/miaixz/bus/core/center/map/FuncKeyMap.java
+++ b/bus-core/src/main/java/org/miaixz/bus/core/center/map/FunctionKeyMap.java
@@ -38,7 +38,7 @@
* @author Kimi Liu
* @since Java 17+
*/
-public class FuncKeyMap extends CustomKeyMap {
+public class FunctionKeyMap extends CustomKeyMap {
private static final long serialVersionUID = -1L;
@@ -51,7 +51,7 @@ public class FuncKeyMap extends CustomKeyMap {
* @param emptyMap Map,提供的空map
* @param keyFunc 自定义KEY的函数
*/
- public FuncKeyMap(final Map emptyMap, final Function