com.jdroid.javaweb.guava.function.PropertyFunction Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jdroid-java-webapp Show documentation
Show all versions of jdroid-java-webapp Show documentation
Jdroid library for Java Web apps
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);
}
}