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.sjdf.platform.xss.StringUtils.java

/**
 * <p>/*  w  w w  .j a v  a 2  s.c o  m*/
 * Checks if the CharSequence contains only uppercase characters.
 * </p>
 * <p/>
 * <p>
 * {@code null} will return {@code false}. An empty String (length()=0) will
 * return {@code false}.
 * </p>
 * <p/>
 * <pre>
 * StringUtils.isAllUpperCase(null)   = false
 * StringUtils.isAllUpperCase("")     = false
 * StringUtils.isAllUpperCase("  ")   = false
 * StringUtils.isAllUpperCase("ABC")  = true
 * StringUtils.isAllUpperCase("aBC") = false
 * </pre>
 *
 * @param cs the CharSequence to check, may be null
 * @return {@code true} if only contains uppercase characters, and is
 * non-null
 * @since 3.0 Changed signature from isAllUpperCase(String) to
 * isAllUpperCase(CharSequence)
 */
public static boolean isAllUpperCase(CharSequence cs) {
    if (cs == null || isEmpty(cs)) {
        return false;
    }
    int sz = cs.length();
    for (int i = 0; i < sz; i++) {
        if (!Character.isUpperCase(cs.charAt(i))) {
            return false;
        }
    }
    return true;
}

From source file:org.apache.commons.lang3.StringUtils.java

/**
 * <p>Checks if the CharSequence contains only uppercase characters.</p>
 *
 * <p>{@code null} will return {@code false}.
 * An empty String (length()=0) will return {@code false}.</p>
 *
 * <pre>//from   ww w.j ava  2s.c  o m
 * StringUtils.isAllUpperCase(null)   = false
 * StringUtils.isAllUpperCase("")     = false
 * StringUtils.isAllUpperCase("  ")   = false
 * StringUtils.isAllUpperCase("ABC")  = true
 * StringUtils.isAllUpperCase("aBC") = false
 * </pre>
 *
 * @param cs the CharSequence to check, may be null
 * @return {@code true} if only contains uppercase characters, and is non-null
 * @since 2.5
 * @since 3.0 Changed signature from isAllUpperCase(String) to isAllUpperCase(CharSequence)
 */
public static boolean isAllUpperCase(CharSequence cs) {
    if (cs == null || isEmpty(cs)) {
        return false;
    }
    int sz = cs.length();
    for (int i = 0; i < sz; i++) {
        if (Character.isUpperCase(cs.charAt(i)) == false) {
            return false;
        }
    }
    return true;
}

From source file:net.bashtech.geobot.ReceiverBot.java

private int getCapsNumber(String s) {
    int caps = 0;
    for (int i = 0; i < s.length(); i++) {
        if (Character.isUpperCase(s.charAt(i))) {
            caps++;//www .  j ava2 s . c om
        }
    }

    return caps;
}

