Example usage for java.lang Character isLetter

List of usage examples for java.lang Character isLetter

Introduction

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

Prototype

public static boolean isLetter(int codePoint) 

Source Link

Document

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

Usage

From source file:me.ryanhamshire.PopulationDensity.PopulationDensity.java

String getRegionNameError(String name, boolean console) {
    if (name.length() > this.maxRegionNameLength) {
        if (console)
            return "Name too long.";
        else//from   w  w  w. java2 s .  co  m
            return this.dataStore.getMessage(Messages.RegionNameLength, String.valueOf(maxRegionNameLength));
    }

    for (int i = 0; i < name.length(); i++) {
        char c = name.charAt(i);
        if (!Character.isLetter(c) && !Character.isDigit(c) && c != ' ') {
            if (console)
                return "Name includes symbols or puncutation.";
            else
                return this.dataStore.getMessage(Messages.RegionNamesOnlyLettersAndNumbers);
        }
    }

    return null;
}

From source file:org.zanata.action.ProjectHome.java

/**
 * Check the name by removing any whitespaces in the string and
 * make sure it contains at least an alphanumeric char
 *///  w ww .java2s . co  m
public boolean isValidName(String name) {
    String trimmedName = StringUtils.deleteWhitespace(name);
    for (char c : trimmedName.toCharArray()) {
        if (Character.isDigit(c) || Character.isLetter(c)) {
            return true;
        }
    }
    return false;
}

From source file:com.ruesga.rview.SearchActivity.java

@SuppressWarnings("Convert2streamapi")
private void requestCustomSuggestions(String filter) {
    // Do no perform suggestion when there are selection or cursor is not at the end
    // of the textview
    if (mBinding.searchView.getSelectionStart() != mBinding.searchView.getSelectionStart()
            || mBinding.searchView.getSelectionStart() < mBinding.searchView.getText().length()) {
        clearSuggestions();/*from w w w.j  a v  a 2 s.  co  m*/
        return;
    }

    // Extract the current filter
    int pos = filter.lastIndexOf(" ");
    pos = pos == -1 ? 0 : ++pos;
    String currentFilter = filter.substring(pos);
    String partial = filter.substring(0, pos);

    // Some sanitize checks
    if (TextUtils.isEmpty(currentFilter)) {
        clearSuggestions();
        return;
    }
    char c = filter.charAt(pos);
    if (!Character.isLetter(c) && !Character.isDigit(c)) {
        clearSuggestions();
        return;
    }

    // Extract the token
    pos = currentFilter.indexOf(":");
    if (pos != -1) {
        String token = currentFilter.substring(0, pos);
        currentFilter = currentFilter.substring(pos + 1);
        partial += token + ":";
        if (TextUtils.isEmpty(currentFilter)) {
            clearSuggestions();
            return;
        }

        final int index = Arrays.asList(ChangeQuery.FIELDS_NAMES).indexOf(token);
        if (index != -1) {
            Double version = ChangeQuery.SUPPORTED_VERSION[index];
            ServerVersion serverVersion = mAccount.getServerVersion();
            if (version == null || (serverVersion != null && version <= serverVersion.getVersion())) {
                Class clazz = ChangeQuery.SUGGEST_TYPES[index];
                if (clazz != null) {
                    if (clazz.equals(AccountInfo.class)) {
                        requestAccountSuggestions(currentFilter, partial);
                        return;
                    } else if (clazz.equals(ProjectInfo.class)) {
                        requestProjectSuggestions(currentFilter, partial);
                        return;
                    }
                }
            }
        }
    }

    final List<Suggestion> suggestions = new ArrayList<>();
    String f = partial + currentFilter;
    pos = f.trim().lastIndexOf(" ");
    if (pos != -1) {
        partial = f.substring(0, pos + 1);
        f = f.substring(pos + 1);
    } else if (f.contains(":")) {
        partial = "";
    }
    for (String s : mSuggestions) {
        if (s.startsWith(f) && !s.trim().equals(f)) {
            suggestions.add(new Suggestion(f, partial, s, null, R.drawable.ic_search, false));
        }
    }
    mBinding.searchView.swapSuggestions(suggestions);
}

From source file:org.opensextant.util.TextUtils.java

/**
 * Normalization: Clean the ends, Remove Line-endings from middle of entity.
 *
 * <pre>/*from   w ww .ja  v a  2  s.  c o  m*/
 *  Example:
 *        TEXT: **The Daily Newsletter of \n\rBarbara, So.**
 *       CLEAN: __The Daily Newsletter of __Barbara, So___
 *
 * Where "__" represents omitted characters.
 * </pre>
 * 
 * @param str
 *            text
 * @return scrubbed text
 */
