Java Reflection Method Setter Get getSetters(Class klass)

Here you can find the source of getSetters(Class klass)

Description

get Setters

License

Apache License

Declaration

private static Map<String, Method> getSetters(Class<?> klass) 

Method Source Code

//package com.java2s;
/*/* w  ww  .j  av a 2 s  .c  om*/
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

import java.lang.reflect.Method;
import java.lang.reflect.Modifier;

import java.util.HashMap;

import java.util.Locale;
import java.util.Map;

public class Main {
    private static Map<String, Method> getSetters(Class<?> klass) {
        Map<String, Method> methods = new HashMap<String, Method>();
        for (Method method : klass.getMethods()) {
            String name = method.getName();
            if (name.startsWith("set") && name.length() > 3 && Modifier.isPublic(method.getModifiers())
                    && !Modifier.isStatic(method.getModifiers()) && Void.TYPE.equals(method.getReturnType())
                    && method.getParameterTypes().length == 1) {
                methods.put(name.substring(3, 4).toLowerCase(Locale.ENGLISH) + name.substring(4), method);
            }
        }
        return methods;
    }
}

Related

  1. getSetters(Class klass)
  2. getSetters(Class klass)
  3. getSetters(Class c)
  4. getSetters(Class clazz)
  5. getSetters(Class clazz)
  6. getSetters(Object obj)
  7. getSettersForType(Class clazz, String typeName)
  8. getSetterShorthandName(Method method)
  9. getSetterType(Method method)