Example usage for java.lang Character toLowerCase

List of usage examples for java.lang Character toLowerCase

Introduction

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

Prototype

public static int toLowerCase(int codePoint) 

Source Link

Document

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

Usage

From source file:ma.glasnost.orika.impl.util.StringUtil.java

/**
 * Remark: Copied from commons-lang3 v3.5
 *
 * <p>Uncapitalizes a String, changing the first character to lower case as per {@link
 * Character#toLowerCase(char)}. No other characters are changed.</p>
 *
 * <p>For a word based algorithm, see {@link org.apache.commons.lang3.text.WordUtils#uncapitalize(String)}.
 * A {@code null} input String returns {@code null}.</p>
 *
 * <pre>/*from w  w w  .ja  v  a 2  s  .co  m*/
 * StringUtils.uncapitalize(null)  = null
 * StringUtils.uncapitalize("")    = ""
 * StringUtils.uncapitalize("cat") = "cat"
 * StringUtils.uncapitalize("Cat") = "cat"
 * StringUtils.uncapitalize("CAT") = "cAT"
 * </pre>
 *
 * @param str the String to uncapitalize, may be null
 * @return the uncapitalized String, {@code null} if null String input
 * @see org.apache.commons.lang3.text.WordUtils#uncapitalize(String)
 * @see #capitalize(String)
 * @since 2.0
 */
public static String uncapitalize(final String str) {
    int strLen;
    if (str == null || (strLen = str.length()) == 0) {
        return str;
    }

    final char firstChar = str.charAt(0);
    final char newChar = Character.toLowerCase(firstChar);
    if (firstChar == newChar) {
        // already uncapitalized
        return str;
    }

    char[] newChars = new char[strLen];
    newChars[0] = newChar;
    str.getChars(1, strLen, newChars, 1);
    return String.valueOf(newChars);
}

From source file:com.thinkbiganalytics.feedmgr.rest.support.SystemNamingService.java

public static String generateSystemName(String name) {
    //first trim it
    String systemName = StringUtils.trimToEmpty(name);
    if (StringUtils.isBlank(systemName)) {
        return systemName;
    }//from   ww w .  j a v  a2s  . co m
    systemName = systemName.replaceAll(" +", "_");
    systemName = systemName.replaceAll("[^\\w_]", "");

    int i = 0;

    StringBuilder s = new StringBuilder();
    CharacterIterator itr = new StringCharacterIterator(systemName);
    for (char c = itr.first(); c != CharacterIterator.DONE; c = itr.next()) {
        if (Character.isUpperCase(c)) {
            //if it is upper, not at the start and not at the end check to see if i am surrounded by upper then lower it.
            if (i > 0 && i != systemName.length() - 1) {
                char prevChar = systemName.charAt(i - 1);
                char nextChar = systemName.charAt(i + 1);

                if (Character.isUpperCase(prevChar) && (Character.isUpperCase(nextChar)
                        || CharUtils.isAsciiNumeric(nextChar) || '_' == nextChar || '-' == nextChar)) {
                    char lowerChar = Character.toLowerCase(systemName.charAt(i));
                    s.append(lowerChar);
                } else {
                    s.append(c);
                }
            } else if (i > 0 && i == systemName.length() - 1) {
                char prevChar = systemName.charAt(i - 1);
                if (Character.isUpperCase(prevChar) && !CharUtils.isAsciiNumeric(systemName.charAt(i))) {
                    char lowerChar = Character.toLowerCase(systemName.charAt(i));
                    s.append(lowerChar);
                } else {
                    s.append(c);
                }
            } else {
                s.append(c);
            }
        } else {
            s.append(c);
        }

        i++;
    }

    systemName = s.toString();
    systemName = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, systemName);
    systemName = CaseFormat.LOWER_HYPHEN.to(CaseFormat.LOWER_UNDERSCORE, systemName);
    systemName = StringUtils.replace(systemName, "__", "_");
    // Truncate length if exceeds Hive limit
    systemName = (systemName.length() > 128 ? systemName.substring(0, 127) : systemName);
    return systemName;
}

From source file:io.wcm.handler.richtext.impl.DataPropertyUtil.java

/**
 * Converts a headless camel case property name to a HTML5 data attribute name including "data-" prefix.
 * @param headlessCamelCaseName Headless camel case name
 * @return HTML5 data attribute name//w  w  w .j  av  a2 s.  co  m
 * @throws IllegalArgumentException If parameter name is not valid
 */
public static String toHtml5DataName(String headlessCamelCaseName) {
    if (StringUtils.isEmpty(headlessCamelCaseName)) {
        throw new IllegalArgumentException("Property name is empty.");
    }
    if (!isHeadlessCamelCaseName(headlessCamelCaseName)) {
        throw new IllegalArgumentException(
                "This is not a valid headless camel case property name: " + headlessCamelCaseName);
    }

    StringBuilder html5DataName = new StringBuilder(HTML5_DATA_PREFIX);
    for (int i = 0; i < headlessCamelCaseName.length(); i++) {
        char c = headlessCamelCaseName.charAt(i);
        if (CharUtils.isAsciiAlphaUpper(c)) {
            html5DataName.append('-');
        }
        html5DataName.append(Character.toLowerCase(c));
    }

    return html5DataName.toString();
}

From source file:de.mirkosertic.desktopsearch.QueryTokenizer.java

