Example usage for org.apache.commons.lang3 StringUtils isAllUpperCase

List of usage examples for org.apache.commons.lang3 StringUtils isAllUpperCase

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringUtils isAllUpperCase.

Prototype

public static boolean isAllUpperCase(final CharSequence cs) 

Source Link

Document

Checks if the CharSequence contains only uppercase characters.

null will return false .

Usage

From source file:org.ambraproject.views.CrossRefSearch.java

/**
 * Build search query to pass to the crossref search API
 *
 * @return a query string//from  ww w. jav  a2s  . c om
 */
public String buildQuery() {
    StringBuilder sb = new StringBuilder();

    for (CitedArticleName name : this.names) {
        String fullName = "";

        if (StringUtils.isNotBlank(name.surName) && StringUtils.isNotBlank(name.givenName)) {
            if (StringUtils.isAllUpperCase(name.givenName.replaceAll("[^A-Za-z0-9]", ""))) {
                for (Character c : name.givenName.toCharArray()) {
                    fullName = fullName + c + ". ";
                }
                fullName = fullName + name.surName;
            } else {
                fullName = name.givenName + " " + name.surName;
            }
        } else {
            if (StringUtils.isNotBlank(name.surName)) {
                fullName = name.surName;
            }

            if (StringUtils.isNotBlank(name.collab)) {
                fullName = name.collab;
            }
        }

        if (StringUtils.isNotBlank(fullName)) {
            if (sb.length() > 0) {
                sb.append(", ");
            }

            sb.append(fullName);
        }
    }

    if (StringUtils.isNotBlank(this.title)) {
        sb.append(", \"").append(this.title).append("\"");
    }

    if (StringUtils.isNotBlank(this.source)) {
        sb.append(", ").append(this.source);
    }

    if (StringUtils.isNotBlank(this.volume)) {
        sb.append(", vol. ").append(volume);
    }

    if (StringUtils.isNotBlank(this.issue)) {
        sb.append(", no. ").append(this.issue);
    }

    if (StringUtils.isNotBlank(this.fPage) && StringUtils.isNotBlank(this.lPage)) {
        sb.append(", pp. ").append(this.fPage).append("-").append(this.lPage);
    } else if (StringUtils.isNotBlank(this.fPage)) {
        sb.append(", pp. ").append(this.fPage);
    }

    if (StringUtils.isNotBlank(this.elocationID)) {
        sb.append(", e").append(this.elocationID);
    }

    if (StringUtils.isNotBlank(this.year)) {
        sb.append(", ").append(this.year);
    }

    return sb.toString();
}

From source file:org.apache.usergrid.security.PasswordPolicyImpl.java

public Collection<String> policyCheck(String password, int minLength, int minUppercase, int minDigits,
        int minSpecialChars) {

    List<String> violations = new ArrayList<>(3);

    // check length
    if (password == null || password.length() < minLength) {
        violations.add(PasswordPolicy.ERROR_LENGTH_POLICY + ": must be at least " + minLength + " characters");
    }/*from   w w w .  java 2  s  .c o m*/

    // count upper case
    if (minUppercase > 0) {
        int upperCaseCount = 0;
        for (char c : password.toCharArray()) {
            if (StringUtils.isAllUpperCase(String.valueOf(c))) {
                upperCaseCount++;
            }
        }
        if (upperCaseCount < minUppercase) {
            violations.add(PasswordPolicy.ERROR_UPPERCASE_POLICY + ": requires " + minUppercase
                    + " uppercase characters");
        }
    }

    // count digits case
    if (minDigits > 0) {
        int digitCount = 0;
        for (char c : password.toCharArray()) {
            if (StringUtils.isNumeric(String.valueOf(c))) {
                digitCount++;
            }
        }
        if (digitCount < minDigits) {
            violations.add(PasswordPolicy.ERROR_DIGITS_POLICY + ": requires " + minDigits + " digits");
        }
    }

    // count special characters
    if (minSpecialChars > 0) {
        int specialCharCount = 0;
        for (char c : password.toCharArray()) {
            if (passwordPolicyFig.getAllowedSpecialChars().contains(String.valueOf(c))) {
                specialCharCount++;
            }
        }
        if (specialCharCount < minSpecialChars) {
            violations.add(PasswordPolicy.ERROR_SPECIAL_CHARS_POLICY + ": requires " + minSpecialChars
                    + " special characters");
        }
    }

    return violations;
}

From source file:org.gbif.namefinder.analysis.sciname.SciNameAnalyzerTest.java

