Java Getter Name Create toGetterName(String name)

Here you can find the source of toGetterName(String name)

Description

to Getter Name

License

BSD License

Declaration

public static String toGetterName(String name) 

Method Source Code

//package com.java2s;
//License from project: BSD License 

public class Main {
    public static String toGetterName(String name) {
        return tohPrefixialCamelName(name, "get");
    }//from   ww w  . j  ava  2  s .c  om

    public static String tohPrefixialCamelName(String name, String prefix) {
        if (name == null || name.length() == 0) {
            return "";
        }
        StringBuffer buffer = new StringBuffer();
        String camelName = toCamelName(name);
        return buffer.append(prefix).append(camelName).toString();
    }

    public static String toCamelName(String name) {
        if (name == null || name.length() == 0) {
            return "";
        }
        char firstChar = name.charAt(0);
        if (!Character.isLetter(firstChar)) {
            return name;
        }
        char upperChar = Character.toUpperCase(firstChar);
        StringBuffer buffer = new StringBuffer();
        return buffer.append(upperChar).append(name.substring(1, name.length())).toString();
    }
}

Related

  1. toGetter(final String field)
  2. toGetter(String fieldName)
  3. toGetter(String name)
  4. toGetterMethodName(String s)
  5. toGetterName(String name)
  6. toGetterName(String property)
  7. toGetterString(String str)