Java Reflection Method Getter Get getGetterMethod(Class clazz, String methodNameWithoutGetPrefix)

Here you can find the source of getGetterMethod(Class clazz, String methodNameWithoutGetPrefix)

Description

get Getter Method

License

Open Source License

Declaration

public static Method getGetterMethod(Class<?> clazz, String methodNameWithoutGetPrefix)
            throws ClassNotFoundException 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2014 Salesforce.com, inc..
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * /*from   ww w .j a  v a2 s  . c  o m*/
 * Contributors:
 *     Salesforce.com, inc. - initial API and implementation
 ******************************************************************************/

import java.lang.reflect.Method;

import java.util.Collection;

import java.util.List;

import java.util.Map;

public class Main {
    public static Method getGetterMethod(Class<?> clazz, String methodNameWithoutGetPrefix)
            throws ClassNotFoundException {
        Method getterMethod = null;
        Method[] methods = clazz.getDeclaredMethods();
        if (isNotEmpty(methods)) {
            for (Method method : methods) {
                if (method.getName().equals("get" + methodNameWithoutGetPrefix)
                        && method.getGenericParameterTypes().length == 0) {
                    getterMethod = method;
                    break;
                }
            }
        }
        return getterMethod;
    }

    public static boolean isNotEmpty(Object obj) {
        return !isEmpty(obj);
    }

    public static boolean isNotEmpty(Object[] objs) {
        return !isEmpty(objs);
    }

    public static boolean isNotEmpty(byte[] objs) {
        return !isEmpty(objs);
    }

    public static boolean isNotEmpty(Collection<?> col) {
        return !isEmpty(col);
    }

    public static boolean isNotEmpty(List<?> col) {
        return !isEmpty(col);
    }

    public static boolean isNotEmpty(Map<?, ?> map) {
        return map != null && !map.isEmpty();
    }

    public static boolean isNotEmpty(String str) {
        return !isEmpty(str);
    }

    public static boolean isEmpty(Object obj) {
        return obj == null;
    }

    public static boolean isEmpty(Object[] objs) {
        return objs == null || objs.length == 0;
    }

    public static boolean isEmpty(byte[] objs) {
        return objs == null || objs.length == 0;
    }

    public static boolean isEmpty(Collection<?> col) {
        return col == null || col.isEmpty();
    }

    public static boolean isEmpty(List<?> col) {
        return col == null || col.isEmpty();
    }

    public static boolean isEmpty(Map<?, ?> map) {
        return map == null || map.isEmpty();
    }

    public static boolean isEmpty(String str) {
        return str == null || str.length() == 0;
    }
}

Related

  1. getGetterMethod(Class containingClass, String propertyName)
  2. getGetterMethod(Class type, String property)
  3. getGetterMethod(Class beanClass, String property)
  4. getGetterMethod(Class c, String field)
  5. getGetterMethod(Class clazz, String fieldName)
  6. getGetterMethod(Class clazz, String name)
  7. getGetterMethod(Class clazz, String propertyName)
  8. getGetterMethod(String getterName, Object bean, Class returnType)
  9. getGetterMethodByProperty(String propertyName, Class beanClass, Class returnType)