chaschev.lang.Functions2 Maven / Gradle / Ivy
package chaschev.lang;
import chaschev.lang.reflect.ClassDesc;
import chaschev.lang.reflect.ConstructorDesc;
import chaschev.lang.reflect.MethodDesc;
import chaschev.util.Exceptions;
import com.google.common.base.Function;
import com.google.common.base.Preconditions;
import javax.annotation.Nullable;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
/**
* @author Andrey Chaschev [email protected]
*/
public class Functions2 {
public static ObjectMethod constructor(final Class aClass, final Class... params){
return new ObjectMethod() {
private final ConstructorDesc constructor = OpenBean.getClassDesc(aClass).getConstructorDesc(false, params);
@Override
public T create(Object... params) {
return constructor.newInstance(params);
}
};
}
public static ObjectMethod method(final Object obj, final String method, final Class... params){
return method(obj, method, false, params);
}
public static ObjectMethod method(final Object obj, final String method, final boolean strictly, final Class... params){
return new ObjectMethod() {
private final MethodDesc methodDesc = OpenBean.getClassDesc(obj.getClass()).getMethodDesc(method, strictly, params);
@Override
public T create(Object... params) {
return (T) methodDesc.invoke(obj, params);
}
};
}
public static ObjectMethod dynamicConstructor(final Class aClass){
return new ObjectMethod() {
private final ClassDesc classDesc = OpenBean.getClassDesc(aClass);
@Override
public T create(Object... params) {
return classDesc.getConstructorDesc(false, params).newInstance(params);
}
};
}
@SuppressWarnings("unchecked")
public static
© 2015 - 2025 Weber Informatics LLC | Privacy Policy