Skip to content

Commit

Permalink
[release] release 2.1.0-alpha
Browse files Browse the repository at this point in the history
  • Loading branch information
VampireAchao committed Jan 20, 2024
1 parent 97926da commit ec99412
Show file tree
Hide file tree
Showing 7 changed files with 248 additions and 144 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<revision>2.0.3</revision>
<revision>2.1.0-alpha</revision>
<maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version>
<maven-surefire-plugin.version>2.22.2</maven-surefire-plugin.version>
<surefire.argLine></surefire.argLine>
Expand Down Expand Up @@ -359,4 +359,4 @@
</profile>
</profiles>

</project>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,11 @@ public static String getGetterName(String propertyName) {
* @param <T> 对象类型
*/
public static <T, R> R copyProperties(T source, R target) {
return copyProperties(source, target, CopyOption.globalCopyOption);
return copyProperties(source, target, CopyOption.GLOBAL_COPY_OPTION);
}

public static <T, R> R copyProperties(T source, Class<R> targetType) {
return copyProperties(source, targetType, CopyOption.globalCopyOption);
return copyProperties(source, targetType, CopyOption.GLOBAL_COPY_OPTION);
}

public static <T, R> R copyProperties(T source, Class<R> targetType, CopyOption copyOption) {
Expand All @@ -153,18 +153,18 @@ public static <T, R> R copyProperties(T source, R target, CopyOption copyOption)

Class<T> sourceType = SerFunc.<Class<?>, Class<T>>cast().apply(source.getClass());
Map<String, Map.Entry<SerFunc<T, Object>, Serializable>> sourcePropertyGetterSetterMap =
LambdaHelper.getPropertyGetterSetterMap(sourceType);
LambdaHelper.getPropertyGetterSetterMap(sourceType);

Class<R> targetType = SerFunc.<Class<?>, Class<R>>cast().apply(target.getClass());
Map<String, Map.Entry<SerFunc<R, Object>, Serializable>> targetPropertyGetterSetterMap =
LambdaHelper.getPropertyGetterSetterMap(targetType);
LambdaHelper.getPropertyGetterSetterMap(targetType);

for (Map.Entry<String, Map.Entry<SerFunc<T, Object>, Serializable>> sourceEntry :
sourcePropertyGetterSetterMap.entrySet()) {
sourcePropertyGetterSetterMap.entrySet()) {
String property = sourceEntry.getKey();
Map.Entry<SerFunc<T, Object>, Serializable> sourceGetterSetter = sourceEntry.getValue();
Map.Entry<SerFunc<R, Object>, Serializable> targetGetterSetter =
targetPropertyGetterSetterMap.get(property);
targetPropertyGetterSetterMap.get(property);

if (targetGetterSetter != null) {
SerFunc<T, Object> sourceGetter = sourceGetterSetter.getKey();
Expand All @@ -173,10 +173,16 @@ public static <T, R> R copyProperties(T source, R target, CopyOption copyOption)
LambdaExecutable sourceGetterLambda = LambdaHelper.resolve(sourceGetter);
LambdaExecutable targetGetterLambda = LambdaHelper.resolve(targetGetter);
Object value = sourceGetter.apply(source);
final Converter<Object, Object> converter = copyOption.getConverter((Class<?>) sourceGetterLambda.getReturnType(), (Class<?>) targetGetterLambda.getReturnType());
final Converter<Object, Object> converter =
copyOption.getConverter(
(Class<?>) sourceGetterLambda.getReturnType(),
(Class<?>) targetGetterLambda.getReturnType());
if (Objects.isNull(converter)) {
if (!copyOption.isIgnoreError()) {
throw new ConvertFailException(String.format("no convert from %s to %s", sourceGetterLambda.getReturnType(), targetGetterLambda.getReturnType()));
throw new ConvertFailException(
String.format(
"no convert from %s to %s",
sourceGetterLambda.getReturnType(), targetGetterLambda.getReturnType()));
}
} else {
value = converter.convert(value);
Expand All @@ -187,7 +193,9 @@ public static <T, R> R copyProperties(T source, R target, CopyOption copyOption)
if (BiConsumer.class.isAssignableFrom(setter.getClass())) {
SerFunc.<Serializable, BiConsumer<R, Object>>cast().apply(setter).accept(target, value);
} else if (BiFunction.class.isAssignableFrom(setter.getClass())) {
SerFunc.<Serializable, BiFunction<R, Object, R>>cast().apply(setter).apply(target, value);
SerFunc.<Serializable, BiFunction<R, Object, R>>cast()
.apply(setter)
.apply(target, value);
}
} catch (Exception e) {
if (copyOption.isIgnoreError()) {
Expand All @@ -199,5 +207,4 @@ public static <T, R> R copyProperties(T source, R target, CopyOption copyOption)
}
return target;
}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.dromara.streamquery.stream.core.bean;/*
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
Expand All @@ -14,6 +14,22 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.dromara.streamquery.stream.core.bean; /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* NoConverterException
Expand All @@ -22,23 +38,23 @@
*/
public class ConvertFailException extends RuntimeException {

/**
* Constructor for NoConverterException.
*
* @param cause a {@link java.lang.Throwable} object
*/
public ConvertFailException(Throwable cause) {
super(cause);
}
/**
* Constructor for NoConverterException.
*
* @param cause a {@link java.lang.Throwable} object
*/
public ConvertFailException(Throwable cause) {
super(cause);
}

/**
* Constructs a new runtime exception with the specified detail message. The cause is not
* initialized, and may subsequently be initialized by a call to {@link #initCause}.
*
* @param message the detail message. The detail message is saved for later retrieval by the
* {@link #getMessage()} method.
*/
public ConvertFailException(String message) {
super(message);
}
/**
* Constructs a new runtime exception with the specified detail message. The cause is not
* initialized, and may subsequently be initialized by a call to {@link #initCause}.
*
* @param message the detail message. The detail message is saved for later retrieval by the
* {@link #getMessage()} method.
*/
public ConvertFailException(String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,34 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.dromara.streamquery.stream.core.bean;

/**
* Converter
*
* @author [email protected]
* @param <S> source type
* @param <T> target type
*/
public interface Converter<S, T> {
T convert(S source);
/**
* convert
*
* @param source source
* @return target
*/
T convert(S source);
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.dromara.streamquery.stream.core.bean;

import java.util.Objects;
Expand All @@ -8,35 +24,41 @@
* @author [email protected]
*/
public class ConverterKey {
private Class<?> sourceType;
private Class<?> targetType;
private Class<?> sourceType;
private Class<?> targetType;

public Class<?> getSourceType() {
return sourceType;
}
public Class<?> getSourceType() {
return sourceType;
}

public void setSourceType(Class<?> sourceType) {
this.sourceType = sourceType;
}
public void setSourceType(Class<?> sourceType) {
this.sourceType = sourceType;
}

public Class<?> getTargetType() {
return targetType;
}
public Class<?> getTargetType() {
return targetType;
}

public void setTargetType(Class<?> targetType) {
this.targetType = targetType;
}
public void setTargetType(Class<?> targetType) {
this.targetType = targetType;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ConverterKey that = (ConverterKey) o;
return Objects.equals(sourceType, that.sourceType) && Objects.equals(targetType, that.targetType);
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}

@Override
public int hashCode() {
return Objects.hash(sourceType, targetType);
if (o == null || getClass() != o.getClass()) {
return false;
}
ConverterKey that = (ConverterKey) o;
return Objects.equals(sourceType, that.sourceType)
&& Objects.equals(targetType, that.targetType);
}

@Override
public int hashCode() {
return Objects.hash(sourceType, targetType);
}
}
Loading

0 comments on commit ec99412

Please sign in to comment.