public static Method getGetterMethod(Class<?> clazz, String name) { Method[] methods = clazz.getMethods(); for (Method method : methods) { String methodName = method.getName(); if (methodName.matches("^(get|is).*") && method.getParameterTypes().length == 0) { int idx = methodName.startsWith("get") ? 3 : 2; if (Introspector.decapitalize(methodName.substring(idx)).equals(name)) return method; } } throw new IllegalArgumentException("no such getter method: " + clazz.getName() + '.' + name); }
public static Method getGetterMethod(Class<?> clazz, String name) { Method[] methods = clazz.getMethods(); for (Method method : methods) { String methodName = method.getName(); if (methodName.matches("^(get|is).*") && method.getParameterTypes().length == 0) { int idx = methodName.startsWith("get") ? 3 : 2; if (Introspector.decapitalize(methodName.substring(idx)).equals(name)) return method; } } throw new IllegalArgumentException("no such getter method: " + clazz.getName() + '.' + name); }
public static Method getSetterMethod(Class<?> clazz, String name) { Method[] methods = clazz.getMethods(); for (Method method: methods) { String methodName = method.getName(); if ( methodName.startsWith("set") && method.getParameterTypes().length==1 ) { if ( Introspector.decapitalize( methodName.substring(3) ).equals(name) ) { return method; } } } throw new IllegalArgumentException("no such setter method: " + clazz.getName() + '.' + name); }
public static Method getSetterMethod(Class<?> clazz, String name) { Method[] methods = clazz.getMethods(); for (Method method: methods) { String methodName = method.getName(); if ( methodName.startsWith("set") && method.getParameterTypes().length==1 ) { if ( Introspector.decapitalize( methodName.substring(3) ).equals(name) ) { return method; } } } throw new IllegalArgumentException("no such setter method: " + clazz.getName() + '.' + name); }
@SuppressWarnings("unchecked") private static void introspectSet(Method method, Map<String, Map<String, Object>> propertyMap) { String methodName = method.getName(); if (!method.getName().startsWith("set")) return; if (method.getParameterTypes().length != 1 || method.getReturnType() != void.class) return; String propertyName = decapitalize(methodName.substring(3)); Map<String, Object> table = propertyMap.get(propertyName); if (table == null) { table = new HashMap<String, Object>(); propertyMap.put(propertyName, table); } List<Method> setters = (List<Method>)table.get("setters"); if (setters == null) { setters = new ArrayList<Method>(); table.put("setters", setters); } // add new setter setters.add(method); }
@SuppressWarnings("unchecked") private static void introspectSet(Method method, Map<String, Map<String, Object>> propertyMap) { String methodName = method.getName(); if (!method.getName().startsWith("set")) return; if (method.getParameterTypes().length != 1 || method.getReturnType() != void.class) return; String propertyName = decapitalize(methodName.substring(3)); Map<String, Object> table = propertyMap.get(propertyName); if (table == null) { table = new HashMap<String, Object>(); propertyMap.put(propertyName, table); } List<Method> setters = (List<Method>)table.get("setters"); if (setters == null) { setters = new ArrayList<Method>(); table.put("setters", setters); } // add new setter setters.add(method); }
@SuppressWarnings("unchecked") private static void introspectSet(Method method, Map<String, Map<String, Object>> propertyMap) { String methodName = method.getName(); if (!method.getName().startsWith("set")) return; if (method.getParameterTypes().length != 1 || method.getReturnType() != void.class) return; String propertyName = decapitalize(methodName.substring(3)); Map<String, Object> table = propertyMap.get(propertyName); if (table == null) { table = new HashMap<String, Object>(); propertyMap.put(propertyName, table); } List<Method> setters = (List<Method>)table.get("setters"); if (setters == null) { setters = new ArrayList<Method>(); table.put("setters", setters); } // add new setter setters.add(method); }
@SuppressWarnings("unchecked") private static void introspectSet(Method method, Map<String, Map<String, Object>> propertyMap) { String methodName = method.getName(); if (!method.getName().startsWith("set")) return; if (method.getParameterTypes().length != 1 || method.getReturnType() != void.class) return; String propertyName = decapitalize(methodName.substring(3)); Map<String, Object> table = propertyMap.get(propertyName); if (table == null) { table = new HashMap<String, Object>(); propertyMap.put(propertyName, table); } List<Method> setters = (List<Method>)table.get("setters"); if (setters == null) { setters = new ArrayList<Method>(); table.put("setters", setters); } // add new setter setters.add(method); }
@SuppressWarnings("unchecked") private static void introspectGet(Method method, Map<String, Map<String, Object>> propertyMap) { String methodName = method.getName(); if (!(method.getName().startsWith("get") || method.getName().startsWith("is"))) return; if (method.getParameterTypes().length > 0 || method.getReturnType() == void.class) return; if (method.getName().startsWith("is") && method.getReturnType() != boolean.class) return; String propertyName = method.getName().startsWith("get") ? methodName.substring(3) : methodName.substring(2); propertyName = decapitalize(propertyName); Map<String, Object> table = propertyMap.get(propertyName); if (table == null) { table = new HashMap<String, Object>(); propertyMap.put(propertyName, table); } List<Method> getters = (List<Method>)table.get("getters"); if (getters == null) { getters = new ArrayList<Method>(); table.put("getters", getters); } getters.add(method); }
@SuppressWarnings("unchecked") private static void introspectGet(Method method, Map<String, Map<String, Object>> propertyMap) { String methodName = method.getName(); if (!(method.getName().startsWith("get") || method.getName().startsWith("is"))) return; if (method.getParameterTypes().length > 0 || method.getReturnType() == void.class) return; if (method.getName().startsWith("is") && method.getReturnType() != boolean.class) return; String propertyName = method.getName().startsWith("get") ? methodName.substring(3) : methodName.substring(2); propertyName = decapitalize(propertyName); Map<String, Object> table = propertyMap.get(propertyName); if (table == null) { table = new HashMap<String, Object>(); propertyMap.put(propertyName, table); } List<Method> getters = (List<Method>)table.get("getters"); if (getters == null) { getters = new ArrayList<Method>(); table.put("getters", getters); } getters.add(method); }
@SuppressWarnings("unchecked") private static void introspectGet(Method method, Map<String, Map<String, Object>> propertyMap) { String methodName = method.getName(); if (!(method.getName().startsWith("get") || method.getName().startsWith("is"))) return; if (method.getParameterTypes().length > 0 || method.getReturnType() == void.class) return; if (method.getName().startsWith("is") && method.getReturnType() != boolean.class) return; String propertyName = method.getName().startsWith("get") ? methodName.substring(3) : methodName.substring(2); propertyName = decapitalize(propertyName); Map<String, Object> table = propertyMap.get(propertyName); if (table == null) { table = new HashMap<String, Object>(); propertyMap.put(propertyName, table); } List<Method> getters = (List<Method>)table.get("getters"); if (getters == null) { getters = new ArrayList<Method>(); table.put("getters", getters); } getters.add(method); }
@SuppressWarnings("unchecked") private static void introspectGet(Method method, Map<String, Map<String, Object>> propertyMap) { String methodName = method.getName(); if (!(method.getName().startsWith("get") || method.getName().startsWith("is"))) return; if (method.getParameterTypes().length > 0 || method.getReturnType() == void.class) return; if (method.getName().startsWith("is") && method.getReturnType() != boolean.class) return; String propertyName = method.getName().startsWith("get") ? methodName.substring(3) : methodName.substring(2); propertyName = decapitalize(propertyName); Map<String, Object> table = propertyMap.get(propertyName); if (table == null) { table = new HashMap<String, Object>(); propertyMap.put(propertyName, table); } List<Method> getters = (List<Method>)table.get("getters"); if (getters == null) { getters = new ArrayList<Method>(); table.put("getters", getters); } getters.add(method); }