com.github.paganini2008.devtools.beans.streaming.Transformers Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of devtools-beans-streaming Show documentation
Show all versions of devtools-beans-streaming Show documentation
a useful java tools based on java collection stream framework
package com.github.paganini2008.devtools.beans.streaming;
import java.util.Map;
import com.github.paganini2008.devtools.beans.BeanUtils;
import com.github.paganini2008.devtools.beans.PropertyFilter;
import com.github.paganini2008.devtools.beans.PropertyFilters;
import com.github.paganini2008.devtools.beans.PropertyUtils;
/**
*
* Transformers
*
* @author Fred Feng
*
*
* @version 1.0
*/
public abstract class Transformers {
public static Transformer> asMap() {
return asMap((PropertyFilter) null);
}
public static Transformer> asMap(String[] propertyNames) {
return asMap(PropertyFilters.includedProperties(propertyNames));
}
public static Transformer> asMap(PropertyFilter propertyFilter) {
return e -> {
return PropertyUtils.convertToMap(e, null, propertyFilter);
};
}
public static Transformer asBean(Class requiredType, String[] propertyNames) {
return asBean(requiredType, PropertyFilters.includedProperties(propertyNames));
}
public static Transformer asBean(Class requiredType) {
return asBean(requiredType, (PropertyFilter) null);
}
public static Transformer asBean(Class requiredType, PropertyFilter propertyFilter) {
return e -> {
return BeanUtils.copy(e, requiredType, propertyFilter);
};
}
}