From source file:com.rdm.common.util.StringUtils.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 w  w  w. jav  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 com.rdm.common.util.text.WordUtils#swapCase(String)}.
 * A {@code null} input String returns {@code null}.</p>
 *
 * <pre>
 * StringUtils.swapCase(null)                 = null
 * StringUtils.swapCase("")                   = ""
 * StringUtils.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(final String str) {
    if (StringUtils.isEmpty(str)) {
        return str;
    }

    final char[] buffer = str.toCharArray();

    for (int i = 0; i < buffer.length; i++) {
        final 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:com.clark.func.Functions.java

/**
 * <p>/*  www .j  a v a  2s .  co  m*/
 * Swaps the case of a String changing upper and title case to lower case,
 * and lower case to upper case.
 * </p>
 * 
 * <ul>
 * <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</code> input String returns <code>null</code>.
 * </p>
 * 
 * <pre>
 * swapCase(null)                 = null
 * swapCase("")                   = ""
 * 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</code> if null String input
 */
public static String swapCase(String str) {
    int strLen;
    if (str == null || (strLen = str.length()) == 0) {
        return str;
    }
    StringBuilder buffer = new StringBuilder(strLen);

    char ch = 0;
    for (int i = 0; i < strLen; i++) {
        ch = str.charAt(i);
        if (Character.isUpperCase(ch)) {
            ch = Character.toLowerCase(ch);
        } else if (Character.isTitleCase(ch)) {
            ch = Character.toLowerCase(ch);
        } else if (Character.isLowerCase(ch)) {
            ch = Character.toUpperCase(ch);
        }
        buffer.append(ch);
    }
    return buffer.toString();
}

From source file:com.zimbra.cs.account.ldap.LdapProvisioning.java

/**
 * called to check password strength. Should pass in either an Account, or Cos/Attributes (during creation).
 *
 * @param password/*from   w  w w .j a  v  a  2s . c o  m*/
 * @param acct
 * @param cos
 * @param attrs
 * @throws ServiceException
 */
private void checkPasswordStrength(String password, Account acct, Cos cos, ZMutableEntry entry)
        throws ServiceException {
    int minLength = getInt(acct, cos, entry, Provisioning.A_zimbraPasswordMinLength, 0);
    if (minLength > 0 && password.length() < minLength) {
        throw AccountServiceException.INVALID_PASSWORD("too short",
                new Argument(Provisioning.A_zimbraPasswordMinLength, minLength, Argument.Type.NUM));
    }

    int maxLength = getInt(acct, cos, entry, Provisioning.A_zimbraPasswordMaxLength, 0);
    if (maxLength > 0 && password.length() > maxLength) {
        throw AccountServiceException.INVALID_PASSWORD("too long",
                new Argument(Provisioning.A_zimbraPasswordMaxLength, maxLength, Argument.Type.NUM));
    }

    int minUpperCase = getInt(acct, cos, entry, Provisioning.A_zimbraPasswordMinUpperCaseChars, 0);
    int minLowerCase = getInt(acct, cos, entry, Provisioning.A_zimbraPasswordMinLowerCaseChars, 0);
    int minNumeric = getInt(acct, cos, entry, Provisioning.A_zimbraPasswordMinNumericChars, 0);
    int minPunctuation = getInt(acct, cos, entry, Provisioning.A_zimbraPasswordMinPunctuationChars, 0);
    int minAlpha = getInt(acct, cos, entry, Provisioning.A_zimbraPasswordMinAlphaChars, 0);
    int minNumOrPunc = getInt(acct, cos, entry, Provisioning.A_zimbraPasswordMinDigitsOrPuncs, 0);

    String allowedChars = getString(acct, cos, entry, Provisioning.A_zimbraPasswordAllowedChars);
    Pattern allowedCharsPattern = null;
    if (allowedChars != null) {
        try {
            allowedCharsPattern = Pattern.compile(allowedChars);
        } catch (PatternSyntaxException e) {
            throw AccountServiceException.INVALID_PASSWORD(
                    Provisioning.A_zimbraPasswordAllowedChars + " is not valid regex: " + e.getMessage());
        }
    }
    String allowedPuncChars = getString(acct, cos, entry, Provisioning.A_zimbraPasswordAllowedPunctuationChars);
    Pattern allowedPuncCharsPattern = null;
    if (allowedPuncChars != null) {
        try {
            allowedPuncCharsPattern = Pattern.compile(allowedPuncChars);
        } catch (PatternSyntaxException e) {
            throw AccountServiceException.INVALID_PASSWORD(Provisioning.A_zimbraPasswordAllowedPunctuationChars
                    + " is not valid regex: " + e.getMessage());
        }
    }

    boolean hasPolicies = minUpperCase > 0 || minLowerCase > 0 || minNumeric > 0 || minPunctuation > 0
            || minAlpha > 0 || minNumOrPunc > 0 || allowedCharsPattern != null
            || allowedPuncCharsPattern != null;

    if (!hasPolicies) {
        return;
    }

    int upper = 0;
    int lower = 0;
    int numeric = 0;
    int punctuation = 0;
    int alpha = 0;

    for (int i = 0; i < password.length(); i++) {
        char ch = password.charAt(i);

        if (allowedCharsPattern != null) {
            if (!allowedCharsPattern.matcher(Character.toString(ch)).matches()) {
                throw AccountServiceException.INVALID_PASSWORD(ch + " is not an allowed character",
                        new Argument(Provisioning.A_zimbraPasswordAllowedChars, allowedChars,
                                Argument.Type.STR));
            }
        }

        boolean isAlpha = true;
        if (Character.isUpperCase(ch)) {
            upper++;
        } else if (Character.isLowerCase(ch)) {
            lower++;
        } else if (Character.isDigit(ch)) {
            numeric++;
            isAlpha = false;
        } else if (allowedPuncCharsPattern != null) {
            if (allowedPuncCharsPattern.matcher(Character.toString(ch)).matches()) {
                punctuation++;
                isAlpha = false;
            }
        } else if (isAsciiPunc(ch)) {
            punctuation++;
            isAlpha = false;
        }
        if (isAlpha) {
            alpha++;
        }
    }

    if (upper < minUpperCase) {
        throw AccountServiceException.INVALID_PASSWORD("not enough upper case characters",
                new Argument(Provisioning.A_zimbraPasswordMinUpperCaseChars, minUpperCase, Argument.Type.NUM));
    }
    if (lower < minLowerCase) {
        throw AccountServiceException.INVALID_PASSWORD("not enough lower case characters",
                new Argument(Provisioning.A_zimbraPasswordMinLowerCaseChars, minLowerCase, Argument.Type.NUM));
    }
    if (numeric < minNumeric) {
        throw AccountServiceException.INVALID_PASSWORD("not enough numeric characters",
                new Argument(Provisioning.A_zimbraPasswordMinNumericChars, minNumeric, Argument.Type.NUM));
    }
    if (punctuation < minPunctuation) {
        throw AccountServiceException.INVALID_PASSWORD("not enough punctuation characters", new Argument(
                Provisioning.A_zimbraPasswordMinPunctuationChars, minPunctuation, Argument.Type.NUM));
    }
    if (alpha < minAlpha) {
        throw AccountServiceException.INVALID_PASSWORD("not enough alpha characters",
                new Argument(Provisioning.A_zimbraPasswordMinAlphaChars, minAlpha, Argument.Type.NUM));
    }
    if (numeric + punctuation < minNumOrPunc) {
        throw AccountServiceException.INVALID_PASSWORD("not enough numeric or punctuation characters",
                new Argument(Provisioning.A_zimbraPasswordMinDigitsOrPuncs, minNumOrPunc, Argument.Type.NUM));
    }
}

From source file:bfile.util.StringUtils.java

/**
 * <p>Swaps the case of a String changing upper and title case to
 * lower case, and lower case to upper case.</p>
 *
 * <ul>/*w w w .  ja  v  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>
 * StringUtils.swapCase(null)                 = null
 * StringUtils.swapCase("")                   = ""
 * StringUtils.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(final String str) {
    if (StringUtils.isEmpty(str)) {
        return str;
    }

    final int strLen = str.length();
    int newCodePoints[] = new int[strLen]; // cannot be longer than the char array
    int outOffset = 0;
    for (int i = 0; i < strLen;) {
        final int oldCodepoint = str.codePointAt(i);
        final int newCodePoint;
        if (Character.isUpperCase(oldCodepoint)) {
            newCodePoint = Character.toLowerCase(oldCodepoint);
        } else if (Character.isTitleCase(oldCodepoint)) {
            newCodePoint = Character.toLowerCase(oldCodepoint);
        } else if (Character.isLowerCase(oldCodepoint)) {
            newCodePoint = Character.toUpperCase(oldCodepoint);
        } else {
            newCodePoint = oldCodepoint;
        }
        newCodePoints[outOffset++] = newCodePoint;
        i += Character.charCount(newCodePoint);
    }
    return new String(newCodePoints, 0, outOffset);
}

From source file:bfile.util.StringUtils.java

/**
 * <p>Checks if the CharSequence contains only uppercase characters.</p>
 *
 * <p>{@code null} will return {@code false}.
 * An empty String (length()=0) will return {@code false}.</p>
 *
 * <pre>/*  w  ww .j ava2  s .c o  m*/
 * StringUtils.isAllUpperCase(null)   = false
 * StringUtils.isAllUpperCase("")     = false
 * StringUtils.isAllUpperCase("  ")   = false
 * StringUtils.isAllUpperCase("ABC")  = true
 * StringUtils.isAllUpperCase("aBC")  = false
 * StringUtils.isAllUpperCase("A C")  = false
 * StringUtils.isAllUpperCase("A1C")  = false
 * StringUtils.isAllUpperCase("A/C")  = false
 * </pre>
 *
 * @param cs the CharSequence to check, may be null
 * @return {@code true} if only contains uppercase characters, and is non-null
 * @since 2.5
 * @since 3.0 Changed signature from isAllUpperCase(String) to isAllUpperCase(CharSequence)
 */
public static boolean isAllUpperCase(final CharSequence cs) {
    if (cs == null || isEmpty(cs)) {
        return false;
    }
    final int sz = cs.length();
    for (int i = 0; i < sz; i++) {
        if (Character.isUpperCase(cs.charAt(i)) == false) {
            return false;
        }
    }
    return true;
}

From source file:org.openTwoFactor.client.util.TwoFactorClientCommonUtils.java

/**
 * lower the first letter of the string.  if input HelloThere, the output is helloThere
 * @param input//from  www .  j  a v a  2s.  c  om
 * @return the result
 */
public static String lowerFirstLetter(String input) {
    if (input == null || input.length() < 1) {
        return input;
    }

    char firstChar = input.charAt(0);
    if (Character.isUpperCase(firstChar)) {
        return Character.toLowerCase(firstChar) + input.substring(1);
    }

    return input;

}

From source file:sandbox.perspecting.JSONBasedDBPediaSerializer.java

@SuppressWarnings("unchecked")
private JSONObject getLinkedDataInfo(String uri) throws Exception {

    SailRepository sr = new SailRepository(new MemoryStore());
    SailRepositoryConnection conn;//from   w  w w  .  ja v a  2 s . c  o m
    sr.initialize();
    conn = sr.getConnection();

    JSONObject json = new JSONObject();

    System.out.println("Lookup: " + uri);

    // hack to get data from local DBpedia mirror

    String urlString = uri.replaceFirst("http://dbpedia.org/resource/", "http://" + dbpediaMirror + "/data/");

    URL url = new URL(urlString);

    // only absolute URIs are assumed
    conn.add(url, "", RDFFormat.RDFXML);

    for (Statement stmt : conn.getStatements(null,
            new URIImpl("http://" + dbpediaMirror + "/ontology/wikiPageRedirects"), null, false).asList()) {
        sr = new SailRepository(new MemoryStore());
        sr.initialize();
        conn = sr.getConnection();

        uri = stmt.getObject().stringValue().replace("resource", "data");

        System.out.println("Found redirect from " + url + " to " + stmt.getObject().stringValue());
        conn.add(new URL(uri), "", RDFFormat.RDFXML);
    }

    System.out.println("found " + conn.size() + " triples.");
    json.put("_uri", uri);
    json.put("group", uri.hashCode());

    for (Statement stmt : conn
            .getStatements(new URIImpl(uri.replaceFirst("data", "resource")), null, null, false).asList()) {

        String predicate = stmt.getPredicate().toString()
                .substring(stmt.getPredicate().toString().lastIndexOf("/") + 1);

        predicate = predicate.substring(predicate.indexOf("#") + 1);

        String predicate2 = "";

        for (char c : predicate.toCharArray()) {
            if (Character.isUpperCase(c)) {
                predicate2 += " ";
            }
            predicate2 += Character.toLowerCase(c);
        }

        predicate = predicate2;

        if (stmt.getObject() instanceof Literal) {
            String object = stmt.getObject().stringValue();
            if (!object.contains("px") && !object.contains("{")) {

                if (predicate.equals("abstract") || predicate.equals("comment")) {
                    int i = stmt.getObject().stringValue().indexOf(". ");
                    if (i > 0) {
                        json.put("_abstract", stmt.getObject().stringValue().substring(0, i));
                    } else {
                        json.put("_abstract", stmt.getObject().stringValue());
                    }
                } else if (predicate.contains(" ")) {
                    json.put(predicate, stmt.getObject().stringValue());
                }
            }
        } else if (predicate.equals("depiction")) {
            json.put("_img", stmt.getObject().stringValue());
        } else if (predicate.equals("page")) {
            json.put("_wikipedia", stmt.getObject().stringValue());
        } else if (!predicate.endsWith("same as") && !predicate.endsWith("thumbnail")) {

            String object = stmt.getObject().stringValue()
                    .substring(stmt.getObject().stringValue().lastIndexOf("/") + 1);
            if (!object.contains(":") && !predicate.startsWith("wiki")) {
                json.put(predicate, object.replaceAll("_", " "));
            }
        }

    }

    return json;
}