Java Reflection Method Setter Get getSetter(String s)

Here you can find the source of getSetter(String s)

Description

This new method 'slightly' outperforms the old method, it was essentially a perfect example of me wasting my time and a premature optimization.

License

Apache License

Parameter

Parameter Description
s -

Return

String

Declaration

public static String getSetter(String s) 

Method Source Code

//package com.java2s;
/**/* w  w  w . j a  va  2s.co m*/
 * MVEL 2.0
 * Copyright (C) 2007 The Codehaus
 * Mike Brock, Dhanji Prasanna, John Graham, Mark Proctor
 *
 * Licensed 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 static java.lang.Character.toUpperCase;

public class Main {
    /**
     * This new method 'slightly' outperforms the old method, it was
     * essentially a perfect example of me wasting my time and a
     * premature optimization.  But what the hell...
     *
     * @param s -
     * @return String
     */
    public static String getSetter(String s) {
        char[] chars = new char[s.length() + 3];

        chars[0] = 's';
        chars[1] = 'e';
        chars[2] = 't';

        chars[3] = toUpperCase(s.charAt(0));

        for (int i = s.length() - 1; i != 0; i--) {
            chars[i + 3] = s.charAt(i);
        }

        return new String(chars);
    }
}

Related

  1. getSetter(Object target, String property, Class parameterType)
  2. getSetter(String fieldName, Class clazz, Class fieldType)
  3. getSetter(String key, Class clazz, Class paramClazz)
  4. getSetter(String property, Object o)
  5. getSetter(String propertyName, Class clazz, Class arg)
  6. getSetterAttributeType(Method m)
  7. getSetterFieldName(Method method)
  8. getSetterForGetter(Method[] methods, Method getter)
  9. getSetterFromCache(Class clazz)