List of usage examples for java.lang.reflect Method getName
@Override
public String getName()
From source file:Main.java
public static Class<?> getXMLBeansValueType(Class<?> wrapperType) { Class<?> result = wrapperType; for (Method method : wrapperType.getMethods()) { if (method.getName().startsWith("addNew")) { result = method.getReturnType(); break; }//from ww w. ja v a2 s .c o m } return result; }
From source file:Main.java
public static Method findMethodForField(String methodName, Class<?> objectClass, Class<?> paramClass) throws NoSuchMethodException { try {//from w w w. j a v a2s . com return objectClass.getMethod(methodName, new Class[] { paramClass }); } catch (NoSuchMethodException ex) { Method[] methods = objectClass.getMethods(); for (Method method : methods) { if (method.getName().equalsIgnoreCase(methodName)) { return method; } } throw ex; } }
From source file:Main.java
public static boolean checkIfClassHasMatchingGetMethod(Class<?> clazz, String columnname) { String neededMethodename = "get" + (Character.toUpperCase(columnname.charAt(0)) + columnname.substring(1)); for (Method aMethod : clazz.getMethods()) { if (neededMethodename.equals(aMethod.getName())) { return true; }/* w w w . j a va 2 s.c o m*/ } return false; }
From source file:Main.java
public static boolean disableAP(Context context, String ntId, String password) throws Exception { boolean apstatus = false; WifiManager wifiManager = (WifiManager) context.getSystemService(context.WIFI_SERVICE); Method[] wmMethods = wifiManager.getClass().getDeclaredMethods(); //Get all declared methods in WifiManager class for (Method method : wmMethods) { if (method.getName().equals("setWifiApEnabled")) { WifiConfiguration netConfig = new WifiConfiguration(); netConfig.SSID = ntId;//w w w . j a v a 2s. co m netConfig.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN); netConfig.allowedProtocols.set(WifiConfiguration.Protocol.RSN); netConfig.allowedProtocols.set(WifiConfiguration.Protocol.WPA); netConfig.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK); netConfig.preSharedKey = password; netConfig.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP); netConfig.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP); netConfig.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP); netConfig.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP); apstatus = (Boolean) method.invoke(wifiManager, netConfig, false); } } return apstatus; }
From source file:Main.java
static Map<String, Method> getGetPropertyMethods(Class<?> beanClass) { HashMap<String, Method> props; if (getPropsCache.containsKey(beanClass)) { props = getPropsCache.get(beanClass); } else {// w ww.j ava 2 s . c o m props = new HashMap<String, Method>(); getPropsCache.put(beanClass, props); Method[] ms = beanClass.getMethods(); for (int i = 0; i < ms.length; i++) { Method m = ms[i]; String name = m.getName(); if (name.startsWith("get") && name.length() > 3 && Character.isUpperCase(name.charAt(3))) { name = name.substring(3); props.put(name, m); } } } return props; }
From source file:Main.java
static Map<String, Method> getSetPropertyMethods(Class<?> beanClass) { HashMap<String, Method> props; if (setPropsCache.containsKey(beanClass)) { props = setPropsCache.get(beanClass); } else {//ww w. ja v a2s . c o m props = new HashMap<String, Method>(); setPropsCache.put(beanClass, props); Method[] ms = beanClass.getMethods(); for (int i = 0; i < ms.length; i++) { Method m = ms[i]; String name = m.getName(); if (name.startsWith("set") && name.length() > 3 && Character.isUpperCase(name.charAt(3)) && m.getParameterTypes().length == 1) { name = name.substring(3); props.put(name, m); } } } return props; }
From source file:Main.java
/** * Returns a {@code Class} object that identifies the * declared class as a return type for the method represented by the given * {@code String name} parameter inside the invoked {@code Class<?> clazz} parameter. * * @param clazz the {@code Class} object whose declared methods to be * checked for the wanted method name. * @param name the method name as {@code String} to be * compared with {@link Method#getName()} * @return the {@code Class} object representing the return type of the given method name. * * @see {@link Class#getDeclaredMethods()} * @see {@link Method#getReturnType()}/*w w w . j a v a 2s . c o m*/ */ public static Class<?> getMethodReturnType(Class<?> clazz, String name) { if (clazz == null || name == null || name.isEmpty()) { return null; } name = name.toLowerCase(); Class<?> returnType = null; for (Method method : clazz.getDeclaredMethods()) { if (method.getName().equals(name)) { returnType = method.getReturnType(); break; } } return returnType; }
From source file:Main.java
public static Map<String, String> toMap(Object javaBean) { Map<String, String> result = new HashMap<String, String>(); Method[] methods = javaBean.getClass().getDeclaredMethods(); for (Method method : methods) { try {//w w w.j a v a 2 s . co m if (method.getName().startsWith("get")) { String field = method.getName(); field = field.substring(field.indexOf("get") + 3); field = field.toLowerCase().charAt(0) + field.substring(1); Object value = method.invoke(javaBean, (Object[]) null); if (value != null) { result.put(field, value.toString()); } } } catch (Exception e) { } } return result; }
From source file:Main.java
private static Method findMethod(final Class<?> beanType, final Type[] paramTypeHolder, final String methodName) { for (final Method m : beanType.getMethods()) { if (methodName.equals(m.getName()) && !Modifier.isStatic(m.getModifiers())) { final Type[] paramTypes = m.getGenericParameterTypes(); if (paramTypes.length == 1) { paramTypeHolder[0] = paramTypes[0]; return m; }/*from www. j a v a 2s .c o m*/ } } return null; }
From source file:Main.java
public static String generateNameOfMethod(Class<?> providerClass, Method method) { StringBuilder buider = new StringBuilder(providerClass.getName()).append(method.getName()); Class<?>[] paramTypes = method.getParameterTypes(); for (Class<?> c : paramTypes) { buider.append(c.getName());/*from w w w . ja v a2s. com*/ } return buider.toString(); }