Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

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

public class Main {
    /**
     * Converts a method name to a Java attribute name, e.g. getFooBar() --> fooBar, isFlag --> flag.
     * @param methodName
     * @return
     */
    public static String methodNameToJavaAttributeName(final String methodName) {
        String name = methodName;
        if ((methodName.startsWith("get") || methodName.startsWith("set")) && methodName.length() > 3)
            name = methodName.substring(3);
        else if (methodName.startsWith("is") && methodName.length() > 2)
            name = methodName.substring(2);

        if (Character.isUpperCase(name.charAt(0)))
            return name.substring(0, 1).toLowerCase() + name.substring(1);
        return name;
    }
}