normalized Getter Name - Java Reflection

Java examples for Reflection:Getter

Description

normalized Getter Name

Demo Code


//package com.java2s;

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

    public static String GETTER_PREFIX = "get";

    public static String normalizedGetterName(String propertyName) {
        String propertyBaseName = normalizePropertyBaseName(propertyName);
        return GETTER_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