Skip to content

Commit

Permalink
v8.1.0
Browse files Browse the repository at this point in the history
v8.1.0
  • Loading branch information
839128 authored Sep 24, 2024
2 parents c7d8cfc + 405af63 commit 053723f
Show file tree
Hide file tree
Showing 288 changed files with 5,834 additions and 3,001 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</p>
<p align="center">
<a target="_blank" href="https://search.maven.org/search?q=org.miaixz">
<img src="https://img.shields.io/badge/maven--central-v8.0.9-blue.svg?label=Maven%20Central" />
<img src="https://img.shields.io/badge/maven--central-v8.1.0-blue.svg?label=Maven%20Central" />
</a>
<a target="_blank" href="https://travis-ci.org/839128/bus">
<img src="https://app.travis-ci.com/839128/bus.svg?token=TZPNK5FQiKMp9cao3SnY&branch=main">
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8.0.9
8.1.0
2 changes: 1 addition & 1 deletion bus-all/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

<groupId>org.miaixz</groupId>
<artifactId>bus-all</artifactId>
<version>8.0.9</version>
<version>8.1.0</version>
<packaging>jar</packaging>

<name>${project.artifactId}</name>
Expand Down
2 changes: 1 addition & 1 deletion bus-base/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

<groupId>org.miaixz</groupId>
<artifactId>bus-base</artifactId>
<version>8.0.9</version>
<version>8.1.0</version>
<packaging>jar</packaging>

<name>${project.artifactId}</name>
Expand Down
2 changes: 1 addition & 1 deletion bus-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

<groupId>org.miaixz</groupId>
<artifactId>bus-bom</artifactId>
<version>8.0.9</version>
<version>8.1.0</version>
<packaging>jar</packaging>

<name>${project.artifactId}</name>
Expand Down
2 changes: 1 addition & 1 deletion bus-cache/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

<groupId>org.miaixz</groupId>
<artifactId>bus-cache</artifactId>
<version>8.0.9</version>
<version>8.1.0</version>
<packaging>jar</packaging>

<name>${project.artifactId}</name>
Expand Down
2 changes: 1 addition & 1 deletion bus-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

<groupId>org.miaixz</groupId>
<artifactId>bus-core</artifactId>
<version>8.0.9</version>
<version>8.1.0</version>
<packaging>jar</packaging>

<name>${project.artifactId}</name>
Expand Down
14 changes: 7 additions & 7 deletions bus-core/src/main/java/org/miaixz/bus/core/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@
*/
package org.miaixz.bus.core;

import org.miaixz.bus.core.lang.Assert;
import org.miaixz.bus.core.lang.Symbol;
import org.miaixz.bus.core.xyz.CharKit;
import org.miaixz.bus.core.xyz.CompareKit;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.miaixz.bus.core.lang.Assert;
import org.miaixz.bus.core.lang.Symbol;
import org.miaixz.bus.core.xyz.CharKit;
import org.miaixz.bus.core.xyz.CompareKit;

/**
* 字符串版本表示,用于解析版本号的不同部分并比较大小。 来自:java.lang.module.ModuleDescriptor.Version
*
Expand All @@ -48,7 +48,7 @@ public class Version implements Comparable<Version>, Serializable {
/**
* 版本信息
*/
public static final String _VERSION = "8.0.9";
public static final String _VERSION = "8.1.0";

private static final long serialVersionUID = -1L;
private final String version;
Expand Down Expand Up @@ -304,7 +304,7 @@ private int compareTokens(final List<Object> ts1, final List<Object> ts2) {
}
return c;
}
// Types differ, so convert number to string form
// Types differ, so support number to string form
final int c = o1.toString().compareTo(o2.toString());
if (c == 0) {
continue;
Expand Down
15 changes: 8 additions & 7 deletions bus-core/src/main/java/org/miaixz/bus/core/bean/DynaBean.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,10 @@ public <T> T get(final String fieldName) throws BeanException {
} else {
final PropDesc prop = BeanKit.getBeanDesc(beanClass).getProp(fieldName);
if (null == prop) {
throw new BeanException("No public field or get method for {}", fieldName);
// 节点字段不存在,类似于Map无key,返回null而非报错
return null;
}
return (T) prop.getValue(bean);
return (T) prop.getValue(bean, false);
}
}

Expand Down Expand Up @@ -232,17 +233,17 @@ public int hashCode() {
}

