Java Setter Name Create toSetterName(String name)

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

Description

to Setter Name

License

BSD License

Declaration

public static String toSetterName(String name) 

Method Source Code

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

public class Main {
    public static String toSetterName(String name) {
        return tohPrefixialCamelName(name, "set");
    }//from ww w .  j ava 2 s. co m

    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. toSetterName(String field)
  2. toSetterName(String fieldName)
  3. toSetterName(String property)