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

com.jdroid.javaweb.guava.function.PropertyFunction Maven / Gradle / Ivy

The newest version!
package com.jdroid.javaweb.guava.function;

import java.io.Serializable;
import com.google.common.base.Function;
import com.jdroid.java.utils.ReflectionUtils;

/**
 * Transforms an object into one of its property
 * 
 * @param  The type of the parameter object
 * @param  The type of the result object
 * 
 */
public class PropertyFunction implements Function, Serializable {
	
	private String propertyName;
	
	/**
	 * @param propertyName The name of the object's property
	 */
	public PropertyFunction(String propertyName) {
		this.propertyName = propertyName;
	}
	
	/**
	 * @see com.google.common.base.Function#apply(java.lang.Object)
	 */
	@SuppressWarnings("unchecked")
	@Override
	public T apply(F from) {
		return (T)ReflectionUtils.getFieldValue(from, this.propertyName);
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy