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:pl.edu.pwr.litmap.textobjects.Textobject.java

/**
 * W obiektach, ktrych nazwa skada si z wielu wyrazw czasami sam .getBase() daje bdne wyniki, np 
 * "Dawid Podsiado" -> "Dawid podsi"/*  w  ww . ja v a 2 s  .  c om*/
 * "Syryjskiego Obserwatorium Praw Czowieka" -> "syryjski obserwatorium prawo czowiek"
 * ale
 * "Sebastian Nowak: -> "Sebastian Nowak"
 * 
 * Bdy rwnie w jednowyrazowych:
 * "[w] Opolu" -> "opole" (brak pierwszej duej litery)
 * Dlatego jeeli wykryje zmian wielkoci pierwszej litery (lub inn cech wskazujc - np. nazwa ulicy, ktej forma podstawowa zazwyczaj jest bdna)
 * na moliwo wystpienia bedu pozostawia wersje z tekstu (zamiast nieprawidowej formy podstawowej)
 * @return the baseName
 */
public String getBaseName() {
    String baseName;
    StringBuilder sb = new StringBuilder();
    boolean possibleErrorInRecognize = false;

    if (this.getNameClass().equals(NameClass.ROAD_NAM)
            || this.getNameClass().equals(NameClass.ADDRESS_STREET_NAM)) {
        possibleErrorInRecognize = true;
    } else if (chunk.getTokens().size() > 1) {
        possibleErrorInRecognize = true;
    } else {

        for (Integer token_index : chunk.getTokens()) {
            Token token = chunk.getSentence().getTokens().get(token_index);
            Tag tag = token.getTags().get(0);

            if (Character.isUpperCase(token.getFirstValue().charAt(0))
                    && !Character.isUpperCase(tag.getBase().charAt(0))) {
                possibleErrorInRecognize = true;
                break;
            }

            sb.append(tag.getBase());
            if (!token.getNoSpaceAfter()) {
                sb.append(' ');
            }
        }
    }

    baseName = possibleErrorInRecognize ? getRawText() : sb.toString().trim();

    return baseName;
}

From source file:mrcg.utils.Utils.java

public static String toDatabaseFormat(String s) {
    StringBuilder b = new StringBuilder(s.length() + 5);
    for (char c : s.toCharArray()) {
        if (Character.isUpperCase(c) && b.length() > 0) {
            b.append('_');
        }//from w  ww  .  ja va  2s.c om
        b.append(Character.toLowerCase(c));
    }
    return b.toString();
}

From source file:org.jboss.dashboard.commons.misc.ReflectionUtils.java

/**
 * Convert the fieldName to a valid name to be append to METHOD_PREFIX_GET/SET
 *
 * @param fieldName name of the accessor property
 * @return valid name for accessor/*  w  w w .j a  va2  s.  c o m*/
 */
private static String getValidAccessorName(String fieldName) {
    char firstChar = fieldName.charAt(0);
    String field = StringUtil.toJavaClassName(fieldName);
    if (fieldName.length() > 1) {
        //fix if firstCharacter is lowercase and second is uppercase, then create correct accessor (i.e. getter for field xXX is getxXX)
        char secondChar = fieldName.charAt(1);
        if (Character.isLowerCase(firstChar) && Character.isUpperCase(secondChar)) {
            field = field.replaceFirst(Character.toString(field.charAt(0)), Character.toString(firstChar));
        }
    }
    return field;
}

From source file:org.grouplens.lenskit.eval.graph.ComponentNodeBuilder.java

static String shortClassName(Class<?> type) {
    if (ClassUtils.isPrimitiveOrWrapper(type)) {
        if (!type.isPrimitive()) {
            type = ClassUtils.wrapperToPrimitive(type);
        }//from www. j ava2 s .c o  m
        return type.getName();
    } else if (type.getPackage().equals(Package.getPackage("java.lang"))) {
        return type.getSimpleName();
    } else {
        String[] words = type.getName().split(" ");
        String fullClassName = words[words.length - 1];
        String[] path = fullClassName.split("\\.");
        int i = 0;
        while (!Character.isUpperCase(path[i + 1].charAt(0))) {
            path[i] = path[i].substring(0, 1);
            i++;
        }
        return StringUtils.join(path, ".");
    }
}

