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:Main.java

/**
 * <p>Capitalizes a String changing the first letter to title case as
 * per {@link Character#toTitleCase(char)}. No other letters are changed.</p>
 *
 * <p>For a word based algorithm, see {@link WordUtils#capitalize(String)}.
 * A <code>null</code> input String returns <code>null</code>.</p>
 *
 * <pre>/*from   www. j a va2  s .c  o  m*/
 * StringUtils.capitalize(null)  = null
 * StringUtils.capitalize("")    = ""
 * StringUtils.capitalize("cat") = "Cat"
 * StringUtils.capitalize("cAt") = "CAt"
 * </pre>
 *
 * @param str  the String to capitalize, may be null
 * @return the capitalized String, <code>null</code> if null String input
 * @see WordUtils#capitalize(String)
 * @see #uncapitalize(String)
 * @since 2.0
 */
public static String capitalize(String str) {
    int strLen;
    if (str == null || (strLen = str.length()) == 0) {
        return str;
    }
    return new StringBuffer(strLen).append(Character.toTitleCase(str.charAt(0))).append(str.substring(1))
            .toString();
}

From source file:Main.java

/**
 * <p>/*ww w  . j ava  2s.  c  o m*/
 * Swaps the case of String.
 * </p>
 * <p/>
 * <p>
 * Properly looks after making sure the start of words are Titlecase and not Uppercase.
 * </p>
 * <p/>
 * <p>
 * <code>null</code> is returned as <code>null</code>.
 * </p>
 *
 * @param str the String to swap the case of
 * @return the modified String
 */
public static String swapCase(String str) {
    if (str == null) {
        return null;
    }
    int sz = str.length();
    StringBuilder buffer = new StringBuilder(sz);

    boolean whitespace = false;
    char ch;
    char tmp;

    for (int i = 0; i < sz; i++) {
        ch = str.charAt(i);
        if (Character.isUpperCase(ch)) {
            tmp = Character.toLowerCase(ch);
        } else if (Character.isTitleCase(ch)) {
            tmp = Character.toLowerCase(ch);
        } else if (Character.isLowerCase(ch)) {
            if (whitespace) {
                tmp = Character.toTitleCase(ch);
            } else {
                tmp = Character.toUpperCase(ch);
            }
        } else {
            tmp = ch;
        }
        buffer.append(tmp);
        whitespace = Character.isWhitespace(ch);
    }
    return buffer.toString();
}

From source file:org.betaconceptframework.astroboa.security.management.CmsPerson.java

@Override
public String getDisplayName() {

    if (displayName == null) {
        //Create one from first last and father name
        StringBuilder displayNameBuilder = new StringBuilder();

        if (StringUtils.isNotBlank(firstName)) {
            displayNameBuilder.append(firstName);
        }/*from w  ww. j av a 2  s . c o  m*/

        if (StringUtils.isNotBlank(fatherName)) {
            displayNameBuilder.append(" ");
            displayNameBuilder.append(Character.toTitleCase(fatherName.charAt(0)));
        }

        if (StringUtils.isNotBlank(familyName)) {
            displayNameBuilder.append(" ");
            displayNameBuilder.append(familyName);
        }

        displayName = displayNameBuilder.toString();
    }

    return displayName;
}

From source file:org.gradle.language.base.internal.DefaultBinaryNamingScheme.java

private void appendCapitalized(StringBuilder builder, String word) {
    builder.append(Character.toTitleCase(word.charAt(0))).append(word.substring(1));
}

From source file:org.eclipse.smarthome.binding.astro.internal.util.PropertyUtils.java

/**
 * Converts the string to a getter property.
 *//*from   w  ww  . ja  v a2  s.  c o  m*/
private static String toGetterString(String str) {
    StringBuilder sb = new StringBuilder();
    sb.append("get");
    sb.append(Character.toTitleCase(str.charAt(0)));
    sb.append(str.substring(1));
    return sb.toString();
}

From source file:com.bukanir.android.utils.Utils.java

public static String toTitleCase(String input) {
    StringBuilder titleCase = new StringBuilder();
    boolean nextTitleCase = true;
    for (char c : input.toCharArray()) {
        if (Character.isSpaceChar(c)) {
            nextTitleCase = true;/*from   w ww  .j  a  v a 2 s  . c om*/
        } else if (nextTitleCase) {
            c = Character.toTitleCase(c);
            nextTitleCase = false;
        }
        titleCase.append(c);
    }
    return titleCase.toString();
}

From source file:pawl.jbehave.GenerateJUnitStoriesMojo.java

/**
 * Convert file name to class name.//from w  ww .  j  a  v a 2 s .c o m
 *
 * @param name of file
 * @return class name
 */
public String getClassNameFrom(final String name) {
    int extensionIndex = name.lastIndexOf('.');
    String nameWithOutExtension = name.substring(0, extensionIndex);
    String[] words = nameWithOutExtension.split("_");
    StringBuilder builder = new StringBuilder();
    for (String word : words) {
        builder.append(Character.toTitleCase(word.charAt(0))).append(word.substring(1));
    }
    return builder.toString();
}

From source file:net.community.chest.gitcloud.facade.ServletUtils.java

