Java Class Field Convert To fieldToGetMethod(String fieldName)

Here you can find the source of fieldToGetMethod(String fieldName)

Description

field To Get Method

License

Apache License

Parameter

Parameter Description
fieldName e.g. name

Return

e.g. getName

Declaration

public static String fieldToGetMethod(String fieldName) 

Method Source Code

//package com.java2s;
/*//from w  w  w  . jav a2  s .  c  om
 * Copyright 2013-2016 iNeunet OpenSource and the original author or authors.
 *
 * 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.
 */

public class Main {
    /**
     * @param fieldName e.g. name
     * @return e.g. getName
     */
    public static String fieldToGetMethod(String fieldName) {
        return "get" + toFirstUpper(fieldName);
    }

    /**
     * e.g. strUtils to StrUtils, str to Str
     * @param string e.g. strUtils
     * @return e.g. StringUtils
     */
    public static String toFirstUpper(String string) {
        int c = ((int) string.charAt(0));
        if (c >= 97 && c <= 122) {
            // is lower
            char Upp = (char) (((int) string.charAt(0)) - 32);
            return Upp + string.substring(1);
        }
        return string;
    }
}

Related

  1. fieldToColumnName(String name)
  2. fieldToProperty(String field)
  3. fieldToPropertyName(String name)
  4. fieldToString(String name, Object value)
  5. fieldToValue(byte[] buffer, int offset, int length)