Example usage for java.lang Character isUpperCase

List of usage examples for java.lang Character isUpperCase

Introduction

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

Prototype

public static boolean isUpperCase(int codePoint) 

Source Link

Document

Determines if the specified character (Unicode code point) is an uppercase character.

Usage

From source file:com.urbancode.x2o.xml.XmlWrite.java

public String convertFromCamelCase(String toConvert) {
    String result = toConvert;//from ww  w.  j  a va2s.  co  m
    StringBuilder builder = new StringBuilder();

    for (int i = 0; i < result.length(); i++) {
        if (Character.isUpperCase(result.charAt(i)) && i != 0) {
            builder.append("-");
        }
        builder.append(result.charAt(i));
    }
    result = builder.toString().toLowerCase();

    return result;
}

From source file:jp.co.ctc_g.jfw.core.util.Beans.java

/**
 * ???????/*from   w  w  w .j  a  v  a 2s .c o m*/
 * ???{@link Strings#isEmpty(CharSequence) }???
 * ????????????
 * @param capitalizee ??
 * @return ?????
 */
public static String capitalize(String capitalizee) {
    if (Strings.isEmpty(capitalizee))
        return capitalizee;
    if (capitalizee.length() > 1) {
        if (Character.isUpperCase(capitalizee.charAt(1))) {
            return capitalizee;
        } else {
            return new StringBuilder().append(capitalizee.substring(0, 1).toUpperCase())
                    .append(capitalizee.substring(1, capitalizee.length())).toString();
        }
    } else {
        return capitalizee.toUpperCase();
    }
}

From source file:com.manydesigns.elements.util.Util.java

public static String camelCaseToWords(String s) {
    if (s == null) {
        return null;
    }//from   ww  w.  j a v a2s.co  m
    StringBuilder sb = new StringBuilder();
    boolean first = true;
    for (int i = 0; i < s.length(); i++) {
        char c = s.charAt(i);
        if (first) {
            first = false;
            sb.append(c);
        } else {
            if (Character.isUpperCase(c)) {
                sb.append(' ');
                sb.append(Character.toLowerCase(c));
            } else {
                sb.append(c);
            }
        }
    }
    return sb.toString();
}

From source file:org.executequery.gui.text.TextUtilities.java

public static void changeSelectionToUnderscore(JTextComponent textComponent) {

    String selectedText = textComponent.getSelectedText();
    if (StringUtils.isBlank(selectedText)) {

        return;/* w w  w.j  a v  a 2 s .c o  m*/
    }

    String breakChars = "-_ \t";

    boolean lastCharWasUnderscore = false;
    StringBuilder sb = new StringBuilder();
    char[] chars = selectedText.toCharArray();
    for (int i = 0; i < chars.length; i++) {

        char _char = chars[i];
        if (breakChars.indexOf(_char) != -1) {

            sb.append("_");
            lastCharWasUnderscore = true;

        } else if (Character.isUpperCase(_char)) {

            if (!lastCharWasUnderscore) {

                sb.append("_");
            }
            sb.append(_char);
            lastCharWasUnderscore = false;

        } else {

            sb.append(_char);
            lastCharWasUnderscore = false;
        }

    }

    textComponent.replaceSelection(sb.toString().toLowerCase());
}

From source file:com.wavemaker.common.util.StringUtils.java

public static boolean hasUpperCase(String s) {
    for (int i = 0; i < s.length(); i++) {
        char c = s.charAt(i);
        if (Character.isUpperCase(c)) {
            return true;
        }//from w  w  w  .j  av a  2  s. co m
    }
    return false;
}

From source file:org.languagetool.rules.uk.MissingHyphenRule.java

@Override
public RuleMatch[] match(AnalyzedSentence sentence) throws IOException {
    List<RuleMatch> ruleMatches = new ArrayList<>();
    AnalyzedTokenReadings[] tokens = sentence.getTokensWithoutWhitespace();

    for (int i = 1; i < tokens.length - 1; i++) {
        AnalyzedTokenReadings tokenReadings = tokens[i];
        AnalyzedTokenReadings nextTokenReadings = tokens[i + 1];

        boolean isCapitalized = Character.isUpperCase(tokenReadings.getToken().charAt(0));

        if ((isInPrefixes(tokenReadings, isCapitalized)
                || (tokenReadings.getToken().toLowerCase().equals("")
                        && LemmaHelper.hasLemma(tokens[i + 1], "")))
                && PosTagHelper.hasPosTagPart(nextTokenReadings, "noun")
                //          && ! PosTagHelper.hasPosTag(nextTokenReadings, Pattern.compile("^(?!noun).*"))
                && ALL_LOWER.matcher(nextTokenReadings.getToken()).matches()) {

            String hyphenedWord = tokenReadings.getToken() + "-" + nextTokenReadings.getToken();
            String tokenToCheck = isCapitalized ? StringUtils.uncapitalize(hyphenedWord) : hyphenedWord;

            if (wordTagger.tag(tokenToCheck).size() > 0) {
                RuleMatch potentialRuleMatch = new RuleMatch(this, sentence, tokenReadings.getStartPos(),
                        nextTokenReadings.getEndPos(), ",  ??",
                        getDescription());
                potentialRuleMatch.setSuggestedReplacement(hyphenedWord);

                ruleMatches.add(potentialRuleMatch);
            }/*from   w  ww  . j a  v a2s  .  co  m*/
        }

    }

    return ruleMatches.toArray(new RuleMatch[0]);
}

From source file:ch.algotrader.esper.SpringServiceResolver.java

String adjust(final String s) {
    for (int i = 0; i < s.length(); i++) {
        char ch = s.charAt(i);
        if (!Character.isUpperCase(ch)) {
            return s;
        }/* w  w  w  .ja  v  a 2 s  .com*/
    }
    return s.toLowerCase(Locale.ROOT);
}

From source file:org.gradle.model.internal.manage.schema.ModelSchemaExtractor.java

public <T> ModelSchema<T> extract(Class<T> type) throws InvalidManagedModelElementTypeException {
    validateType(type);/*from w  ww . ja v  a2s .c om*/

    List<Method> methodList = Arrays.asList(type.getDeclaredMethods());
    if (methodList.isEmpty()) {
        return new ModelSchema<T>(type, Collections.<ModelProperty<?>>emptyList());
    }

    List<ModelProperty<?>> properties = Lists.newLinkedList();

    Map<String, Method> methods = Maps.newHashMap();
    for (Method method : methodList) {
        String name = method.getName();
        if (methods.containsKey(name)) {
            throw invalidMethod(type, name, "overloaded methods are not supported");
        }
        methods.put(name, method);
    }

    List<String> methodNames = Lists.newLinkedList(methods.keySet());
    List<String> handled = Lists.newArrayList();

    for (ListIterator<String> iterator = methodNames.listIterator(); iterator.hasNext();) {
        String methodName = iterator.next();

        Method method = methods.get(methodName);
        if (methodName.startsWith("get") && !methodName.equals("get")) {
            if (method.getParameterTypes().length != 0) {
                throw invalidMethod(type, methodName, "getter methods cannot take parameters");
            }

            Class<?> returnType = method.getReturnType();
            if (!returnType.equals(String.class)) {
                throw invalidMethod(type, methodName, "only String properties are supported");
            }

            // hardcoded for now
            ModelType<String> propertyType = ModelType.of(String.class);

            Character getterPropertyNameFirstChar = methodName.charAt(3);
            if (!Character.isUpperCase(getterPropertyNameFirstChar)) {
                throw invalidMethod(type, methodName,
                        "the 4th character of the getter method name must be an uppercase character");
            }

            String propertyNameCapitalized = methodName.substring(3);
            String propertyName = StringUtils.uncapitalize(propertyNameCapitalized);
            String setterName = "set" + propertyNameCapitalized;

            if (!methods.containsKey(setterName)) {
                throw invalidMethod(type, methodName, "no corresponding setter for getter");
            }

            Method setter = methods.get(setterName);
            handled.add(setterName);

            if (!setter.getReturnType().equals(void.class)) {
                throw invalidMethod(type, setterName, "setter method must have void return type");
            }

            Type[] setterParameterTypes = setter.getGenericParameterTypes();
            if (setterParameterTypes.length != 1) {
                throw invalidMethod(type, setterName, "setter method must have exactly one parameter");
            }

            ModelType<?> setterType = ModelType.of(setterParameterTypes[0]);
            if (!setterType.equals(propertyType)) {
                throw invalidMethod(type, setterName,
                        "setter method param must be of exactly the same type as the getter returns (expected: "
                                + propertyType + ", found: " + setterType + ")");
            }

            properties.add(new ModelProperty<String>(propertyName, propertyType));
            iterator.remove();
        }
    }

    methodNames.removeAll(handled);

    // TODO - should call out valid getters without setters
    if (!methodNames.isEmpty()) {
        throw invalid(type, "only paired getter/setter methods are supported (invalid methods: ["
                + Joiner.on(", ").join(methodNames) + "])");
    }

    return new ModelSchema<T>(type, properties);
}

From source file:org.eclipse.wb.internal.core.utils.StringUtilities.java

/**
 * Extract camel caps from specified string.
 * // w  w  w . ja v  a2s . co m
 * <pre>
 * Example: NullPointException --> NPE
 * 
 * <pre>
 */
public static String extractCamelCaps(String string) {
    if (string == null) {
        return null;
    }
    StringBuffer buf = new StringBuffer(string.length());
    int length = string.length();
    for (int i = 0; i < length; i++) {
        char ch = string.charAt(i);
        if (Character.isUpperCase(ch)) {
            buf.append(ch);
        }
    }
    return buf.toString();
}

From source file:org.ourbeehive.mbp.util.JavaFormatter.java

public static String getDbStyle(String javaPhrase) {

    // The return value.
    StringBuffer javaWord = new StringBuffer();
    StringBuffer dbPhrase = new StringBuffer();
    String dbWord = null;// w  w  w.ja  v a  2 s  .c o m

    // Get "javaNameToDbName" cache from ctxCache.
    // Hashtable<String, String> javaNameToDbNameCache = CtxCacheFacade.getJavaNameToDbNameCache();

    int len = javaPhrase.length();
    char c = 0;
    for (int i = 0; i < len; i++) {

        c = javaPhrase.charAt(i);

        // Java Bean????"_"
        if (String.valueOf(c).equals(MapperElm.UNDER_LINE) == true) {
            continue;
        }

        if (Character.isLowerCase(c) == true || Character.isDigit(c) == true) {
            javaWord.append(c);
            if (i < len - 1) {
                continue;
            }
        }

        if (javaWord.length() != 0) {

            // Find corresponding dbWord with previous javaWord.
            // dbWord = javaNameToDbNameCache.get(javaWord.toString().toLowerCase());
            dbWord = javaWord.toString().toUpperCase();
            // if (dbWord != null) {
            if (dbPhrase.length() != 0) {
                dbPhrase.append(MapperElm.UNDER_LINE);
            }
            dbPhrase.append(dbWord);
        }

        // else {
        // // No need to look up others.
        // logger.warn("NO DB WORD: Fail to find corresponding DB word for " + "Java word '" + javaWord + "' in Java phrase '" + javaPhrase
        // + "'");
        // return null;
        // }

        // Begin a new javaWord.
        javaWord.delete(0, javaWord.length());
        if (Character.isUpperCase(c) == true) {
            javaWord.append(c);
        }

    }

    // javaWord.append(c);

    // Processing the last javaWord.
    // if (javaWord.length() != 0) {
    //
    // // Find corresponding dbWord with the last javaWord.
    // dbWord = fullNameToAbbrCache.get(javaWord.toString().toLowerCase());
    // if (dbWord != null) {
    // if (dbPhrase.length() != 0) {
    // dbPhrase.append(MapperElm.UNDER_LINE);
    // }
    // dbPhrase.append(dbWord);
    // } else {
    // // No need to look up others.
    // logger.warn("NO DB WORD: Fail to find corresponding DB word for " + "Java word '" + javaWord + "' in Java phrase '" + javaPhrase
    // + "'");
    // return null;
    // }
    // }

    return dbPhrase.toString();

}