package com.kdanmobile.reader;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

public class ReflectionHelper {

    private ReflectionHelper() {}

    public static Object getPrivateValue(Object object, String fieldName, Class clazz) {
        try {
            Field field = clazz.getDeclaredField(fieldName);
            field.setAccessible(true);
            return field.get(object);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    public static void setPrivateValue(Object object, String fieldName, Object value, Class clazz) {
        try {
            Field field = clazz.getDeclaredField(fieldName);
            field.setAccessible(true);
            field.set(object, value);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static Method getPrivateMethod(String name, Class clazz, Class<?>... parameterTypes) {
        try {
            Method method = clazz.getDeclaredMethod(name, parameterTypes);
            method.setAccessible(true);
            return method;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}