QueryTokenizer(String aQuery) {

    requiredTerms = new ArrayList<>();
    notRequiredTerms = new ArrayList<>();

    boolean isFirstChar = true;
    boolean isNegated = false;
    StringBuilder theCurrentTerm = new StringBuilder();

    for (int i = 0; i < aQuery.length(); i++) {
        char theCurrentChar = Character.toLowerCase(aQuery.charAt(i));
        switch (theCurrentChar) {
        case '-': {
            if (isFirstChar) {
                isFirstChar = false;// w  w  w  .j  av a  2s.co  m
                isNegated = true;
            } else {
                theCurrentTerm.append(theCurrentChar);
            }
            break;
        }
        case '+':
            if (isFirstChar) {
                isNegated = false;
                isFirstChar = false;
            } else {
                theCurrentTerm.append(theCurrentChar);
            }
            break;
        case ' ': {
            if (isValid(theCurrentTerm.toString())) {
                if (isNegated) {
                    notRequiredTerms.add(theCurrentTerm.toString());
                } else {
                    requiredTerms.add(theCurrentTerm.toString());
                }
            }
            theCurrentTerm = new StringBuilder();
            isNegated = false;
            isFirstChar = true;
            break;
        }
        default: {
            theCurrentTerm.append(theCurrentChar);
            isFirstChar = false;
            break;
        }
        }
    }

    if (isValid(theCurrentTerm.toString())) {
        if (isNegated) {
            notRequiredTerms.add(theCurrentTerm.toString());
        } else {
            requiredTerms.add(theCurrentTerm.toString());
        }
    }
}

From source file:com.rabbitmq.examples.StressPersister.java

private static int sizeArg(CommandLine cmd, char opt, int def) {
    String arg = cmd.getOptionValue(opt, Integer.toString(def));
    int multiplier = 1;
    boolean strip = false;
    switch (Character.toLowerCase(arg.charAt(arg.length() - 1))) {
    case 'b':
        multiplier = 1;//from   w  w w. j a  v  a 2  s . c  om
        strip = true;
        break;
    case 'k':
        multiplier = 1024;
        strip = true;
        break;
    case 'm':
        multiplier = 1048576;
        strip = true;
        break;
    default:
        break;
    }
    if (strip) {
        arg = arg.substring(0, arg.length() - 1);
    }
    return multiplier * Integer.parseInt(arg);
}

From source file:org.lendingclub.mercator.aws.JsonConverter.java

private String getKey(String key) {
    if (Character.isUpperCase(key.charAt(0))) {
        return Character.toLowerCase(key.charAt(0)) + key.substring(1);
    }//from w ww.  j  a  v  a 2 s . co  m
    return key;
}

From source file:de.upb.wdqa.wdvd.features.FeatureImpl.java

@Override
public String getName() {
    // convert first character to lower case
    String result = this.getClass().getSimpleName();
    result = Character.toLowerCase(result.charAt(0)) + result.substring(1);
    return result;
}

From source file:com.adaptris.core.marshaller.xstream.XStreamUtils.java

/**
 * Converts a lowercase hyphen separated format into a camelcase based
 * format. Used by the unmarshalling process to convert an xml element into
 * a java class/field name./*  w w  w.  j a  v a2  s .co  m*/
 * 
 * @param xmlElementName
 *            - Current element name to be processed.
 * @return translated name
 */
public static String toFieldName(String xmlElementName) {
    if (xmlElementName == null) {
        return null;
    }
    if (xmlElementName.length() == 0) {
        return xmlElementName;
    }
    if (xmlElementName.length() == 1) {
        return xmlElementName.toLowerCase();
    }
    // -- Follow the Java beans Introspector::decapitalize
    // -- convention by leaving alone String that start with
    // -- 2 uppercase characters.
    if (Character.isUpperCase(xmlElementName.charAt(0)) && Character.isUpperCase(xmlElementName.charAt(1))) {
        return xmlElementName;
    }
    // -- process each character
    StringBuilder input = new StringBuilder(xmlElementName);
    StringBuilder output = new StringBuilder();
    output.append(Character.toLowerCase(input.charAt(0)));
    boolean multiHyphens = false;
    for (int i = 1; i < input.length(); i++) {
        char ch = input.charAt(i);
        if (ch == '-') {
            if (input.charAt(++i) != '-') {
                output.append(Character.toUpperCase(input.charAt(i)));
            } else {
                multiHyphens = true;
            }
        } else {
            if (multiHyphens) {
                output.append(Character.toUpperCase(ch));
            } else {
                output.append(ch);
            }
            multiHyphens = false;

        }
    }
    return output.toString();
}

From source file:com.bedatadriven.rebar.persistence.mapping.PropertyMapping.java

public PropertyMapping(MethodInfo getterMethod) {

    this.getterName = getterMethod.getName();
    this.type = getterMethod.getReturnType();

    int prefixLen = getterName.startsWith("is") ? 2 : 3;
    setterName = "set" + getterName.substring(prefixLen);
    name = Character.toLowerCase(getterName.charAt(prefixLen)) + getterName.substring(prefixLen + 1);
}

From source file:com.facebook.litho.ComponentsStethoManagerImpl.java

private static String toCSSString(String str) {
    final StringBuilder builder = new StringBuilder(str.length());
    builder.append(str);//from  w w w . j a  va2  s  . c o  m
    for (int i = 0, length = builder.length(); i < length; ++i) {
        final char oldChar = builder.charAt(i);
        final char lowerChar = Character.toLowerCase(oldChar);
        final char newChar = lowerChar == '_' ? '-' : lowerChar;
        builder.setCharAt(i, newChar);
    }
    return builder.toString();
}