All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.paganini2008.devtools.beans.streaming.Transformers Maven / Gradle / Ivy

There is a newer version: 2.0.5
Show newest version
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);
		};
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy