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:org.languagetool.rules.uk.TokenAgreementRule.java

@Override
public final RuleMatch[] match(final AnalyzedSentence text) {
    List<RuleMatch> ruleMatches = new ArrayList<>();
    AnalyzedTokenReadings[] tokens = text.getTokensWithoutWhitespace();
    boolean insideMultiword = false;

    AnalyzedTokenReadings reqTokenReadings = null;
    for (int i = 0; i < tokens.length; i++) {
        AnalyzedTokenReadings tokenReadings = tokens[i];

        String posTag = tokenReadings.getAnalyzedToken(0).getPOSTag();

        //TODO: skip conj . 

        if (posTag == null || posTag.contains(IPOSTag.unknown.getText())
                || posTag.equals(JLanguageTool.SENTENCE_START_TAGNAME)) {
            reqTokenReadings = null;//from   w w w  . j a v a2s.c om
            continue;
        }

        // first token is always SENT_START
        String thisToken = tokenReadings.getToken();
        if (i > 1 && thisToken.length() == 1 && Character.isUpperCase(thisToken.charAt(0))
                && tokenReadings.isWhitespaceBefore() && !tokens[i - 1].getToken().matches("[:-]")) { // ?  .  ? .:  
            reqTokenReadings = null;
            continue;
        }

        AnalyzedToken multiwordReqToken = getMultiwordToken(tokenReadings);
        if (multiwordReqToken != null) {
            String mwPosTag = multiwordReqToken.getPOSTag();
            if (mwPosTag.startsWith("</")) {
                insideMultiword = false;
            } else {
                insideMultiword = true;
            }

            if (mwPosTag.startsWith("</") && mwPosTag.contains(REQUIRE_VIDMINOK_SUBSTR)) { // . " "
                posTag = multiwordReqToken.getPOSTag();
                reqTokenReadings = tokenReadings;
                continue;
            } else {
                if (!mwPosTag.contains("adv") && !mwPosTag.contains("insert")) {
                    reqTokenReadings = null;
                }
                continue;
            }
        }

        if (insideMultiword) {
            continue;
        }

        String token = tokenReadings.getAnalyzedToken(0).getToken();
        if (posTag.contains(REQUIRE_VIDMINOK_SUBSTR) && tokenReadings.getReadingsLength() == 1) {
            String prep = token;

            if (prep.equals("") && reverseSearch(tokens, i, "")) // TODO: move to disambiguator
                continue;

            if (prep.equalsIgnoreCase(""))
                continue;

            if ((prep.equalsIgnoreCase("") || prep.equalsIgnoreCase(""))
                    && tokens.length > i + 1
                    && tokens[i + 1].getAnalyzedToken(0).getToken().equalsIgnoreCase("?")) {
                reqTokenReadings = null;
                continue;
            }

            reqTokenReadings = tokenReadings;
            continue;
        }

        if (reqTokenReadings == null)
            continue;

        // Do actual check

        ArrayList<String> posTagsToFind = new ArrayList<>();
        String reqPosTag = reqTokenReadings.getAnalyzedToken(0).getPOSTag();
        String prep = reqTokenReadings.getAnalyzedToken(0).getLemma();

        //      AnalyzedToken multiwordToken = getMultiwordToken(tokenReadings);
        //      if( multiwordToken != null ) {
        //        reqTokenReadings = null;
        //        continue;
        //      }

        //TODO: for numerics only v_naz
        if (prep.equalsIgnoreCase("")) { //&& tokenReadings.getAnalyzedToken(0).getPOSTag().equals(IPOSTag.numr) ) { 
            posTagsToFind.add("v_naz");
        } else if (prep.equalsIgnoreCase("?")) {
            posTagsToFind.add("v_naz");
        }

        Matcher matcher = REQUIRE_VIDMINOK_REGEX.matcher(reqPosTag);
        while (matcher.find()) {
            posTagsToFind.add(matcher.group(1));
        }

        for (AnalyzedToken readingToken : tokenReadings) {
            if (IPOSTag.numr.match(readingToken.getPOSTag())) {
                posTagsToFind.add("v_naz"); // TODO: only if noun is following?
                break;
            }
        }

        //      System.out.println("For " + tokenReadings + " to match " + posTagsToFind + " of " + reqTokenReadings.getToken());
        if (!getReadingWithVidmPosTag(posTagsToFind, tokenReadings)) {
            if (isTokenToSkip(tokenReadings))
                continue;

            //        if( isTokenToIgnore(tokenReadings) ) {
            //          reqTokenReadings = null;
            //          continue;
            //        }

            //TODO: only for subset: ///?... or by verb //??/???...
            if (prep.equalsIgnoreCase("") || prep.equalsIgnoreCase("") || prep.equals("")
                    || prep.equals("")) {
                if (PosTagHelper.hasPosTag(tokenReadings, ".*p:v_naz[^&]*")) { // but not &pron:
                    reqTokenReadings = null;
                    continue;
                }
            }

            //  (??) ,  () ,  () 
            if (prep.equalsIgnoreCase("") && Character.isUpperCase(token.charAt(0))
                    && posTag.matches("noun:.:v_rod.*")) {
                reqTokenReadings = null;
                continue;
            }

            if (prep.equalsIgnoreCase("")) {
                if (token.equals("")) {
                    reqTokenReadings = null;
                    continue;
                }
            }

            if (prep.equalsIgnoreCase("")) {
                if (token.equalsIgnoreCase("") || token.equals("") || token.equals("")
                        || token.equals("")) { // / ??  
                    reqTokenReadings = null;
                    continue;
                }
            } else if (prep.equalsIgnoreCase("")) {
                if (token.equalsIgnoreCase("?") || token.equals("")
                        || token.equals("")) { // / ??  
                    reqTokenReadings = null;
                    continue;
                }
            }

            // exceptions
            if (tokens.length > i + 1) {
                //      if( tokens.length > i+1 && Character.isUpperCase(tokenReadings.getAnalyzedToken(0).getToken().charAt(0))
                //        && hasRequiredPosTag(Arrays.asList("v_naz"), tokenReadings)
                //        && Character.isUpperCase(tokens[i+1].getAnalyzedToken(0).getToken().charAt(0)) )
                //          continue; // "  ", "  "

                if (isCapitalized(token) && STREETS.contains(tokens[i + 1].getAnalyzedToken(0).getToken())) {
                    reqTokenReadings = null;
                    continue;
                }

                if (IPOSTag.isNum(tokens[i + 1].getAnalyzedToken(0).getPOSTag())
                        && (token.equals("?") || token.equals("?")
                                || token.equals("") || token.equals("?"))) {
                    reqTokenReadings = null;
                    continue;
                }

                //   ?  - ? 
                if (PosTagHelper.hasPosTag(tokenReadings, "noun:.:v_oru.*")
                        && tokens[i + 1].hasPartialPosTag("adjp")) {
                    continue;
                }

                if ((prep.equalsIgnoreCase("") || prep.equalsIgnoreCase("")) //  10, ? 3-4
                        && (posTag.startsWith("noun:p:v_naz") || posTag.startsWith("noun:p:v_rod")) // token.equals("") 
                        && IPOSTag.isNum(tokens[i + 1].getAnalyzedToken(0).getPOSTag())) {
                    reqTokenReadings = null;
                    continue;
                }

                if ((token.equals("") || token.equals("") || token.equals(""))
                        && tokens[i + 1].getAnalyzedToken(0).getToken().startsWith("")) {
                    continue;
                }
                if ((token.equals("?") || token.equals("") || token.equals(""))
                        && tokens[i + 1].getAnalyzedToken(0).getToken().startsWith("")) {
                    continue;
                }
                if ((token.equals("?") || token.equals("?"))
                        && tokens[i + 1].getAnalyzedToken(0).getToken().startsWith("")) {
                    continue;
                }

                if (prep.equalsIgnoreCase("") && token.equals("?")
                        && tokens[i + 1].getAnalyzedToken(0).getToken().equals("??")) {
                    reqTokenReadings = null;
                    continue;
                }

                if (tokens[i + 1].getAnalyzedToken(0).getToken().equals("")
                        && tokens[i].getAnalyzedToken(0).getPOSTag().contains(":abbr")) {
                    reqTokenReadings = null;
                    continue;
                }

                if (tokens.length > i + 2) {
                    // ???  ??  ?
                    if (/*prep.equalsIgnoreCase("") &&*/ posTag.matches("adj.*:[mfn]:v_rod.*")) {
                        String gender = PosTagHelper.getGender(posTag);
                        if (gender == null) {
                            //                System.err.println("unknown gender for " + token);
                        }

                        if (PosTagHelper.hasPosTag(tokens[i + 1], "noun.*:" + gender + ":v_rod.*")) {
                            i += 1;
                            continue;
                        }
                    }

                    if ((token.equals("") || token.equals("")
                            || token.equals("") || token.equals(""))
                            && tokens[i + 1].getAnalyzedToken(0).getToken().equals("")) {
                        //          reqTokenReadings = null;
                        continue;
                    }
                    //            // ???  ??  ?
                    //            if (prep.equalsIgnoreCase("") && posTag.matches("adj.*:[mfn]:v_rod.*")) {
                    //              String gender = PosTagHelper.getGender(posTag);
                    //              if ( hasPosTag(tokens[i+1], "noun.*:"+gender+":v_rod.*")) {
                    //                i+=1;
                    //                continue;
                    //              }
                    //            }
                }
            }

            RuleMatch potentialRuleMatch = createRuleMatch(tokenReadings, reqTokenReadings, posTagsToFind);
            ruleMatches.add(potentialRuleMatch);
        }

        reqTokenReadings = null;
    }

    return toRuleMatchArray(ruleMatches);
}

From source file:org.kuali.rice.krad.uif.service.impl.UifDefaultingServiceImpl.java

@Override
public String deriveHumanFriendlyNameFromPropertyName(String camelCasedName) {
    // quick check to make sure there is a property name to modify
    if (StringUtils.isBlank(camelCasedName)) {
        return camelCasedName;
    }/*from w w w.j  a  v a 2  s . co m*/

    // We only want to include the component after the last property separator
    if (camelCasedName.contains(".")) {
        camelCasedName = StringUtils.substringAfterLast(camelCasedName, ".");
    }
    StringBuilder label = new StringBuilder(camelCasedName);
    // upper case the 1st letter
    label.replace(0, 1, label.substring(0, 1).toUpperCase());
    // loop through, inserting spaces when cap
    for (int i = 0; i < label.length(); i++) {
        if (Character.isUpperCase(label.charAt(i)) || Character.isDigit(label.charAt(i))) {
            label.insert(i, ' ');
            i++;
        }
    }

    return label.toString().trim();
}

From source file:org.kie.workbench.common.services.datamodeller.codegen.GenerationTools.java

private String toJavaAccessor(String prefix, String name) {
    if (name == null || name.length() == 0) {
        return name;
    }/*  w  w w .  j  a v  a  2 s  . c  o  m*/

    StringBuilder method = new StringBuilder(prefix);

    if (name.charAt(0) == '_') {
        return method.append(name).toString();
    }

    if (name.length() == 1) {
        return method.append(name.toUpperCase()).toString();
    }

    if (Character.isUpperCase(name.charAt(0))) {
        return method.append(name).toString();
    }

    if (Character.isUpperCase(name.charAt(1))) {
        return method.append(name).toString();
    } else {
        return method.append(StringUtils.capitalize(name)).toString();
    }
}

From source file:org.openlegacy.utils.StringUtil.java

public static String toDisplayName(String text) {
    if (StringUtils.isAllUpperCase(text)) {
        text = text.toLowerCase();//from  www. ja v a2s.c o m
    }
    char[] chars = text.toCharArray();
    StringBuilder sb = new StringBuilder(text.length());
    for (int i = 0; i < chars.length; i++) {
        char c = chars[i];
        if (Character.isLetter(c) || Character.isDigit(c) || c == ' ' || c == '\\' || c == '/' || c == '.') {
            if (i == 0) {
                sb.append(Character.toUpperCase(c));
            } else {
                // add blank current char is upper case, previous char is blank and not upper case
                if (Character.isUpperCase(c) && chars[i - 1] != ' ' && Character.isLetter(chars[i - 1])
                        && !Character.isUpperCase(chars[i - 1])) {
                    sb.append(' ');
                }
                sb.append(c);
            }
        }

    }
    return StringUtils.strip(sb.toString(), " .");
}

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

private <R> List<ModelPropertyExtractionResult<?>> extractPropertySchemas(
        ModelSchemaExtractionContext<R> extractionContext, Multimap<String, Method> methodsByName) {
    List<ModelPropertyExtractionResult<?>> results = Lists.newArrayList();
    Set<Method> handledMethods = Sets.newHashSet();

    List<String> methodNames = Lists.newArrayList(methodsByName.keySet());
    Collections.sort(methodNames);
    Set<String> skippedMethodNames = Sets.newHashSet();
    for (String methodName : methodNames) {
        if (skippedMethodNames.contains(methodName)) {
            continue;
        }/*from w  w w.j a v  a2  s .  co m*/

        Collection<Method> methods = methodsByName.get(methodName);

        List<Method> overloadedMethods = getOverloadedMethods(methods);
        if (overloadedMethods != null) {
            handleOverloadedMethods(extractionContext, overloadedMethods);
            methods = filterGetterMethods(methods);
            if (methods.isEmpty()) {
                continue;
            }
        }

        int getterPrefixLen = getterPrefixLength(methodName);
        if (getterPrefixLen >= 0) {
            Method mostSpecificGetter = ModelSchemaUtils.findMostSpecificMethod(methods);

            char getterPropertyNameFirstChar = methodName.charAt(getterPrefixLen);
            if (!Character.isUpperCase(getterPropertyNameFirstChar)) {
                handleInvalidGetter(extractionContext, mostSpecificGetter,
                        String.format(
                                "the %s character of the getter method name must be an uppercase character",
                                getterPrefixLen == 2 ? "3rd" : "4th"));
                continue;
            }

            String propertyNameCapitalized = methodName.substring(getterPrefixLen);
            String propertyName = StringUtils.uncapitalize(propertyNameCapitalized);
            String setterName = "set" + propertyNameCapitalized;
            Collection<Method> setterMethods = methodsByName.get(setterName);
            PropertyAccessorExtractionContext setterContext = !setterMethods.isEmpty()
                    ? new PropertyAccessorExtractionContext(setterMethods)
                    : null;

            String prefix = methodName.substring(0, getterPrefixLen);
            Iterable<Method> getterMethods = methods;
            if (prefix.equals("get")) {
                String isGetterName = "is" + propertyNameCapitalized;
                Collection<Method> isGetterMethods = methodsByName.get(isGetterName);
                if (!isGetterMethods.isEmpty()) {
                    List<Method> overloadedIsGetterMethods = getOverloadedMethods(isGetterMethods);
                    if (overloadedIsGetterMethods != null) {
                        handleOverloadedMethods(extractionContext, overloadedIsGetterMethods);
                        isGetterMethods = filterGetterMethods(isGetterMethods);
                    }

                    if (!isGetterMethods.isEmpty()) {
                        Method mostSpecificIsGetter = ModelSchemaUtils.findMostSpecificMethod(isGetterMethods);
                        if (mostSpecificGetter.getReturnType() != boolean.class
                                || mostSpecificIsGetter.getReturnType() != boolean.class) {
                            handleInvalidGetter(extractionContext, mostSpecificIsGetter, String.format(
                                    "property '%s' has both '%s()' and '%s()' getters, but they don't both return a boolean",
                                    propertyName, isGetterName, methodName));
                            continue;
                        }
                        getterMethods = Iterables.concat(getterMethods, isGetterMethods);
                        skippedMethodNames.add(isGetterName);
                    }
                }
            }

            PropertyAccessorExtractionContext getterContext = new PropertyAccessorExtractionContext(
                    getterMethods);
            ModelPropertyExtractionResult<?> result = extractPropertySchema(extractionContext, propertyName,
                    getterContext, setterContext, getterPrefixLen);
            if (result != null) {
                results.add(result);
                handledMethods.addAll(getterContext.getDeclaringMethods());
                if (setterContext != null) {
                    handledMethods.addAll(setterContext.getDeclaringMethods());
                }

            }
        }
    }

    validateAllNecessaryMethodsHandled(extractionContext, methodsByName.values(), handledMethods);
    return results;
}

From source file:com.curl.orb.servlet.InstanceManagementUtil.java

public static boolean isSetter(Method method) {
    return (method.getName().startsWith("set") && Character.isUpperCase(method.getName().charAt(3))
            && method.getParameterTypes().length == 1 && method.getReturnType() == void.class);
}

From source file:TestStore.java

private void dumpRecord(byte[] data, int size, PrintStream out, StringBuffer hexLine, StringBuffer charLine,
        int maxLen) {
    if (size == 0)
        return;//from   www  . j  a va  2  s . c  om

    hexLine.setLength(0);
    charLine.setLength(0);

    int count = 0;

    for (int i = 0; i < size; ++i) {
        char b = (char) (data[i] & 0xFF);

        if (b < 0x10) {
            hexLine.append('0');
        }

        hexLine.append(Integer.toHexString(b));
        hexLine.append(' ');

        if ((b >= 32 && b <= 127) || Character.isDigit(b) || Character.isLowerCase(b)
                || Character.isUpperCase(b)) {
            charLine.append((char) b);
        } else {
            charLine.append('.');
        }

        if (++count >= maxLen || i == size - 1) {
            while (count++ < maxLen) {
                hexLine.append("   ");
            }

            hexLine.append(' ');
            hexLine.append(charLine.toString());

            out.println(hexLine.toString());

            hexLine.setLength(0);
            charLine.setLength(0);
            count = 0;
        }
    }
}

From source file:jetx.ext.common.StringMethods.java

/**
 * <p>Swaps the case of a String changing upper and title case to
 * lower case, and lower case to upper case.</p>
 *
 * <ul>//from  ww w .  j  av a 2 s.c om
 *  <li>Upper case character converts to Lower case</li>
 *  <li>Title case character converts to Lower case</li>
 *  <li>Lower case character converts to Upper case</li>
 * </ul>
 *
 * <p>For a word based algorithm, see {@link org.apache.commons.lang3.text.WordUtils#swapCase(String)}.
 * A {@code null} input String returns {@code null}.</p>
 *
 * <pre>
 * StringMethods.swapCase(null)                 = null
 * StringMethods.swapCase("")                   = ""
 * StringMethods.swapCase("The dog has a BONE") = "tHE DOG HAS A bone"
 * </pre>
 *
 * <p>NOTE: This method changed in Lang version 2.0.
 * It no longer performs a word based algorithm.
 * If you only use ASCII, you will notice no change.
 * That functionality is available in org.apache.commons.lang3.text.WordUtils.</p>
 *
 * @param str  the String to swap case, may be null
 * @return the changed String, {@code null} if null String input
 */
public static String swapCase(String str) {
    if (isEmpty(str)) {
        return str;
    }

    char[] buffer = str.toCharArray();

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

From source file:org.forgerock.openam.cts.utils.blob.strategies.AttributeCompressionStrategy.java

/**
 * Generate the initials from the given name.
 *
 * Note: This function is intended to operate against Java field name syntax.
 * As such it simply picks out the first character and all subsequent upper
 * case characters from the String./*w  ww .j  a  v  a 2s. c o  m*/
 *
 * @param name Non null string that follows Java field name syntax.
 * @return The initials of the field.
 */
public static String getInitials(String name) {
    if (name == null) {
        throw new IllegalArgumentException("Name was null");
    }
    StringBuilder r = new StringBuilder();
    boolean start = true;
    for (int ii = 0; ii < name.length(); ii++) {
        char c = name.charAt(ii);
        if (start) {
            r.append(c);
            start = false;
            continue;
        }
        if (Character.isUpperCase(c)) {
            r.append(c);
        }
    }
    return r.toString();
}

From source file:com.google.dart.engine.services.refactoring.NamingConventions.java

/**
 * @return the {@link RefactoringStatus} with {@link RefactoringStatusSeverity#OK} if the name is
 *         valid, {@link RefactoringStatusSeverity#WARNING} if the name is discouraged, or
 *         {@link RefactoringStatusSeverity#ERROR} if the name is illegal.
 *//*from www  .j  a va 2 s  .c o  m*/
public static RefactoringStatus validateLibraryName(String name) {
    // null
    if (name == null) {
        return RefactoringStatus.createErrorStatus("Library name must not be null.");
    }
    // blank
    if (StringUtils.isBlank(name)) {
        return RefactoringStatus.createErrorStatus("Library name must not be blank.");
    }
    // check identifiers
    String[] identifiers = StringUtils.splitPreserveAllTokens(name, '.');
    for (String identifier : identifiers) {
        RefactoringStatus status = validateIdentifier0(identifier, "Library name identifier");
        if (!status.isOK()) {
            return status;
        }
    }
    // should not have upper-case letters
    for (String identifier : identifiers) {
        char[] chars = identifier.toCharArray();
        for (char c : chars) {
            if (Character.isUpperCase(c)) {
                return RefactoringStatus.createWarningStatus(
                        "Library name should consist of lower-case identifier separated by dots.");
            }
        }
    }
    // OK
    return new RefactoringStatus();
}