normalized Setter Name - Java Reflection

Java examples for Reflection:Setter

Description

normalized Setter Name

Demo Code


//package com.java2s;

public class Main {
    public static void main(String[] argv) throws Exception {
        String propertyName = "java2s.com";
        System.out.println(normalizedSetterName(propertyName));
    }/*  w ww.  j av  a  2  s  .  com*/

    public static String SETTER_PREFIX = "set";

    public static String normalizedSetterName(String propertyName) {
        String propertyBaseName = normalizePropertyBaseName(propertyName);
        return SETTER_PREFIX + propertyBaseName;
    }

    /**
     * @param propertyName
     * @return
     */
    private static String normalizePropertyBaseName(String propertyName) {
        if (propertyName == null)
            return null;
        propertyName = propertyName.trim();
        if (propertyName.length() < 1)
            return "";
        char firstChar = propertyName.charAt(0);
        return Character.toUpperCase(firstChar) + propertyName.substring(1);
    }
}

Related Tutorials