public static String normalizeTextEntity(String str) {
    if (isBlank(str)) {
        return "";
    }

    char[] chars = str.toCharArray();

    int s1 = 0, s2 = chars.length - 1;
    int end = s2;

    while (s1 < s2 && !(Character.isLetter(chars[s1]) || Character.isDigit(chars[s1]))) {
        ++s1;
    }

    // No text found
    if (s1 == s2) {
        return null;
    }

    while (s2 > s1 && !(Character.isLetter(chars[s2]) || Character.isDigit(chars[s2]))) {
        --s2;
    }

    if (s1 == 0 && s2 == end) {
        // No cleanup to do.
        return squeeze_whitespace(str);
    }

    // NOT possible, I hope...
    if (s2 <= s1) {
        return "";
    }

    // Some cleanup was done on ends of String. Now clear up whitespace.
    //
    return squeeze_whitespace(str.substring(s1, s2 + 1));
}

From source file:net.java.sip.communicator.gui.AuthenticationSplash.java

public boolean valid() {
    int idx;/*from ww  w.j a v  a 2  s.co m*/
    boolean usern = true, pwd = true, nme = true, lnme = true, ml = true;
    // Username checks

    // Starts with a letter
    if (userName.length() == 0)
        usern = false;
    else if (!Character.isLetter(userName.charAt(0)))
        usern = false;

    // Contains only letters and numbers
    for (idx = 0; idx < userName.length(); idx++) {
        if (!Character.isLetterOrDigit(userName.charAt(idx)))
            usern = false;
    }

    // Is between 4 and 10 characters
    if ((userName.length() < 4) || (userName.length() > 18))
        usern = false;

    // Name and last name checks

    // Both begin with uppercase
    if (name.length() == 0)
        nme = false;
    else if (!Character.isUpperCase(name.charAt(0)))
        nme = false;

    if (lastName.length() == 0)
        lnme = false;
    else if (!Character.isUpperCase(lastName.charAt(0)))
        lnme = false;

    // Both contain only letters
    for (idx = 0; idx < name.length(); idx++) {
        if (!Character.isLetter(name.charAt(idx)))
            nme = false;
    }

    for (idx = 0; idx < lastName.length(); idx++) {
        if (!Character.isLetter(lastName.charAt(idx)))
            lnme = false;
    }

    // Mail chekcs
    Pattern ptr = Pattern.compile(
            "(?:(?:\\r\\n)?[ \\t])*(?:(?:(?:[^()<>@,;:\\\\\".\\[\\] \\000-\\031]+(?:(?:(?:\\r\\n)?[ \\t])+|\\Z|(?=[\\[\"()<>@,;:\\\\\".\\[\\]]))|\"(?:[^\\\"\\r\\\\]|\\\\.|(?:(?:\\r\\n)?[ \\t]))*\"(?:(?:\\r\\n)?[ \\t])*)(?:\\.(?:(?:\\r\\n)?[ \\t])*(?:[^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\\r\\\\]|\\\\.)*\\](?:(?:\\r\\n)?[ \\t])*))*)*:(?:(?:\\r\\n)?[ \\t])*)?(?:[^()<>@,;:\\\\\".\\[\\] \\000-\\031]+(?:(?:(?:\\r\\n)?[ \\t])+|\\Z|(?=[\\[\"()<>@,;:\\\\\".\\[\\]]))|\"(?:[^\\\"\\r\\\\]|\\\\.|(?:(?:\\r\\n)?[ \\t]))*\"(?:(?:\\r\\n)?[ \\t])*)(?:\\.(?:(?:\\r\\n)?[ \\t])*(?:[^()<>@,;:\\\\\".\\[\\] \\000-\\031]+(?:(?:(?:\\r\\n)?[ \\t])+|\\Z|(?=[\\[\"()<>@,;:\\\\\".\\[\\]]))|\"(?:[^\\\"\\r\\\\]|\\\\.|(?:(?:\\r\\n)?[ \\t]))*\"(?:(?:\\r\\n)?[ \\t])*))*@(?:(?:\\r\\n)?[ \\t])*(?:[^()<>@,;:\\\\\".\\[\\] \\000-\\031]+(?:(?:(?:\\r\\n)?[ \\t])+|\\Z|(?=[\\[\"()<>@,;:\\\\\".\\[\\]]))|\\[([^\\[\\]\\r\\\\]|\\\\.)*\\](?:(?:\\r\\n)?[ \\t])*)(?:\\.(?:(?:\\r\\n)?[ \\t])*(?:[^()<>@,;:\\\\\".\\[\\] \\000-\\031]+(?:(?:(?:\\r\\n)?[ \\t])+|\\Z|(?=[\\[\"()<>@,;:\\\\\".\\[\\]]))|\\[([^\\[\\]\\r\\\\]|\\\\.)*\\](?:(?:\\r\\n)?[ \\t])*))*\\>(?:(?:\\r\\n)?[ \\t])*))*)?;\\s*)");
    if (!ptr.matcher(mail).matches())
        ml = false;

    // Password checks

    // Check that we have a variety of different characters
    boolean lower = false, upper = false, number = false, other = false;
    for (idx = 0; idx < password.length(); idx++) {
        if (Character.isUpperCase(password.charAt(idx)))
            upper = true;
        if (Character.isLowerCase(password.charAt(idx)))
            lower = true;
        if (!Character.isLetterOrDigit(password.charAt(idx)))
            other = true;
        if (Character.isDigit(password.charAt(idx)))
            number = true;
    }
    if (!(upper && lower && number && other))
        pwd = false;

    // Verify that the size is acceptable
    if (password.length() < 6 || password.length() > 30)
        pwd = false;

    // Change the label colors
    if (!nme) {
        nameLabel.setForeground(Color.RED);
        nameTextField.setText("");
    }

    if (!lnme) {
        lastNameLabel.setForeground(Color.RED);
        lastNameTextField.setText("");
    }

    if (!ml) {
        mailLabel.setForeground(Color.RED);
        mailTextField.setText("");
    }

    if (!usern) {
        userNameLabel.setForeground(Color.RED);
        userNameTextField.setText("");
    }

    if (!pwd) {
        passwordLabel.setForeground(Color.RED);
        passwordTextField.setText("");
    }

    if (!(nme && lnme && usern && ml && pwd))
        return false;

    return true;
}