@Test
public void testSimpleText() throws Exception {
    System.out.println(StringUtils.isAllUpperCase("G"));
    System.out.println(StringUtils.isAllUpperCase("G"));
    String text = "Help, Asteraceae or is (Felinia) or Felis (Felinia) foordi found. I can't see any of these famous Abies alba anywhere around here, can you? Maybe this is Potentilla vulgaris L. ? You can't be sure, my dear. Paris is a pretty town too, isn't it? They have big numbers of Passer domesticus subsp. domesticus, the most frequent subspecies of Passer domesticus (Linnaeus, 1758)";
    Reader input = new StringReader(text);
    LinkedList<String> expected = new LinkedList<String>();
    expected.add("Asteraceae");
    expected.add("Felis (Felinia) foordi");
    expected.add("Abies alba");
    expected.add("Potentilla vulgaris");
    expected.add("Passer domesticus subsp. domesticus");
    expected.add("Passer domesticus");
    TokenStream tokens = getTokens(input);
    SciNameIterator iter = new SciNameIterator(tokens);
    for (SciName sn : iter) {
        //      System.out.println(sn);
        assertEquals(expected.poll(), sn.scientificName);
    }//from   w  ww.ja  va2 s . c o m
    tokens.end();
    tokens.close();
}

From source file:org.jsweet.input.typescriptdef.util.Util.java

public static boolean elligibleToClass(ModuleDeclaration module) {
    if (Character.isUpperCase(module.getName().charAt(0)) && !StringUtils.isAllUpperCase(module.getName())) {
        for (Declaration declaration : module.getMembers()) {
            if (declaration instanceof TypeDeclaration || declaration instanceof ModuleDeclaration) {
                return false;
            }/*from  w ww  .j a va  2s .  co m*/
        }
        return true;
    } else {
        return false;
    }
}

From source file:org.jumpmind.metl.ui.views.design.EditFlowPalette.java

protected void populateComponentTypesInComponentPalette(String projectVersionId) {
    Map<String, List<XMLComponent>> componentDefinitionsByCategory = context.getComponentDefinitionFactory()
            .getDefinitionsByCategory();
    for (String category : new TreeSet<>(componentDefinitionsByCategory.keySet())) {
        List<XMLComponent> componentDefinitions = new ArrayList<XMLComponent>(
                componentDefinitionsByCategory.get(category));
        Collections.sort(componentDefinitions);
        VerticalLayout componentLayout = new VerticalLayout();
        componentAccordian.addTab(componentLayout,
                StringUtils.isAllUpperCase(category) ? category + "S" : category + "s");
        for (XMLComponent definition : componentDefinitions) {
            ClassResource icon = getImageResourceForComponentType(definition.getId());
            addItemToFlowPanelSection(definition.getName(), definition.getId(), componentLayout, icon, null);
        }//from   w w  w. j  av  a  2  s  .  com
    }
}

From source file:org.lanes.utility.string.FuzzyMatcher.java

public boolean isBothUpperCase(String x1, String y1) {
    if (StringUtils.isAllUpperCase(x1) && StringUtils.isAllUpperCase(y1)) {
        return true;
    } else {/*w ww .  ja v a2s .  co m*/
        return false;
    }
}

From source file:org.lanes.utility.string.FuzzyMatcher.java

public boolean isMostlyUpperCase(String str) {
    String[] chars = str.split(".");
    int totalchar = chars.length;
    int uppercasecnt = 0;
    for (String char_ : chars) {
        if (StringUtils.isAllUpperCase(char_)) {
            uppercasecnt++;/*w  ww.ja v  a  2  s .com*/
        }
    }

    double uppercasepercent = (double) uppercasecnt / (double) totalchar;
    if (uppercasepercent > 0.9) {
        return true;
    }
    return false;

}

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

@Override
public RuleMatch[] match(List<AnalyzedSentence> sentences) throws IOException {
    String firstUse = null;//  w w w  . j a v  a2 s. c om
    List<RuleMatch> ruleMatches = new ArrayList<>();
    int pos = 0;
    for (AnalyzedSentence sentence : sentences) {
        AnalyzedTokenReadings[] tokens = sentence.getTokensWithoutWhitespace();
        for (int i = 0; i < tokens.length; i++) {
            if (i > 0 && (tokens[i - 1].isSentenceStart()
                    || StringUtils.equalsAny(tokens[i - 1].getToken(), "\"", "", ":"))) {
                continue;
            }
            AnalyzedTokenReadings token = tokens[i];
            String word = token.getToken();
            String lcWord = word.toLowerCase();
            if (lowerWords.contains(lcWord) || ambiguousWords.contains(lcWord)) {
                if (firstUse == null) {
                    if (!ambiguousWords.contains(word)) {
                        firstUse = word;
                    }
                } else {
                    boolean firstUseIsUpper = StringTools.startsWithUppercase(firstUse);
                    String msg = null;
                    String replacement = null;
                    if (firstUseIsUpper && !StringTools.startsWithUppercase(word)) {
                        replacement = StringTools.uppercaseFirstChar(word);
                        if (ambiguousWords.contains(word)) {
                            msg = "Vorher wurde bereits '" + firstUse + "' grogeschrieben. "
                                    + "Nur falls es sich hier auch um eine Anrede handelt: Aus Grnden der Einheitlichkeit '"
                                    + replacement + "' hier auch groschreiben?";
                        } else {
                            msg = "Vorher wurde bereits '" + firstUse + "' grogeschrieben. "
                                    + "Aus Grnden der Einheitlichkeit '" + replacement
                                    + "' hier auch groschreiben?";
                        }
                    } else if (!firstUseIsUpper && StringTools.startsWithUppercase(word)
                            && !StringUtils.isAllUpperCase(word)) {
                        replacement = StringTools.lowercaseFirstChar(word);
                        msg = "Vorher wurde bereits '" + firstUse + "' kleingeschrieben. "
                                + "Aus Grnden der Einheitlichkeit '" + replacement
                                + "' hier auch kleinschreiben?";
                    }
                    if (replacement != null) {
                        RuleMatch ruleMatch = new RuleMatch(this, sentence, pos + token.getStartPos(),
                                pos + token.getEndPos(), msg);
                        ruleMatch.setSuggestedReplacement(replacement);
                        ruleMatches.add(ruleMatch);
                    }
                }
            }
        }
        pos += sentence.getText().length();
    }
    return toRuleMatchArray(ruleMatches);
}

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