From source file:org.languagetool.rules.de.CompoundCoherencyRule.java

@Nullable
private String getLemma(AnalyzedTokenReadings atr) {
    String lemmaOrNull = atr.hasSameLemmas() && atr.getReadingsLength() > 0
            ? atr.getReadings().get(0).getLemma()
            : null;//w w w.ja  v a 2  s . co m
    if (lemmaOrNull != null) {
        // our analysis gets lemma "Jugendfoto" for "Jugend-Fotos", we 'fix' that here
        String token = atr.getToken();
        if (!lemmaOrNull.contains("-") && token.contains("-")) {
            StringBuilder lemmaBuilder = new StringBuilder();
            for (int lemmaPos = 0, tokenPos = 0; lemmaPos < lemmaOrNull.length(); lemmaPos++, tokenPos++) {
                if (tokenPos >= token.length()) {
                    break;
                }
                char lemmaChar = lemmaOrNull.charAt(lemmaPos);
                char tokenChar = token.charAt(tokenPos);
                if (lemmaChar == tokenChar) {
                    lemmaBuilder.append(lemmaChar);
                } else if (token.charAt(tokenPos) == '-') {
                    tokenPos++; // skip hyphen
                    lemmaBuilder.append("-");
                    if (lemmaPos + 1 < token.length() && Character.isUpperCase(token.charAt(tokenPos))) {
                        lemmaBuilder.append(Character.toUpperCase(lemmaChar));
                    } else {
                        lemmaBuilder.append(lemmaChar);
                    }
                }
            }
            return lemmaBuilder.toString();
        }
        return lemmaOrNull;
    } else {
        return null;
    }
}

From source file:edu.msu.cme.rdp.readseq.utils.SequenceTrimmer.java

public static int translateCoord(int coord, Sequence seq, CoordType in, CoordType out) {
    int modelPos = 0;
    int seqPos = 0;
    int index;//  w ww. j  a  v  a 2s  .c o  m

    char[] bases = seq.getSeqString().toCharArray();

    for (index = 0; index < bases.length; index++) {
        if (Character.isLetter(bases[index])) {
            seqPos++;
        }

        if ((in == CoordType.seq && seqPos == coord) || (in == CoordType.model && modelPos == coord)
                || (in == CoordType.alignment && index == coord)) {
            break;
        }

        if (bases[index] == '-' || Character.isUpperCase(bases[index])) {
            modelPos++;
        }
    }

    switch (out) {
    case seq:
        return seqPos;
    case model:
        return modelPos;
    case alignment:
        return index;
    }

    throw new IllegalArgumentException("Dunno what to do with out value " + out);
}

From source file:com.change_vision.astah.extension.plugin.csharpreverse.reverser.DoxygenXmlParser.java

/**
 * ???????????????????<br/>//from   w w  w .  j  a v  a  2 s  .  co m
 * 
 * ()  _(?)<br/>
 * :  _1<br/>
 * .  _8
 * 
 * @param str
 *            
 * @return ???
 */
private static String convertString(String str) {
    StringBuffer sb = new StringBuffer();
    for (Character ch : str.toCharArray()) {
        if (ch.equals(':')) {
            sb.append("_1");
        } else if (ch.equals('.')) {
            sb.append("_8");
        } else if (Character.isUpperCase(ch)) {
            sb.append("_" + Character.toLowerCase(ch));
        } else {
            sb.append(ch);
        }
    }
    return sb.toString();
}

From source file:org.grails.datastore.mapping.reflect.ClassPropertyFetcher.java

private void processMethod(Method method) {
    if (method.isSynthetic()) {
        return;//from   www  .jav  a 2s .  c om
    }
    if (!Modifier.isPublic(method.getModifiers())) {
        return;
    }
    if (Modifier.isStatic(method.getModifiers()) && method.getReturnType() != Void.class) {
        if (method.getParameterTypes().length == 0) {
            String name = method.getName();
            if (name.indexOf('$') == -1) {
                if (name.length() > 3 && name.startsWith("get") && Character.isUpperCase(name.charAt(3))) {
                    name = name.substring(3);
                } else if (name.length() > 2 && name.startsWith("is") && Character.isUpperCase(name.charAt(2))
                        && (method.getReturnType() == Boolean.class
                                || method.getReturnType() == boolean.class)) {
                    name = name.substring(2);
                }
                PropertyFetcher fetcher = new GetterPropertyFetcher(method, true);
                List<PropertyFetcher> propertyFetchers = staticFetchers.get(name);
                if (propertyFetchers == null) {
                    staticFetchers.put(name, propertyFetchers = new ArrayList<PropertyFetcher>());
                }
                propertyFetchers.add(fetcher);
                String decapitalized = Introspector.decapitalize(name);
                if (!decapitalized.equals(name)) {
                    propertyFetchers = staticFetchers.get(decapitalized);
                    if (propertyFetchers == null) {
                        staticFetchers.put(decapitalized, propertyFetchers = new ArrayList<PropertyFetcher>());
                    }
                    propertyFetchers.add(fetcher);
                }
            }
        }
    }
}

