Example usage for java.lang Character isLowerCase

List of usage examples for java.lang Character isLowerCase

Introduction

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

Prototype

public static boolean isLowerCase(int codePoint) 

Source Link

Document

Determines if the specified character (Unicode code point) is a lowercase character.

Usage

From source file:Strings.java

/**
 * Returns <code>true</code> if the first character in the
 * specified array is an upper case letter and all subsequent
 * characters are lower case letters.//from w w  w . j  a va2s.co  m
 *
 * @param chars Array of characters to test.
 * @return <code>true</code> if all of the characters in the
 * specified array are lower case letters.
 */
public static boolean capitalized(char[] chars) {
    if (chars.length == 0)
        return false;
    if (!Character.isUpperCase(chars[0]))
        return false;
    for (int i = 1; i < chars.length; ++i)
        if (!Character.isLowerCase(chars[i]))
            return false;
    return true;
}

From source file:Main.java

/**
 * Returns whether the string supplied could be used as a valid XML name.
 * @param name The string to test for XML name validity.
 * @return true if the string can be used as a valid XML name, false otherwise.
 *///from w  w w .j a va2s  .co  m
public static boolean isValidXMLName(String name) {
    String trimmedName = name.trim();

    boolean currentCharacterValid;

    if (name == null || trimmedName.length() == 0) {
        return false;
    }

    // ensure that XML standard reserved names are not used

    if (trimmedName.toUpperCase().startsWith("XML")) {
        return false;
    }

    // test that name starts with a valid XML name-starting character

    if (!Character.isUpperCase(trimmedName.charAt(0)) && !Character.isLowerCase(trimmedName.charAt(0))
            && trimmedName.charAt(0) != '_') {
        return false;
    }

    // test that remainder name chars are a valid XML name characters 

    if (name.trim().length() > 0) {
        for (int i = 1; i < trimmedName.length(); i++) {
            currentCharacterValid = false;

            if (Character.isUpperCase(trimmedName.charAt(i)) || Character.isLowerCase(trimmedName.charAt(i))
                    || Character.isDigit(trimmedName.charAt(i))) {
                currentCharacterValid = true;
            }

            if (trimmedName.charAt(i) == '_' || trimmedName.charAt(i) == '-' || trimmedName.charAt(i) == '.') {
                currentCharacterValid = true;
            }

            if (!currentCharacterValid) {
                return false;
            }
        }
    }
    return true;
}

From source file:Main.java

/**
 * Checks the password against a set of rules to determine whether it is
 * considered weak.  The rules are://ww  w .j a  v a 2s. c o m
 * </p><p>
 * <ul>
 *   <li>It is at least <code>MIN_PASSWORD_LEN</code> characters long.
 *   <li>At least one lowercase character.
 *   <li>At least one uppercase character.
 *   <li>At least one digit or symbol character.
 * </ul>
 *
 * @param password the password to check.
 *
 * @return <code>true</code> if the password is considered to be weak,
 *         <code>false</code> otherwise.
 */
public static boolean isWeakPassword(String password) {
    boolean hasUC = false;
    boolean hasLC = false;
    boolean hasDigit = false;
    boolean hasSymbol = false;

    if (password.length() < MIN_PASSWORD_LEN) {
        return true;
    }

    for (int ii = 0; ii < password.length(); ++ii) {
        char c;

        c = password.charAt(ii);

        if (Character.isDigit(c))
            hasDigit = true;
        else if (Character.isUpperCase(c))
            hasUC = true;
        else if (Character.isLowerCase(c))
            hasLC = true;
        else
            hasSymbol = true;
    }

    return !(hasUC && hasLC && (hasDigit || hasSymbol));
}

From source file:Main.java

/**
 * Returns attribute's getter method. If the method not found then
 * NoSuchMethodException will be thrown.
 * //from  ww  w.  j a va  2 s.co  m
 * @param cls
 *          the class the attribute belongs too
 * @param attr
 *          the attribute's name
 * @return attribute's getter method
 * @throws NoSuchMethodException
 *           if the getter was not found
 */
public final static Method getAttributeGetter(Class cls, String attr) throws NoSuchMethodException {
    StringBuffer buf = new StringBuffer(attr.length() + 3);
    buf.append("get");
    if (Character.isLowerCase(attr.charAt(0))) {
        buf.append(Character.toUpperCase(attr.charAt(0))).append(attr.substring(1));
    } else {
        buf.append(attr);
    }

    try {
        return cls.getMethod(buf.toString(), (Class[]) null);
    } catch (NoSuchMethodException e) {
        buf.replace(0, 3, "is");
        return cls.getMethod(buf.toString(), (Class[]) null);
    }
}

From source file:Main.java

