Java String Camel Case To camelCaseToPretty(String camelCase)

Here you can find the source of camelCaseToPretty(String camelCase)

Description

camel Case To Pretty

License

Creative Commons License

Declaration

public static String camelCaseToPretty(String camelCase) 

Method Source Code

//package com.java2s;
/*/*from  www .  j  a v a  2 s. c om*/
 * This software is in the public domain under CC0 1.0 Universal plus a
 * Grant of Patent License.
 *
 * To the extent possible under law, the author(s) have dedicated all
 * copyright and related and neighboring rights to this software to the
 * public domain worldwide. This software is distributed without any
 * warranty.
 *
 * You should have received a copy of the CC0 Public Domain Dedication
 * along with this software (see the LICENSE.md file). If not, see
 * <http://creativecommons.org/publicdomain/zero/1.0/>.
 */

public class Main {
    public static String camelCaseToPretty(String camelCase) {
        if (camelCase == null || camelCase.length() == 0)
            return "";
        StringBuilder prettyName = new StringBuilder();
        String lastPart = null;
        for (String part : camelCase.split("(?=[A-Z0-9\\.#])")) {
            if (part.length() == 0)
                continue;
            char firstChar = part.charAt(0);
            if (firstChar == '.' || firstChar == '#') {
                if (part.length() == 1)
                    continue;
                part = part.substring(1);
                firstChar = part.charAt(0);
            }
            if (Character.isLowerCase(firstChar))
                part = Character.toUpperCase(firstChar) + part.substring(1);
            if (part.equalsIgnoreCase("id"))
                part = "ID";

            if (part.equals(lastPart))
                continue;
            lastPart = part;
            if (prettyName.length() > 0)
                prettyName.append(" ");
            prettyName.append(part);
        }
        return prettyName.toString();
    }
}

Related

  1. camelCaseToDotNotation(String string)
  2. camelCaseToEnum(String camelCase)
  3. camelCaseToEnum(String name)
  4. camelCaseToHuman(String input)
  5. camelCaseToPhrase(String camelCase)
  6. camelCaseToSeparatedWords(String ccString, String separator)
  7. camelCaseToSeparatorCase(String s, String separator)
  8. camelCaseToSpacedString(String camel)
  9. camelcaseToUppercase(String camelCase)