mirror of https://github.com/longtai-cn/hippo4j
fix : config BeanUtil merged to common(#725)
parent
529c45db77
commit
d902e2a942
@ -1,67 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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 cn.hippo4j.config.toolkit;
|
|
||||||
|
|
||||||
import com.github.dozermapper.core.DozerBeanMapperBuilder;
|
|
||||||
import com.github.dozermapper.core.Mapper;
|
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Bean util.
|
|
||||||
*/
|
|
||||||
public class BeanUtil {
|
|
||||||
|
|
||||||
private BeanUtil() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
protected static Mapper BEAN_MAPPER_BUILDER;
|
|
||||||
|
|
||||||
static {
|
|
||||||
BEAN_MAPPER_BUILDER = DozerBeanMapperBuilder.buildDefault();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static <T, S> T convert(S source, Class<T> clazz) {
|
|
||||||
return Optional.ofNullable(source)
|
|
||||||
.map(each -> BEAN_MAPPER_BUILDER.map(each, clazz))
|
|
||||||
.orElse(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static <T, S> List<T> convert(List<S> sources, Class<T> clazz) {
|
|
||||||
return Optional.ofNullable(sources)
|
|
||||||
.map(each -> {
|
|
||||||
List<T> targetList = new ArrayList<T>(each.size());
|
|
||||||
each.stream()
|
|
||||||
.forEach(item -> targetList.add(BEAN_MAPPER_BUILDER.map(item, clazz)));
|
|
||||||
return targetList;
|
|
||||||
})
|
|
||||||
.orElse(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static <T, S> Set<T> convert(Set<S> sources, Class<T> clazz) {
|
|
||||||
return Optional.ofNullable(sources)
|
|
||||||
.map(each -> {
|
|
||||||
Set<T> targetSize = new HashSet<T>(each.size());
|
|
||||||
each.stream()
|
|
||||||
.forEach(item -> targetSize.add(BEAN_MAPPER_BUILDER.map(item, clazz)));
|
|
||||||
return targetSize;
|
|
||||||
})
|
|
||||||
.orElse(null);
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in new issue