From source file:practica1.Babage.java

private void cantidadClaveKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_cantidadClaveKeyTyped
    char c = evt.getKeyChar();
    if (Character.isLetter(c)) {
        getToolkit().beep();//from   w  w  w  .  ja  v  a  2  s .c o  m
        evt.consume();
    }
}

From source file:au.org.ala.delta.util.Utils.java

/**
 * The main job of this method is to terminate RTF control words with {}
 * instead of a space.//  ww  w .ja v a2s  . com
 */
// Not all cases are handled correctly in the current code.
// For example, text with \bin might not always give correct results
// A few other things, such as \'xx, should perhaps also be given
// explicit treatment, but should not substantially affect the outcome.
public static String despaceRtf(String text, boolean quoteDelims) {
    if (StringUtils.isEmpty(text)) {
        return "";
    }
    int srcPos;
    boolean inRTF = false;
    boolean inParam = false;
    boolean inUnicode = false;
    boolean bracketed = text.charAt(0) == '<' && text.charAt(text.length() - 1) == '>';

    StringBuilder outputText = new StringBuilder(text);
    if (bracketed) // If a "comment", temporarily chop off the terminating
                   // bracket
        outputText.setLength(outputText.length() - 1);
    for (srcPos = 0; srcPos < outputText.length(); ++srcPos) {
        char ch = outputText.charAt(srcPos);
        // Always convert a tab character into a \tab control word
        if (ch == '\t') {
            outputText.replace(srcPos, srcPos + 1, "\\tab{}");
            ch = '\\';
        }
        if (inRTF) {
            if (Character.isDigit(ch) || (!inParam && ch == '-')) {
                if (!inParam && outputText.charAt(srcPos - 1) == 'u' && outputText.charAt(srcPos - 2) == '\\')
                    inUnicode = true;
                inParam = true;
            } else if (inParam || !Character.isLetter(ch)) {
                boolean wasInUnicode = inUnicode;
                inUnicode = inParam = inRTF = false;
                if (Character.isSpaceChar(ch)) {
                    // Check for the absence of a control; when this
                    // happens,
                    // the terminating character IS the control word!
                    if (srcPos > 0 && outputText.charAt(srcPos - 1) == '\\') {
                        // \<NEWLINE> is treated as a \par control. We make
                        // this
                        // change here explicitly, to make it more apparent.
                        // But should we keep the <NEWLINE> character around
                        // as well,
                        // as a clue for breaking lines during output?
                        if (ch == '\n' || ch == '\r') {
                            // text.replace(--srcPos, 2, "\\par{}");
                            outputText.insert(srcPos, "par{}");
                            srcPos += 5;
                        }
                        // (Note that if we don't catch this here, replacing
                        // "\ " could yield
                        // "\{}" which is WRONG. But rather than just get
                        // rid of this, it
                        // is probably better to replace with {} to ensure
                        // that any preceding
                        // RTF is terminated)
                        else if (ch == ' ') {
                            outputText.replace(srcPos - 1, 2, "{}");
                        }
                    }
                    // This is the chief condition we are trying to fix.
                    // Terminate the RTF
                    // control phrase with {} instead of white space...
                    // But if the terminator is a new line, we keep it
                    // around
                    // for assistance in wrapping output lines.
                    // else if (ch == '\n')
                    // {
                    // text.insert(srcPos, "{}");
                    // srcPos += 2;
                    // }
                    else if (ch != '\n') {
                        outputText.setCharAt(srcPos, '{');
                        outputText.insert(++srcPos, '}');
                    }
                }
                // No reason to do the following. Probably better to leave
                // the
                // character quoted.
                // Reinstated 8 December 1999 because we need to be sure
                // all text is in a consistent state when linking characters
                // One exception - if the quoted character is a Unicode
                // "replacement"
                // character, we'd better leave it quoted.
                else if (ch == '\'' && !wasInUnicode && srcPos + 2 < outputText.length()) {
                    char[] buff = new char[3];
                    buff[0] = outputText.charAt(srcPos + 1);
                    buff[1] = outputText.charAt(srcPos + 2);
                    buff[2] = 0;

                    int[] endPos = new int[1];
                    int value = strtol(new String(buff), endPos, 16);
                    if ((endPos[0] == 2) && value > 127 && outputText.charAt(srcPos - 1) == '\\') {

                        srcPos--;
                        outputText.replace(srcPos, srcPos + 4, new String(new char[] { (char) value }));

                    }
                } else if (ch == '\\' && outputText.charAt(srcPos - 1) != '\\') // Terminates
                                                                                // RTF,
                                                                                // but
                                                                                // starts
                                                                                // new
                                                                                // RTF
                {
                    inRTF = true;
                    if (wasInUnicode && srcPos + 1 < outputText.length()
                            && outputText.charAt(srcPos + 1) == '\'')
                        inUnicode = true;
                } else if (ch == '>') {
                    // Append a space after the RTF (it was probably
                    // stripped by the attribute parsing)
                    outputText.insert(srcPos, "{}");
                }
            }
        } else if (ch == '\\')
            inRTF = true;
        // TEST - to allow outputting of a "*" or "#" character in arbitrary
        // text...
        else if (quoteDelims && (ch == '*' || ch == '#')
                && (srcPos == 0 || Character.isSpaceChar(outputText.charAt(srcPos - 1)))) {
            // //char buffer[5];
            // Always build a 4-character replacement string, like:
            // \'20
            // //sprintf(buffer, "\\\'%2.2x", (int)ch);
            // //text.replace(srcPos, buffer, 4);
            // //srcPos += 3;
            outputText.insert(srcPos, "{}");
            srcPos += 2;
        }
    }
    if (inRTF)
        outputText.append("{}");
    if (bracketed)
        outputText.append('>');
    return outputText.toString();
}

