集册 Java实例教程 获取方法后缀

获取方法后缀

欢马劈雪     最近更新时间:2020-01-02 10:19:05

568
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
获取方法后缀

/**

 * JLibs: Common Utilities for Java

 * Copyright (C) 2009  Santhosh Kumar T <santhosh.tekuri@gmail.com>

 *

 * This library is free software; you can redistribute it and/or

 * modify it under the terms of the GNU Lesser General Public

 * License as published by the Free Software Foundation; either

 * version 2.1 of the License, or (at your option) any later version.

 *

 * This library is distributed in the hope that it will be useful,

 * but WITHOUT ANY WARRANTY; without even the implied warranty of

 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU

 * Lesser General Public License for more details.

 */

//package com.nowjava;/*N o  w  J a v a . c o m - 时  代  Java*/


import java.util.Locale;


public class Main {

    public static void main(String[] argv) throws Exception {

        String property = "nowjava.com";

        System.out.println(getMethodSuffix(property));

    }


    public static String getMethodSuffix(String property) {

        switch (property.length()) {/** from nowjava.com - 时  代  Java**/

        case 0:

            throw new IllegalArgumentException("invalid property name: "

                    + property);

        case 1:

            return property.toUpperCase(Locale.ENGLISH);

        default:

            char char0 = property.charAt(0);

            boolean upper0 = Character.isUpperCase(char0);

            char char1 = property.charAt(1);

            boolean upper1 = Character.isUpperCase(char1);

            if (upper0 && upper1) // XCoordinate ==> getXCordinate()

                return property;

            if (!upper0 && !upper1) // xcoordinate ==> getXcoordinate()

                return 
展开阅读全文