From source file:com.liferay.cucumber.util.StringUtil.java

public static boolean isLowerCase(String s) {
    if (s == null) {
        return false;
    }//  w  w  w.j  a  v a  2 s  . co m

    for (int i = 0; i < s.length(); i++) {
        char c = s.charAt(i);

        // Fast path for ascii code, fallback to the slow unicode detection

        if (c <= 127) {
            if ((c >= CharPool.UPPER_CASE_A) && (c <= CharPool.UPPER_CASE_Z)) {

                return false;
            }

            continue;
        }

        if (Character.isLetter(c) && Character.isUpperCase(c)) {
            return false;
        }
    }

    return true;
}

From source file:org.languagetool.dev.bigdata.ProhibitedCompoundRuleEvaluator.java

@SuppressWarnings("ConstantConditions")
private void evaluate(List<Map.Entry<Sentence, Map.Entry<Integer, Integer>>> sentences, boolean isCorrect,
        String token, String homophoneToken, List<Long> evalFactors) throws IOException {
    println("======================");
    printf("Starting evaluation on " + sentences.size() + " sentences with %s/%s (%s):\n", token,
            homophoneToken, String.valueOf(isCorrect));
    JLanguageTool lt = new JLanguageTool(language);
    List<Rule> allActiveRules = lt.getAllActiveRules();
    for (Rule activeRule : allActiveRules) {
        lt.disableRule(activeRule.getId());
    }//from   ww w  .  j a  v  a2s .  c o m
    for (Map.Entry<Sentence, Map.Entry<Integer, Integer>> sentenceMatch : sentences) {
        Sentence sentence = sentenceMatch.getKey();
        String plainText = sentence.getText();
        int matchStart = sentenceMatch.getValue().getKey();
        int matchEnd = sentenceMatch.getValue().getValue();
        String match = plainText.substring(matchStart, matchEnd);
        String textToken = Character.isUpperCase(match.charAt(0)) ? StringUtils.capitalize(token)
                : StringUtils.uncapitalize(token);
        String evaluated = plainText;
        if (!isCorrect) {
            evaluated = plainText.substring(0, matchStart) + textToken + plainText.substring(matchEnd);
        }
        //printf("%nCorrect: %s%nPlain text: %s%nToken: %s%nHomophone: %s%nMatch: '%s'%nReplacement: %s%n%n", String.valueOf(isCorrect), plainText, token, homophoneToken, match, replacement);
        AnalyzedSentence analyzedSentence = lt.getAnalyzedSentence(evaluated);
        for (Long factor : evalFactors) {
            rule.setConfusionPair(new ProhibitedCompoundRule.Pair(homophoneToken, "", token, ""));
            RuleMatch[] matches = rule.match(analyzedSentence);
            String displayStr = plainText.substring(0, matchStart) + token.toUpperCase()
                    + plainText.substring(matchStart + (isCorrect ? token.length() : homophoneToken.length()));
            boolean consideredCorrect = matches.length == 0;
            if (consideredCorrect && isCorrect) {
                evalValues.get(factor).trueNegatives++;
                //println("true negative: " + displayStr);
            } else if (!consideredCorrect && isCorrect) {
                evalValues.get(factor).falsePositives++;
                //println("false positive: " + displayStr);
            } else if (consideredCorrect && !isCorrect) {
                //println("false negative: " + displayStr);
                evalValues.get(factor).falseNegatives++;
            } else {
                evalValues.get(factor).truePositives++;
                //System.out.println("true positive: " + displayStr);
            }
        }
    }
}