Example usage for java.lang Character toTitleCase

List of usage examples for java.lang Character toTitleCase

Introduction

In this page you can find the example usage for java.lang Character toTitleCase.

Prototype

public static int toTitleCase(int codePoint) 

Source Link

Document

Converts the character (Unicode code point) argument to titlecase using case mapping information from the UnicodeData file.

Usage

From source file:org.squale.squalecommon.util.mapping.Mapping.java

/**
 * Obtention du getter d'une mtrique La mthode est recherche dans la classe correspondante, la mthode est du
 * type getXxxx/*from ww w .j  av  a2  s.  c o  m*/
 * 
 * @param pMetric mtrique (par exemple mccabe.class.dit)
 * @return mthode d'accs  cette mtrique (par exemple McCabeQAClassMetricsBO.getDit)
 * @throws IllegalArgumentException si pMetric mal form
 */
public static Method getMetricGetter(String pMetric) throws IllegalArgumentException {
    Method result = null;
    int index = pMetric.lastIndexOf('.');
    if (index < 0) {
        throw new IllegalArgumentException("Metric name should be named tool.component.name");
    }
    String measure = pMetric.substring(0, index);
    String metric = pMetric.substring(index + 1);
    // Obtention de la classe
    Class cl = getMeasureClass(measure);
    // Un log d'erreur aura t fait par la mthode
    // auparavant, inutile d'engorger le log
    if (cl != null) {
        try {
            // On forme le nom du getter
            StringBuffer methodName = new StringBuffer(metric);
            // Respect de la norme javabean pour le caractre en majuscules
            methodName.setCharAt(0, Character.toTitleCase(methodName.charAt(0)));
            methodName.insert(0, "get");
            result = cl.getMethod(methodName.toString(), null);
        } catch (SecurityException e) {
            LOG.error("Getter not found " + pMetric, e);
        } catch (NoSuchMethodException e) {
            LOG.error("Getter not found " + pMetric, e);
        }
    }
    return result;
}

From source file:com.venkatesan.das.cardmanager.OCRCaptureActivity.java

private String toTitleCase(String str) {

    if (str == null) {
        return null;
    }/*  w  w w  . j  a v  a  2  s  .  c  om*/

    boolean space = true;
    StringBuilder builder = new StringBuilder(str);
    final int len = builder.length();

    for (int i = 0; i < len; ++i) {
        char c = builder.charAt(i);
        if (space) {
            if (!Character.isWhitespace(c)) {
                // Convert to title case and switch out of whitespace mode.
                builder.setCharAt(i, Character.toTitleCase(c));
                space = false;
            }
        } else if (Character.isWhitespace(c)) {
            space = true;
        } else {
            builder.setCharAt(i, Character.toLowerCase(c));
        }
    }

    return builder.toString();
}

From source file:de.homelab.madgaksha.lotsofbs.util.LocaleRootWordUtils.java

