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:org.cafed00d.subtitle.WordProcessor.java

/**
 * Examines the word and gather various statistics.
 *///from  www .  j  ava2 s  .  co  m
private void gatherStatistics() {
    while (current < line.length()
            && (Character.isLetter(line.charAt(current)) || line.charAt(current) == '\'')) {
        char ch = line.charAt(current);
        log.trace("@" + current + ":" + ch);
        if (Character.isUpperCase(ch)) {
            upperCount++;

            /*
             * We are interested in upper case I's only if they are not at the first
             * character position. Thus we will ignore words such as "I'll" and
             * words that start sentences.
             */
            if (current != first && ch == UPPER_I) {
                ICount++;
            }
        } else if (ch == '\'') {
            apostropheCount++;
        } else {
            lowerCount++;
            if (ch == LOWER_l) {
                lCount++;
            }
        }
        current++;
    }
}

From source file:com.openedit.users.filesystem.MapPropertyContainer.java

/**
 * Determine whether the given name is valid.  In order to be a valid name, the first character
 * must be a letter or underscore, and each subsequent character must be a letter, digit,
 * underscore, or period.//from  w  w w . j  a v a2 s .  c  o  m
 *
 * @param inName The name to query
 *
 * @return <code>true</code> if the name is valid, <code>false</code> if not
 */
protected boolean isValidName(String inName) {
    if ((inName == null) || (inName.length() == 0)) {
        return false;
    }

    char c = inName.charAt(0);

    if ((c == '_') || Character.isLetter(c)) {
        for (int i = 1; i < inName.length(); i++) {
            c = inName.charAt(i);

            if ((c != '_') && (c != '.') && !Character.isLetter(c) && !Character.isDigit(c)) {
                return false;
            }
        }
    }

    return true;
}

From source file:nz.ac.otago.psyanlab.common.designer.program.operand.RenameOperandDialogueFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    Bundle args = getArguments();/*  ww w.  j a  va 2s . c  om*/
    if (args != null) {
        mOperandId = args.getLong(ARG_OPERAND_ID, -1);
    }

    if (mOperandId == -1) {
        throw new RuntimeException("Invalid operand id.");
    }

    mOperand = mCallbacks.getOperand(mOperandId);

    LayoutInflater inflater = getActivity().getLayoutInflater();
    View view = inflater.inflate(R.layout.dialogue_rename_variable, null);
    mName = (EditText) view.findViewById(R.id.name);
    mName.setText(mOperand.getName());

    // Thanks to serwus <http://stackoverflow.com/users/1598308/serwus>,
    // who posted at <http://stackoverflow.com/a/20325852>. Modified to
    // support unicode codepoints and validating first character of input.
    InputFilter filter = new InputFilter() {
        @Override
        public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart,
                int dend) {
            boolean keepOriginal = true;
            StringBuilder sb = new StringBuilder(end - start);

            int offset = 0;
            String s = source.toString();

            while (offset < s.length()) {
                final int codePoint = s.codePointAt(offset);
                if ((offset == 0 && isAllowedAsFirst(codePoint)) || (offset > 0 && isAllowed(codePoint))) {
                    sb.appendCodePoint(codePoint);
                } else {
                    keepOriginal = false;
                }
                offset += Character.charCount(codePoint);
            }

            if (keepOriginal)
                return null;
            else {
                if (source instanceof Spanned) {
                    SpannableString sp = new SpannableString(sb);
                    TextUtils.copySpansFrom((Spanned) source, start, sb.length(), null, sp, 0);
                    return sp;
                } else {
                    return sb;
                }
            }
        }

        private boolean isAllowed(int codePoint) {
            return Character.isLetterOrDigit(codePoint);
        }

        private boolean isAllowedAsFirst(int codePoint) {
            return Character.isLetter(codePoint);
        }
    };

    mName.setFilters(new InputFilter[] { filter });

    // Build dialogue.
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setTitle(getString(R.string.title_rename_variable, mOperand.getName())).setView(view)
            .setPositiveButton(R.string.action_rename, mPositiveListener)
            .setNegativeButton(R.string.action_cancel, mNegativeListener);

    // Create the AlertDialog object and return it
    Dialog dialog = builder.create();
    dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
    return dialog;
}

From source file:com.stimulus.archiva.language.NGramProfile.java

/**
 * Analyze a piece of text/*from w ww  .  jav a2  s  . com*/
 * 
 * @param text the text to be analyzed
 */
