Java Class Load getClassName(String logicalName, String trailingName)

Here you can find the source of getClassName(String logicalName, String trailingName)

Description

Returns the class name for the given logical name and trailing name.

License

Apache License

Parameter

Parameter Description
logicalName The logical name
trailingName The trailing name

Return

The class name

Declaration

public static String getClassName(String logicalName, String trailingName) 

Method Source Code


//package com.java2s;
/*/*  w ww. j  a  v  a 2s  .co  m*/
 * Copyright 2008 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.util.*;

public class Main {
    /**
     * Returns the class name for the given logical name and trailing name. For example "person" and "Controller" would evaluate to "PersonController"
     *
     * @param logicalName The logical name
     * @param trailingName The trailing name
     * @return The class name
     */
    public static String getClassName(String logicalName, String trailingName) {
        if (isBlank(logicalName)) {
            throw new IllegalArgumentException("Argument [logicalName] cannot be null or blank");
        }

        String className = logicalName.substring(0, 1).toUpperCase(Locale.ENGLISH) + logicalName.substring(1);
        if (trailingName != null) {
            className = className + trailingName;
        }
        return className;
    }

    /**
     * Return the class name for the given logical name. For example "person" would evaluate to "Person"
     *
     * @param logicalName The logical name
     * @return The class name
     */
    public static String getClassName(String logicalName) {
        return getClassName(logicalName, "");
    }

    /**
     * <p>Determines whether a given string is <code>null</code>, empty,
     * or only contains whitespace. If it contains anything other than
     * whitespace then the string is not considered to be blank and the
     * method returns <code>false</code>.</p>
     * <p>We could use Commons Lang for this, but we don't want GrailsNameUtils
     * to have a dependency on any external library to minimise the number of
     * dependencies required to bootstrap Grails.</p>
     * @param str The string to test.
     * @return <code>true</code> if the string is <code>null</code>, or
     * blank.
     */
    public static boolean isBlank(String str) {
        return str == null || str.trim().length() == 0;
    }
}

Related

  1. getClassesTree(Class clazz)
  2. getClassForDomain(String domain)
  3. getClassFQNString(Class clazz, StringBuilder sb)
  4. getClassHierarchyFrom(Class clazz)
  5. getClassHierarchyLeaf( Collection> classes)
  6. getClassNameRepresentation(String name)
  7. getClassNames( StackTraceElement[] currentStack)
  8. loadClass(Class context, String... names)
  9. loadClass(Class sourceClass, final String className)