/**
 * <p>/*from   ww w  . ja  va2s.  c  o  m*/
 * Swaps the case of a String using a word based algorithm.
 * </p>
 * 
 * <ul>
 * <li>Upper case character converts to Lower case</li>
 * <li>Title case character converts to Lower case</li>
 * <li>Lower case character after Whitespace or at start converts to Title
 * case</li>
 * <li>Other Lower case character converts to Upper case</li>
 * </ul>
 * 
 * <p>
 * Whitespace is defined by {@link Character#isWhitespace(char)}. A
 * <code>null</code> input String returns <code>null</code>.
 * </p>
 * 
 * <pre>
 * StringUtils.swapCase(null)                 = null
 * StringUtils.swapCase("")                   = ""
 * StringUtils.swapCase("The dog has a BONE") = "tHE DOG HAS A bone"
 * </pre>
 * 
 * @param str
 *            the String to swap case, may be null
 * @return the changed String, <code>null</code> if null String input
 */
public static String swapCase(final String str) {
    if (StringUtils.isEmpty(str)) {
        return str;
    }
    final char[] buffer = str.toCharArray();

    boolean whitespace = true;

    for (int i = 0; i < buffer.length; i++) {
        final char ch = buffer[i];
        if (Character.isUpperCase(ch)) {
            buffer[i] = Character.toLowerCase(ch);
            whitespace = false;
        } else if (Character.isTitleCase(ch)) {
            buffer[i] = Character.toLowerCase(ch);
            whitespace = false;
        } else if (Character.isLowerCase(ch)) {
            if (whitespace) {
                buffer[i] = Character.toTitleCase(ch);
                whitespace = false;
            } else {
                buffer[i] = Character.toUpperCase(ch);
            }
        } else {
            whitespace = Character.isWhitespace(ch);
        }
    }
    return new String(buffer);
}

From source file:org.kuali.rice.ken.service.impl.NotificationMessageContentServiceImpl.java

/**
 * This method validates the content of a notification message by matching up the namespace of the expected content type
 * to the actual namespace that is passed in as part of the XML message.
 *
 * This is possibly redundant because we are using qualified XPath expressions to obtain content under the correct namespace.
 *
 * @param notification// ww  w .j ava2s.  c  om
 * @param contentType
 * @param contentElement
 * @param content
 * @throws IOException
 * @throws XmlException
 */
private void validateContent(NotificationBo notification, String contentType, Element contentElement,
        String content) throws IOException, XmlException {
    // this debugging relies on a DOM 3 API that is only available with Xerces 2.7.1+ (TypeInfo)
    // commented out for now
    /*LOG.debug(contentElement.getSchemaTypeInfo());
    LOG.debug(contentElement.getSchemaTypeInfo().getTypeName());
    LOG.debug(contentElement.getSchemaTypeInfo().getTypeNamespace());
    LOG.debug(contentElement.getNamespaceURI());
    LOG.debug(contentElement.getLocalName());
    LOG.debug(contentElement.getNodeName());*/

    String contentTypeTitleCase = Character.toTitleCase(contentType.charAt(0)) + contentType.substring(1);
    String expectedNamespaceURI = CONTENT_TYPE_NAMESPACE_PREFIX + contentTypeTitleCase;
    String actualNamespaceURI = contentElement.getNamespaceURI();
    if (!actualNamespaceURI.equals(expectedNamespaceURI)) {
        throw new XmlException("Namespace URI of 'content' node, '" + actualNamespaceURI
                + "', does not match expected namespace URI, '" + expectedNamespaceURI + "', for content type '"
                + contentType + "'");
    }
}

From source file:fr.ribesg.bukkit.api.chat.Chat.java

/**
 * Gets the String identifier of an {@link Achievement} that the client
 * can understand./*from  w w w  .  jav  a  2  s  . c  o m*/
 *
 * @param achievement the achievement
 *
 * @return the achievement's identifier
 */
private static String getAchievementId(final Achievement achievement) {
    switch (achievement) {
    case BUILD_WORKBENCH:
        return "buildWorkBench";
    case GET_DIAMONDS:
        return "diamonds";
    case NETHER_PORTAL:
        return "portal";
    case GHAST_RETURN:
        return "ghast";
    case GET_BLAZE_ROD:
        return "blazeRod";
    case BREW_POTION:
        return "potion";
    case END_PORTAL:
        return "theEnd";
    case THE_END:
        return "theEnd2";
    default:
        final char[] chars = achievement.name().toLowerCase().toCharArray();
        for (int i = 0; i < chars.length - 1; i++) {
            if (chars[i] == '_') {
                i++;
                chars[i] = Character.toTitleCase(chars[i]);
            }
        }
        final String result = new String(chars);
        return "achievement." + result.replace("_", "");
    }
}

From source file:org.ballerinalang.composer.service.workspace.swagger.SwaggerConverterUtils.java

public static String capitalize(String str) {
    int strLen;//from  w w w  .  j a v  a 2s .c  om
    if (str != null && (strLen = str.length()) != 0) {
        char firstChar = str.charAt(0);
        return Character.isTitleCase(firstChar) ? str
                : (new StringBuilder(strLen)).append(Character.toTitleCase(firstChar)).append(str.substring(1))
                        .toString();
    } else {
        return str;
    }
}

From source file:org.evosuite.junit.naming.variables.ExplanatoryNamingTestVisitor.java

/**
 * Make first letter upper case/*from w  ww.ja  v a 2s .  co  m*/
 *
 * @param input
 * @return
 */
private static String capitalize(String input) {
    final char[] buffer = input.toCharArray();
    buffer[0] = Character.toTitleCase(buffer[0]);
    return new String(buffer);
}

From source file:com.caved_in.commons.utilities.StringUtil.java

public static String titleCase(String str) {
    StringBuilder ret = new StringBuilder();
    boolean st = true;
    for (char c : str.toLowerCase().toCharArray()) {
        if (st) {
            ret.append(Character.toTitleCase(c));
        } else {/*www  .jav a2  s  .c  o  m*/
            ret.append(c);
        }
        st = c == ' ';
    }
    return ret.toString();
}

From source file:org.apache.hadoop.util.StringUtils.java

/**
 * Capitalize a word//from   w  w w  .  j  av  a  2 s. co  m
 *
 * @param s the input string
 * @return capitalized string
 */
public static String capitalize(String s) {
    int len = s.length();
    if (len == 0)
        return s;
    return new StringBuilder(len).append(Character.toTitleCase(s.charAt(0))).append(s.substring(1)).toString();
}

From source file:com.glaf.core.util.ReflectUtils.java

/**
 * Returns the setter-method for the given field name or null if no setter
 * exists./*from w  ww  .j  av  a2  s.  c  o m*/
 */
public static Method getSetter(String fieldName, Class<?> clazz, Class<?> fieldType) {
    String setterName = "set" + Character.toTitleCase(fieldName.charAt(0))
            + fieldName.substring(1, fieldName.length());
    try {
        // Using getMathods(), getMathod(...) expects exact parameter type
        // matching and ignores inheritance-tree.
        Method[] methods = clazz.getMethods();
        for (Method method : methods) {
            if (method.getName().equals(setterName)) {
                Class<?>[] paramTypes = method.getParameterTypes();
                if (paramTypes != null && paramTypes.length == 1 && paramTypes[0].isAssignableFrom(fieldType)) {
                    return method;
                }
            }
        }
        return null;
    } catch (SecurityException e) {
        throw new RuntimeException(
                "Not allowed to access method " + setterName + " on class " + clazz.getCanonicalName());
    }
}