Here you can find the source of getSetterMap(Class cls)
Parameter | Description |
---|---|
cls | a parameter |
public static Map getSetterMap(Class cls)
//package com.java2s; //License from project: Apache License import java.lang.reflect.Method; import java.util.Collection; import java.util.Map; import java.util.TreeMap; public class Main { /**// ww w . j a v a2s.com * * @param cls * @return setter map * @deprecated *///FIXME: java docs @return, check if this is used? public static Map getSetterMap(Class cls) { TreeMap map = new TreeMap(); Method methods[] = getAllSetters(cls); String memberName; for (int i = 0; i < methods.length; i++) { memberName = methods[i].getName(); memberName = memberName.substring(3); map.put(memberName, methods[i]); } return map; } public static Method[] getAllSetters(Class cls) { Map map = getAllSettersMap(cls); if (map == null) { return null; } Collection col = map.values(); return (Method[]) col.toArray(new Method[0]); } public static Map getAllSettersMap(Class cls) { if (cls == null) { return null; } Method methods[] = cls.getMethods(); TreeMap map = new TreeMap(); Method method; String name; try { for (int i = 0; i < methods.length; i++) { method = methods[i]; name = method.getName(); if (name.length() <= 3 || name.startsWith("set") == false) { continue; } if (method.getParameterTypes().length == 1) { map.put(method.getName(), method); } } } catch (Exception ex) { ex.printStackTrace(); } return map; } }