Java Java String Format toJavaMethodName(String sqlNotation)

Here you can find the source of toJavaMethodName(String sqlNotation)

Description

Convert name of format THIS_IS_A_NAME to thisIsAName For each letter: if not '_' then convert to lower case and add to output string if '_' then skip letter and add next letter to output string without converting to lower case

License

Open Source License

Parameter

Parameter Description
sqlNotation a parameter

Return

A name complaint with naming convention for Java methods and fields, converted from SQL name

Declaration

public static String toJavaMethodName(String sqlNotation) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2011 MadRobot./*from   w ww  . ja v a 2 s. c  o  m*/
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Lesser Public License v2.1
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 * 
 * Contributors:
 *  Elton Kent - initial API and implementation
 ******************************************************************************/

public class Main {
    /**
     * Convert name of format THIS_IS_A_NAME to thisIsAName For each letter: if
     * not '_' then convert to lower case and add to output string if '_' then
     * skip letter and add next letter to output string without converting to
     * lower case
     * 
     * @param sqlNotation
     * @return A name complaint with naming convention for Java methods and
     *         fields, converted from SQL name
     */
    public static String toJavaMethodName(String sqlNotation) {
        StringBuilder dest = new StringBuilder();
        char[] src = sqlNotation.toCharArray();

        for (int i = 0; i < src.length; i++) {
            char c = src[i];
            boolean isFirstChar = (i == 0) ? true : false;

            if (isFirstChar || c != '_') {
                dest.append(Character.toLowerCase(c));
            } else {
                i++;
                if (i < src.length) {
                    dest.append(src[i]);
                }
            }
        }
        return dest.toString();
    }
}

Related

  1. toJavaIdentifier(String text, Boolean uppercaseFirst)
  2. toJavaIdentifierCamelCase(String tmp)
  3. toJavaIdentifierString(String className)
  4. toJavaImplClassName(String podName, String typeName)
  5. toJavaImplSig(String jsig)
  6. toJavaMethodName(String... words)
  7. toJavaName(String name)
  8. toJavaName(String name)
  9. toJavaPackageName(String name)