/**
 * Returns attribute's setter method. If the method not found then
 * NoSuchMethodException will be thrown.
 * //from  w  ww  .  j  a va2 s.  c o m
 * @param cls
 *          the class the attribute belongs to
 * @param attr
 *          the attribute's name
 * @param type
 *          the attribute's type
 * @return attribute's setter method
 * @throws NoSuchMethodException
 *           if the setter was not found
 */
public final static Method getAttributeSetter(Class cls, String attr, Class type) throws NoSuchMethodException {
    StringBuffer buf = new StringBuffer(attr.length() + 3);
    buf.append("set");
    if (Character.isLowerCase(attr.charAt(0))) {
        buf.append(Character.toUpperCase(attr.charAt(0))).append(attr.substring(1));
    } else {
        buf.append(attr);
    }

    return cls.getMethod(buf.toString(), new Class[] { type });
}

From source file:Main.java

/**
 * <p>// www.ja v  a2  s.c  o  m
 * Swaps the case of String.
 * </p>
 * <p/>
 * <p>
 * Properly looks after making sure the start of words are Titlecase and not Uppercase.
 * </p>
 * <p/>
 * <p>
 * <code>null</code> is returned as <code>null</code>.
 * </p>
 *
 * @param str the String to swap the case of
 * @return the modified String
 */
public static String swapCase(String str) {
    if (str == null) {
        return null;
    }
    int sz = str.length();
    StringBuilder buffer = new StringBuilder(sz);

    boolean whitespace = false;
    char ch;
    char tmp;

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

From source file:de.rnd7.kata.reversi.logic.ai.AIMatrix.java

private static void processLine(final AIMatrix matrix, final int y, final String line) {
    int x = 0;/*from  w  w w  .j a va2s. c om*/
    for (final char ch : line.toCharArray()) {
        final int weight;
        if (Character.isLowerCase(ch)) {
            weight = -Character.toUpperCase(ch);
        } else {
            weight = ch;
        }

        matrix.set(new Coordinate(x++, y), weight);
    }
}

From source file:com.threecrickets.jygments.grammar.Lexer.java

public static Lexer getByName(String name) throws ResolutionException {
    if ((name == null) || (name.length() == 0))
        name = "Lexer";
    else if (Character.isLowerCase(name.charAt(0)))
        name = Character.toUpperCase(name.charAt(0)) + name.substring(1) + "Lexer";

    Lexer lexer = getByFullName(name);/*from ww  w . j  a  v a 2s . c  om*/
    if (lexer != null)
        return lexer;
    else {
        // Try contrib package
        String pack = Jygments.class.getPackage().getName() + ".contrib";
        lexer = getByFullName(pack + "." + name);
        if (lexer == null) {
            // Try this package
            pack = Lexer.class.getPackage().getName();
            lexer = getByFullName(pack + "." + name);
        }
        return lexer;
    }
}

From source file:com.viettel.ws.client.JDBCUtil.java

public static String convertToOrigin(String s) {
    String newStr = "";
    for (char c : s.toCharArray()) {
        if (!Character.isDigit(c) && Character.isUpperCase(c)) {
            newStr += ("_" + String.valueOf(c));
        } else if (!Character.isDigit(c) && Character.isLowerCase(c)) {
            newStr += String.valueOf(c).toUpperCase();
        } else {/*  w ww  . jav  a 2  s. c  o  m*/
            newStr += String.valueOf(c);
        }
    }
    return newStr;
}

From source file:org.xaloon.core.api.util.TextUtil.java

/**
 * Parses class name into readable value
 * //from w w  w . ja  va  2  s  . co m
 * @param identifier
 *            string value which will be used to parse readable value
 * @return readable string value
 */
public static String parseName(String identifier) {
    // Check for a complex property.
    int idx = identifier.lastIndexOf('.');
    if (idx < 0) {
        idx = identifier.lastIndexOf('$'); // Java nested classes.
    }

    if (idx >= 0 && identifier.length() > 1) {
        identifier = identifier.substring(idx + 1);
    }

    if (identifier.length() == 0) {
        return DelimiterEnum.EMPTY.value();
    }

    char[] chars = identifier.toCharArray();
    StringBuilder buf = new StringBuilder(chars.length + 10);

    buf.append(chars[0]);
    boolean lastLower = false;
    for (int i = 1; i < chars.length; ++i) {
        if (!Character.isLowerCase(chars[i])) {
            // Lower to upper case transition -- add space before it
            if (lastLower) {
                buf.append(' ');
            }
        }

        buf.append(chars[i]);
        lastLower = Character.isLowerCase(chars[i]) || Character.isDigit(chars[i]);
    }
    String result = buf.toString().toLowerCase();
    if (result.lastIndexOf(DelimiterEnum.SPACE.value()) > 0) {
        result = result.substring(0, result.lastIndexOf(DelimiterEnum.SPACE.value()));
    }
    return result;
}