public void analyze(StringBuffer text) {

    if (ngrams != null) {
        ngrams.clear();
        sorted = null;
        ngramcounts = null;
    }

    word.clear().append(SEPARATOR);
    for (int i = 0; i < text.length(); i++) {
        char c = Character.toLowerCase(text.charAt(i));

        if (Character.isLetter(c)) {
            add(word.append(c));
        } else {
            //found word boundary
            if (word.length() > 1) {
                //we have a word!
                add(word.append(SEPARATOR));
                word.clear().append(SEPARATOR);
            }
        }
    }

    if (word.length() > 1) {
        //we have a word!
        add(word.append(SEPARATOR));
    }
    normalize();
}

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:eu.sisob.uma.crawler.ResearchersCrawlers.CrawlerDepartamentsV3Controller.java

public CrawlerDepartamentsV3Controller(String storageFolder, File data_dir, List<String> subjects)
        throws Exception {
    super(storageFolder, false);

    wronk_link_keywords = new ArrayList<String>();
    link_keywords = new ArrayList<String>();
    link_departments_keywords = new ArrayList<String>();
    link_subdepartment_keywords = new ArrayList<String>();
    link_departments_type_keywords = new ArrayList<Map.Entry<String, String>>();

    interesting_urls_detected = new TreeMap<String, List<CandidateTypeURL>>();

    setKeyWordSeparator("/");

    /**/*from   ww w.  j  av  a 2  s.  c  o  m*/
     * ADDING KEYWORDS, ALL KEYWORD ARE PASSED THROUGH getCanonicalName function
     * Departments type key may have got many values separated by keyword_separator
     */
    List<String> lst = null;
    File f = null;
    try {
        f = new File(data_dir, DEPARTMENTS_RESULT_TAG + ".keywords");
        lst = FileUtils.readLines(f, "UTF-8");
        for (String keyword : lst) {
            keyword = CandidateTypeURL.getCanonicalName(keyword);
            addListLinkKeyWordsOfDepartmentsList(keyword);
        }
    } catch (Exception ex) {
        ProjectLogger.LOGGER.error(ex);
    }

    try {
        f = new File(data_dir, SUBDEPARTMENTS_RESULT_TAG + ".keywords");
        lst = FileUtils.readLines(f, "UTF-8");
        for (String keyword : lst) {
            keyword = CandidateTypeURL.getCanonicalName(keyword);
            addListLinkKeyWordsOfSubDepartmentsList(keyword);
        }
    } catch (Exception ex) {
        ProjectLogger.LOGGER.error(ex);
    }

    try {
        f = new File(data_dir, KEYWORDS_RESULT_TAG + ".keywords");
        lst = FileUtils.readLines(f, "UTF-8");
        for (String keyword : lst) {
            keyword = CandidateTypeURL.getCanonicalName(keyword);
            addListLinkKeyWords(keyword);
        }
    } catch (Exception ex) {
        ProjectLogger.LOGGER.error(ex);
    }

    try {
        f = new File(data_dir, WRONG_KEYWORDS_RESULT_TAG + ".keywords");
        lst = FileUtils.readLines(f, "UTF-8");
        for (String keyword : lst) {
            keyword = CandidateTypeURL.getCanonicalName(keyword);
            this.addListLinkWrongKeyWords(keyword);
        }
    } catch (Exception ex) {
        ProjectLogger.LOGGER.error(ex);
    }

    //Add subjects
    for (String subject : subjects) {
        String canonice_subject = "";
        for (String sub_subject : subject.split(keyword_separator)) {
            if (Character.isLetter(sub_subject.charAt(0)))
                addListLinkKeyWordsOfSubDepartmentsList(String.valueOf(sub_subject.charAt(0)));

            canonice_subject += keyword_separator + CandidateTypeURL.getCanonicalName(sub_subject);

        }

        addListLinkKeyWordsOfDepartmentsType(subject, canonice_subject.substring(1));
    }

    addPluraliceWords(this.getLstLinkKeyWordsOfDepartmentsType());

    if (CrawlerTrace.isTraceUrlsActive()) {
        try {
            String[] filenames = { WRONG_URLS_RESULT_TAG, KEYWORDS_RESULT_TAG, WRONG_KEYWORDS_RESULT_TAG,
                    SUBDEPARTMENTS_RESULT_TAG, DEPARTMENTS_RESULT_TAG, DEPARTMENT_OF_RESULT_TAG };
            crawler_trace = new CrawlerTrace(storageFolder, filenames);
        } catch (Exception ex) {
            Logger.getLogger("error").error(ex.getMessage(), ex);
            crawler_trace = null;
        }
    } else {
        crawler_trace = null;
    }

}

From source file:org.sakaiproject.vm.VelocityServlet.java

/**
 * Change any characters that Velocity doesn't like in the name to '_' to make a valid Velocity name
 * /*from w  w w .jav  a2s  .c  om*/
 * @param name
 *        The name to convert.
 * @return The name converted to a valid Velocity name.
 */
