remove Method Accessor - Java Reflection

Java examples for Reflection:Method Name

Description

remove Method Accessor

Demo Code

//package com.java2s;

public class Main {
    public static void main(String[] argv) {
        String s = "getName";
        System.out.println(removeMethodAccessor(s));
    }/*  w  w w . j av a  2s.c  om*/

    public static String removeMethodAccessor(String s) {
        if (isNotEmptyWithTrim(s)) {
            if (s.startsWith("get")) {
                return s.length() > 3 ? s.substring(3) : s;
            } else if (s.startsWith("is")) {
                return s.length() > 2 ? s.substring(2) : s;
            } else if (s.startsWith("set")) {
                return s.length() > 3 ? s.substring(3) : s;
            }
        }
        return s;
    }

    public static boolean isNotEmptyWithTrim(String s) {
        return !isEmptyWithTrim(s);
    }

    public static boolean isEmptyWithTrim(String s) {
        return s == null || s.trim().length() == 0;
    }
}

Related Tutorials