org.azeckoski.reflectutils.ClassFields Java Examples

The following examples show how to use org.azeckoski.reflectutils.ClassFields. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CSVApisUtil.java    From sofa-acts with Apache License 2.0 6 votes vote down vote up
public static Map<String, Field> findTargetClsFields(Class<?> cls) {
    if (isWrapClass(cls)) {
        return null;
    }
    ReflectUtils refUtil = ReflectUtils.getInstance();
    ClassFields<?> clsFiled = refUtil.analyzeClass(cls);
    List<Field> getPro = clsFiled.getClassData().getFields();
    Map<String, Field> reClsProp = new HashMap<String, Field>();
    for (Field proValue : getPro) {
        if (Modifier.isFinal(proValue.getModifiers())
            || Modifier.isStatic(proValue.getModifiers())) {
            continue;
        }
        String propName = proValue.getName();
        reClsProp.put(propName, proValue);
    }

    return reClsProp;
}
 
Example #2
Source File: EnumConverter.java    From reflectutils with Apache License 2.0 6 votes vote down vote up
public Enum convertInterface(Object value, Class<? extends Enum> implementationType) {
    Enum convert = null;
    String name = value.toString(); // can only deal with strings
    // now we try to find the enum field in this enum class
    ClassFields<Enum> cf = (ClassFields<Enum>) getFieldUtils().analyzeClass(implementationType);
    List<Enum> enumConstants = cf.getClassData().getEnumConstants();
    for (Enum e : enumConstants) {
        if (e.name().equals(name)) {
            // found the matching enum
            convert = e;
            break;
        }
    }
    if (convert == null) {
        throw new UnsupportedOperationException("Failure attempting to create enum for name ("+name+") in ("+implementationType+")");
    }
    return convert;
}