From source file:org.botlibre.util.Utils.java

/**
 * Compress the text to be a proper identifier within the size limit.
 * Replace space with '-' and remove any non alpha numerics.
 *//* www. j a va  2  s. c  om*/
public static String compress(String text, int size) {
    TextStream stream = new TextStream(text);
    StringWriter writer = new StringWriter(text.length());
    int count = 0;
    while (!stream.atEnd()) {
        if (count >= size) {
            break;
        }
        char next = stream.next();
        if (Character.isLetter(next) || Character.isDigit(next) || (next == '_')) {
            writer.write(next);
        } else {
            writer.write('_');
        }
        count++;
    }
    return writer.toString();
}

From source file:org.apache.geode.admin.jmx.internal.MBeanUtil.java

/** Returns true if the path is on Windows. */
static boolean pathIsWindows(String path) {
    if (path != null && path.length() > 1) {
        return (Character.isLetter(path.charAt(0)) && path.charAt(1) == ':')
                || (path.startsWith("//") || path.startsWith("\\\\"));
    }/* w  w  w.  j  a va2s. co m*/
    return false;
}

From source file:com.sfs.whichdoctor.dao.AddressVerificationDAOImpl.java

/**
 * Checks if the string is all upper case.
 *
 * @param s the string/*from  w  w w  .  j a v a  2s  .  c  o  m*/
 * @return true, if is all upper
 */
private static boolean isAllUpper(String s) {
    for (char c : s.toCharArray()) {
        if (Character.isLetter(c) && Character.isLowerCase(c)) {
            return false;
        }
    }
    return true;
}