protected String escapeVmName(String name) {
    char[] chars = name.toCharArray();

    // make sure first character is valid (alpha)
    if (!Character.isLetter(chars[0])) {
        chars[0] = 'X';
    }

    // replace any other invalid characters
    for (int i = 1; i < chars.length; i++) {
        char c = chars[i];
        if (!(Character.isLetterOrDigit(c) || (c == '_') || (c == '-'))) {
            chars[i] = '_';
        }
    }

    return new String(chars);

}

From source file:com.fujitsu.dc.core.odata.DcExpressionParser.java

/**
 * tokenizer./* w  ww  .  j a  v a 2 s  .co  m*/
 * OData4j?tokenizer???'_'?????????
 * @param value value
 * @return 
 */
public static List<Token> tokenize(String value) {
    List<Token> rt = new ArrayList<Token>();
    int current = 0;
    int end = 0;

    while (true) {
        if (current == value.length()) {
            return rt;
        }
        char c = value.charAt(current);
        if (Character.isWhitespace(c)) {
            end = readWhitespace(value, current);
            rt.add(new Token(TokenType.WHITESPACE, value.substring(current, end)));
            current = end;
        } else if (c == '\'') {
            end = readQuotedString(value, current + 1);
            rt.add(new Token(TokenType.QUOTED_STRING, value.substring(current, end)));
            current = end;
        } else if (Character.isLetter(c)) {
            end = readWord(value, current + 1);
            rt.add(new Token(TokenType.WORD, value.substring(current, end)));
            current = end;
        } else if (c == '_') {
            end = readWord(value, current + 1);
            rt.add(new Token(TokenType.WORD, value.substring(current, end)));
            current = end;
        } else if (Character.isDigit(c)) {
            end = readDigits(value, current + 1);
            rt.add(new Token(TokenType.NUMBER, value.substring(current, end)));
            current = end;
        } else if (c == '(') {
            rt.add(new Token(TokenType.OPENPAREN, Character.toString(c)));
            current++;
        } else if (c == ')') {
            rt.add(new Token(TokenType.CLOSEPAREN, Character.toString(c)));
            current++;
        } else if (c == '-') {
            if (Character.isDigit(value.charAt(current + 1))) {
                end = readDigits(value, current + 1);
                rt.add(new Token(TokenType.NUMBER, value.substring(current, end)));
                current = end;
            } else {
                rt.add(new Token(TokenType.SYMBOL, Character.toString(c)));
                current++;
            }
        } else if (",.+=:".indexOf(c) > -1) {
            rt.add(new Token(TokenType.SYMBOL, Character.toString(c)));
            current++;
        } else {
            dumpTokens(rt);
            throw new RuntimeException("Unable to tokenize: " + value + " current: " + current + " rem: "
                    + value.substring(current));
        }
    }

}

From source file:org.eclipse.rdf4j.repository.manager.RepositoryManager.java

/**
 * Generates an ID for a new repository based on the specified base name. The base name may for example be
 * a repository name entered by the user. The generated ID will contain a variant of this name that does
 * not occur as a repository ID in this manager yet and is suitable for use as a file name (e.g. for the
 * repository's data directory).//from w w w. j  ava2s  .  c  om
 * 
 * @param baseName
 *        The String on which the returned ID should be based, must not be <tt>null</tt>.
 * @return A new repository ID derived from the specified base name.
 * @throws RepositoryException
 * @throws RepositoryConfigException
 */
public String getNewRepositoryID(String baseName) throws RepositoryException, RepositoryConfigException {
    if (baseName != null) {
        // Filter exotic characters from the base name
        baseName = baseName.trim();

        int length = baseName.length();
        StringBuilder buffer = new StringBuilder(length);

        for (char c : baseName.toCharArray()) {
            if (Character.isLetter(c) || Character.isDigit(c) || c == '-' || c == '_' || c == '.') {
                // Convert to lower case since file names are case insensitive on
                // some/most platforms
                buffer.append(Character.toLowerCase(c));
            } else if (c != '"' && c != '\'') {
                buffer.append('-');
            }
        }

        baseName = buffer.toString();
    }

    // First try if we can use the base name without an appended index
    if (baseName != null && baseName.length() > 0 && !hasRepositoryConfig(baseName)) {
        return baseName;
    }

    // When the base name is null or empty, generate one
    if (baseName == null || baseName.length() == 0) {
        baseName = "repository-";
    } else if (!baseName.endsWith("-")) {
        baseName += "-";
    }

    // Keep appending numbers until we find an unused ID
    int index = 2;
    while (hasRepositoryConfig(baseName + index)) {
        index++;
    }

    return baseName + index;
}

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

public static boolean isLowerCase(String s) {
    if (s == null) {
        return false;
    }/*  w w  w  . ja  v  a 2  s .  com*/

    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;
}