@Override
public boolean equals(final Object obj) {
if (this == obj) {
public boolean equals(final Object object) {
if (this == object) {
return true;
}
if (obj == null) {
if (object == null) {
return false;
}
if (getClass() != obj.getClass()) {
if (getClass() != object.getClass()) {
return false;
}
final DynaBean other = (DynaBean) obj;
final DynaBean other = (DynaBean) object;
if (bean == null) {
return other.bean == null;
} else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@

import org.miaixz.bus.core.bean.desc.PropDesc;
import org.miaixz.bus.core.lang.Assert;
import org.miaixz.bus.core.lang.exception.BeanException;
import org.miaixz.bus.core.lang.mutable.MutableEntry;
import org.miaixz.bus.core.xyz.MapKit;
import org.miaixz.bus.core.xyz.StringKit;
import org.miaixz.bus.core.xyz.TypeKit;

Expand Down Expand Up @@ -66,6 +68,7 @@ public BeanToBeanCopier(final S source, final T target, final Type targetType, f

@Override
public T copy() {
final CopyOptions copyOptions = this.copyOptions;
Class<?> actualEditable = target.getClass();
if (null != copyOptions.editable) {
// 检查限制类是否为target的父类或接口
Expand All @@ -75,18 +78,30 @@ public T copy() {
actualEditable = copyOptions.editable;
}
final Map<String, PropDesc> targetPropDescMap = getBeanDesc(actualEditable).getPropMap(copyOptions.ignoreCase);
if (MapKit.isEmpty(targetPropDescMap)) {
if (copyOptions.ignoreError) {
return target;
}
throw new BeanException("No properties for target: {}", actualEditable);
}

final Map<String, PropDesc> sourcePropDescMap = getBeanDesc(source.getClass())
.getPropMap(copyOptions.ignoreCase);
if (MapKit.isEmpty(sourcePropDescMap)) {
if (copyOptions.ignoreError) {
return target;
}
throw new BeanException("No properties for source: {}", source.getClass());
}
sourcePropDescMap.forEach((sFieldName, sDesc) -> {
if (null == sFieldName || !sDesc.isReadable(copyOptions.transientSupport)) {
// 字段空或不可读,跳过
return;
}

// 检查源对象属性是否过滤属性
Object sValue = sDesc.getValue(this.source);
if (!copyOptions.testPropertyFilter(sDesc.getField(), sValue)) {
Object sValue = sDesc.getValue(this.source, copyOptions.ignoreError);
if (!this.copyOptions.testPropertyFilter(sDesc.getField(), sValue)) {
return;
}

Expand All @@ -104,16 +119,15 @@ public T copy() {

// 检查目标字段可写性
// 目标字段检查放在键值对编辑之后,因为键可能被编辑修改
final PropDesc tDesc = this.copyOptions.findPropDesc(targetPropDescMap, sFieldName);
if (null == tDesc || !tDesc.isWritable(this.copyOptions.transientSupport)) {
final PropDesc tDesc = copyOptions.findPropDesc(targetPropDescMap, sFieldName);
if (null == tDesc || !tDesc.isWritable(copyOptions.transientSupport)) {
// 字段不可写,跳过之
return;
}

// 获取目标字段真实类型并转换源值
final Type fieldType = TypeKit.getActualType(this.targetType, tDesc.getFieldType());
// sValue = Convert.convertWithCheck(fieldType, sValue, null, this.copyOptions.ignoreError);
sValue = this.copyOptions.convertField(fieldType, sValue);
sValue = copyOptions.convertField(fieldType, sValue);

// 目标赋值
tDesc.setValue(this.target, sValue, copyOptions.ignoreNullValue, copyOptions.ignoreError,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public BeanToMapCopier(final Object source, final Map target, final Type targetT

@Override
public Map copy() {
final CopyOptions copyOptions = this.copyOptions;
Class<?> actualEditable = source.getClass();
if (null != copyOptions.editable) {
// 检查限制类是否为target的父类或接口
Expand All @@ -82,7 +83,7 @@ public Map copy() {
}

// 检查源对象属性是否过滤属性
Object sValue = sDesc.getValue(this.source);
Object sValue = sDesc.getValue(this.source, copyOptions.ignoreError);
if (!copyOptions.testPropertyFilter(sDesc.getField(), sValue)) {
return;
}
Expand All @@ -102,8 +103,7 @@ public Map copy() {
// 获取目标值真实类型并转换源值
final Type[] typeArguments = TypeKit.getTypeArguments(this.targetType);
if (null != typeArguments && typeArguments.length > 1) {
// sValue = Convert.convertWithCheck(typeArguments[1], sValue, null, this.copyOptions.ignoreError);
sValue = this.copyOptions.convertField(typeArguments[1], sValue);
sValue = copyOptions.convertField(typeArguments[1], sValue);
}

// 目标赋值
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@
*/
package org.miaixz.bus.core.bean.copier;

import java.io.Serializable;
import java.lang.reflect.Field;
import java.lang.reflect.Type;
import java.util.Map;
import java.util.Set;
import java.util.function.BiPredicate;
import java.util.function.UnaryOperator;

import org.miaixz.bus.core.bean.desc.BeanDesc;
import org.miaixz.bus.core.bean.desc.PropDesc;
import org.miaixz.bus.core.center.function.FunctionX;
Expand All @@ -37,14 +45,6 @@
import org.miaixz.bus.core.xyz.LambdaKit;
import org.miaixz.bus.core.xyz.StringKit;

import java.io.Serializable;
import java.lang.reflect.Field;
import java.lang.reflect.Type;
import java.util.Map;
import java.util.Set;
import java.util.function.BiPredicate;
import java.util.function.UnaryOperator;

/**
* 属性拷贝选项 包括: 1、限制的类或接口,必须为目标对象的实现接口或父类,用于限制拷贝的属性,例如一个类我只想复制其父类的一些属性,就可以将editable设置为父类 2、是否忽略空值,当源对象的值为null时,true:
* 忽略而不注入此值,false: 注入null 3、忽略的属性列表,设置一个属性列表,不拷贝这些属性值
Expand Down Expand Up @@ -99,8 +99,7 @@ public class CopyOptions implements Serializable {
*/
protected Converter converter = (type, value) -> Convert.convertWithCheck(type, value, null, ignoreError);
/**
* 自定义的Bean解析类<br>
* 默认规则下普通Bean使用严格的Bean解析,需要同时解析Bean中的字段和方法,然后匹配,自定义后可以只解析getter和setter方法
* 自定义的Bean解析类 默认规则下普通Bean使用严格的Bean解析,需要同时解析Bean中的字段和方法,然后匹配,自定义后可以只解析getter和setter方法
*/
protected Class<BeanDesc> beanDescClass;
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@
/**
* 值提供者,用于提供Bean注入时参数对应值得抽象接口 继承或匿名实例化此接口 在Bean注入过程中,Bean获得字段名,通过外部方式根据这个字段名查找相应的字段值,然后注入Bean
*
* @param <T> KEY类型,一般情况下为 {@link String}
* @param <K> KEY类型,一般情况下为 {@link String}
* @author Kimi Liu
* @since Java 17+
*/
public interface ValueProvider<T> {
public interface ValueProvider<K> {

/**
* 获取值 返回值一般需要匹配被注入类型,如果不匹配会调用默认转换 Convert#convert(Type, Object)实现转换
Expand All @@ -45,14 +45,14 @@ public interface ValueProvider<T> {
* @param valueType 被注入的值的类型
* @return 对应参数名的值
*/
Object value(T key, Type valueType);
Object value(K key, Type valueType);

/**
* 是否包含指定KEY,如果不包含则忽略注入 此接口方法单独需要实现的意义在于:有些值提供者(比如Map)key是存在的,但是value为null,此时如果需要注入这个null,需要根据此方法判断
*
* @param key Bean对象中参数名
* @return 是否包含指定KEY
*/
boolean containsKey(T key);
boolean containsKey(K key);

}
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,19 @@ public T copy() {
}
final Map<String, PropDesc> targetPropDescMap = getBeanDesc(actualEditable).getPropMap(copyOptions.ignoreCase);

targetPropDescMap.forEach((tFieldName, tDesc) -> {
targetPropDescMap.forEach((tFieldName, propDesc) -> {
if (null == tFieldName) {
return;
}

// 检查目标字段可写性
if (null == tDesc || !tDesc.isWritable(this.copyOptions.transientSupport)) {
if (null == propDesc || !propDesc.isWritable(this.copyOptions.transientSupport)) {
// 字段不可写,跳过之
return;
}

// 获取目标字段真实类型
final Type fieldType = TypeKit.getActualType(this.targetType, tDesc.getFieldType());
final Type fieldType = TypeKit.getActualType(this.targetType, propDesc.getFieldType());
// 编辑键值对
final MutableEntry<Object, Object> entry = copyOptions.editField(tFieldName, null);
if (null == entry) {
Expand All @@ -106,12 +106,12 @@ public T copy() {
final Object sValue = source.value(tFieldName, fieldType);

// 检查目标对象属性是否过滤属性
if (!copyOptions.testPropertyFilter(tDesc.getField(), sValue)) {
if (!copyOptions.testPropertyFilter(propDesc.getField(), sValue)) {
return;
}

// 目标赋值
tDesc.setValue(this.target, sValue, copyOptions.ignoreNullValue, copyOptions.ignoreError,
propDesc.setValue(this.target, sValue, copyOptions.ignoreNullValue, copyOptions.ignoreError,
copyOptions.override);
});
return this.target;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public BeanValueProvider(final Object bean, BeanDesc beanDesc) {
public Object value(final String key, final Type valueType) {
final PropDesc prop = beanDesc.getProp(key);
if (null != prop) {
return Convert.convert(valueType, prop.getValue(bean));
return Convert.convert(valueType, prop.getValue(bean, false));
}
return null;
}
Expand Down
Loading

0 comments on commit 053723f

Please sign in to comment.