private boolean ignoreCompoundWithIgnoredWord(String word) throws IOException {
    if (!StringTools.startsWithUppercase(word)
            && !StringUtils.startsWithAny(word, "nord", "west", "ost", "sd")) {
        // otherwise stuff like "rumfangreichen" gets accepted
        return false;
    }//from w  ww .j av  a2  s. c  o m
    String[] words = word.split("-");
    if (words.length < 2) {
        // non-hyphenated compound (e.g., "Feynmandiagramm"):
        // only search for compounds that start(!) with a word from spelling.txt
        int end = super.startsWithIgnoredWord(word, true);
        if (end < 3) {
            // support for geographical adjectives - although "sd/ost/west/nord" are not in spelling.txt 
            // to accept sentences such as
            // "Der westperuanische Ferienort, das ostargentinische Stdtchen, das sdukrainische Brauchtum, der nordgyptische Staudamm."
            if (word.startsWith("ost") || word.startsWith("sd")) {
                end = 3;
            } else if (word.startsWith("west") || word.startsWith("nord")) {
                end = 4;
            } else {
                return false;
            }
        }
        String ignoredWord = word.substring(0, end);
        String partialWord = word.substring(end);
        boolean isCandidateForNonHyphenatedCompound = !StringUtils.isAllUpperCase(ignoredWord)
                && (StringUtils.isAllLowerCase(partialWord) || ignoredWord.endsWith("-"));
        boolean needFugenS = isNeedingFugenS(ignoredWord);
        if (isCandidateForNonHyphenatedCompound && !needFugenS && partialWord.length() > 2) {
            return !hunspellDict.misspelled(partialWord)
                    || !hunspellDict.misspelled(StringUtils.capitalize(partialWord));
        } else if (isCandidateForNonHyphenatedCompound && needFugenS && partialWord.length() > 2) {
            partialWord = partialWord.startsWith("s") ? partialWord.substring(1) : partialWord;
            return !hunspellDict.misspelled(partialWord)
                    || !hunspellDict.misspelled(StringUtils.capitalize(partialWord));
        }
        return false;
    }
    // hyphenated compound (e.g., "Feynman-Diagramm"):
    boolean hasIgnoredWord = false;
    List<String> toSpellCheck = new ArrayList<>(3);
    String stripFirst = word.substring(words[0].length() + 1); // everything after the first "-"
    String stripLast = word.substring(0, word.length() - words[words.length - 1].length() - 1); // everything up to the last "-"

    if (super.ignoreWord(stripFirst) || wordsToBeIgnoredInCompounds.contains(stripFirst)) { // e.g., "Senioren-Au-pair"
        hasIgnoredWord = true;
        if (!super.ignoreWord(words[0])) {
            toSpellCheck.add(words[0]);
        }
    } else if (super.ignoreWord(stripLast) || wordsToBeIgnoredInCompounds.contains(stripLast)) { // e.g., "Au-pair-Agentur"
        hasIgnoredWord = true;
        if (!super.ignoreWord(words[words.length - 1])) {
            toSpellCheck.add(words[words.length - 1]);
        }
    } else {
        for (String word1 : words) {
            if (super.ignoreWord(word1) || wordsToBeIgnoredInCompounds.contains(word1)) {
                hasIgnoredWord = true;
            } else {
                toSpellCheck.add(word1);
            }
        }
    }

    if (hasIgnoredWord) {
        for (String w : toSpellCheck) {
            if (hunspellDict.misspelled(w)) {
                return false;
            }
        }
    }
    return hasIgnoredWord;
}

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

@Override
protected boolean isAcceptedWordFromLanguage(Language language, String word) {
    // probably an abbreviation, e.g. "DOE" -> "Department of Energy"
    return "en".equals(language.getShortCode()) && StringUtils.isAllUpperCase(word);
}