ReflectUtil

import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;

import com.google.common.collect.Maps;

public class ReflectUtil {

public static <T> Map<String, PropertyDescriptor> parserPropertyDescs(Class<T> clazz) throws
    IntrospectionException {
    Map<String, PropertyDescriptor> propertyInfos = Maps.newHashMap();
    BeanInfo beanInfo = Introspector.getBeanInfo(clazz, Object.class);
    PropertyDescriptor pds[] = beanInfo.getPropertyDescriptors();
    for (PropertyDescriptor pd : pds) {
        if (pd.getWriteMethod() != null && pd.getReadMethod() != null) {
            propertyInfos.put(pd.getName(), pd);
        }
    }
    return propertyInfos;
}

public static String parseField(String s) {
    if(StringUtils.isBlank(s)) {
        return s;
    }
    for(int i=0; i<s.length(); i++) {
        if(s.charAt(i) == '(') {
            return s.substring(0, i);
        }
    }
    return s;
}

public static String[] merge(String[][] ss) {
    if(ss == null) {
        return null;
    }
    String[] returnResult = new String[ss.length];
    for(int i=0; i<ss.length; i++) {
        String[] s = ss[i];
        returnResult[i] = s[0] + "(" + s[1] + ")";
    }
    return returnResult;
}

}

仅有 1 条评论
  1. 活捉大佬一只

添加新评论