public static final String capitalizeHttpHeaderName(String hdrName) {
    if (StringUtils.isEmpty(hdrName)) {
        return hdrName;
    }//from www. j a va2s . co  m

    int curPos = hdrName.indexOf('-');
    if (curPos < 0) {
        return ExtendedCharSequenceUtils.capitalize(hdrName);
    }

    StringBuilder sb = null;
    for (int lastPos = 0;;) {
        char ch = hdrName.charAt(lastPos), tch = Character.toTitleCase(ch);
        if (ch != tch) {
            if (sb == null) {
                sb = new StringBuilder(hdrName.length());
                // append the data that was OK
                if (lastPos > 0) {
                    sb.append(hdrName.substring(0, lastPos));
                }
            }

            sb.append(tch);

            if (curPos > lastPos) {
                sb.append(hdrName.substring(lastPos + 1 /* excluding the capital letter */,
                        curPos + 1 /* including the '-' */));
            } else { // last component in string
                sb.append(hdrName.substring(lastPos + 1 /* excluding the capital letter */));
            }
        }

        if (curPos < lastPos) {
            break;
        }

        if ((lastPos = curPos + 1) >= hdrName.length()) {
            break;
        }

        curPos = hdrName.indexOf('-', lastPos);
    }

    if (sb == null) { // There was no need to modify anything
        return hdrName;
    } else {
        return sb.toString();
    }
}

From source file:ubic.gemma.web.remote.CharacteristicConverter.java

@SuppressWarnings("unchecked")
@Override//from   w ww .jav  a 2  s. co  m
public Object convertInbound(Class paramType, InboundVariable iv, InboundContext inctx)
        throws MarshallException {
    String value = iv.getValue();

    // If the text is null then the whole bean is null
    if (value.trim().equals(ProtocolConstants.INBOUND_NULL)) {
        return null;
    }

    if (!value.startsWith(ProtocolConstants.INBOUND_MAP_START)) {
        throw new MarshallException(paramType,
                Messages.getString("BeanConverter.FormatError", ProtocolConstants.INBOUND_MAP_START));
    }

    if (!value.endsWith(ProtocolConstants.INBOUND_MAP_END)) {
        throw new MarshallException(paramType,
                Messages.getString("BeanConverter.FormatError", ProtocolConstants.INBOUND_MAP_START));
    }

    value = value.substring(1, value.length() - 1);

    try {
        Map<String, String> tokens = extractInboundTokens(paramType, value);

        Object bean;
        if (instanceType != null) {

            log.info(instanceType);

            if (tokens.containsKey("valueUri"))
                bean = VocabCharacteristic.Factory.newInstance();
            else
                bean = Characteristic.Factory.newInstance();

            inctx.addConverted(iv, instanceType, bean);
        } else {
            if (tokens.containsKey("valueUri"))
                bean = ubic.gemma.model.common.description.VocabCharacteristic.Factory.newInstance();
            else
                bean = ubic.gemma.model.common.description.Characteristic.Factory.newInstance();

            inctx.addConverted(iv, paramType, bean);
        }

        Map<String, Property> properties = getPropertyMapFromObject(bean, false, true);

        // Loop through the properties passed in

        for (Iterator<Entry<String, String>> it = tokens.entrySet().iterator(); it.hasNext();) {
            Map.Entry<String, String> entry = it.next();
            String key = entry.getKey();
            String val = entry.getValue();

            Property property = properties.get(key);
            if (property == null) {
                log.warn("Missing java bean property to match javascript property: " + key
                        + ". For causes see debug level logs:");

                log.debug("- The javascript may be refer to a property that does not exist");
                log.debug("- You may be missing the correct setter: set" + Character.toTitleCase(key.charAt(0))
                        + key.substring(1) + "()");
                log.debug("- The property may be excluded using include or exclude rules.");

                StringBuffer all = new StringBuffer();
                for (Iterator<String> pit = properties.keySet().iterator(); pit.hasNext();) {
                    all.append(pit.next());
                    if (pit.hasNext()) {
                        all.append(',');
                    }
                }
                log.debug("Fields exist for (" + all + ").");
                continue;
            }

            Class<?> propType = property.getPropertyType();

            String[] split = ParseUtil.splitInbound(val);
            String splitValue = split[LocalUtil.INBOUND_INDEX_VALUE];
            String splitType = split[LocalUtil.INBOUND_INDEX_TYPE];

            InboundVariable nested = new InboundVariable(iv.getLookup(), null, splitType, splitValue);
            TypeHintContext incc = createTypeHintContext(inctx, property);

            Object output = converterManager.convertInbound(propType, nested, inctx, incc);

            // TODO: Total hack. Change the properties association to be a SET instead of a Collection in the model
            // Model think this is a collection, hibernate thinks its a set. DWR converts collections to
            // ArrayLists... *sigh* Hibernate then dies of a class cast exception. All because of a general type of
            // Collection
            if ((key.equals("properties")) && (output instanceof ArrayList)) {
                ArrayList<Object> propertyList = (ArrayList<Object>) output;
                output = new HashSet<Object>(propertyList);
            }

            property.setValue(bean, output);
        }

        return bean;
    } catch (MarshallException ex) {
        throw ex;
    } catch (Exception ex) {
        throw new MarshallException(paramType, ex);
    }
}

From source file:org.opentestsystem.delivery.testreg.domain.MasterResourceAccommodation.java

@JsonProperty
public void setResourceType(final String resourceType) {
    if (isNotEmpty(resourceType)) {
        this.resourceType = Character.toTitleCase(resourceType.charAt(0))
                + resourceType.substring(1).toLowerCase();
    } else {/*from   w ww  .j a  v  a2s  .c  om*/

        this.resourceType = resourceType;
    }
}