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:com.cburch.draw.shapes.SvgReader.java

private static AbstractCanvasObject createPath(Element elt) {
    Matcher patt = PATH_REGEX.matcher(elt.getAttribute("d"));
    List<String> tokens = new ArrayList<String>();
    int type = -1; // -1 error, 0 start, 1 curve, 2 polyline
    while (patt.find()) {
        String token = patt.group();
        tokens.add(token);/*from   w w  w  .jav  a  2s.  co  m*/
        if (Character.isLetter(token.charAt(0))) {
            switch (token.charAt(0)) {
            case 'M':
                if (type == -1)
                    type = 0;
                else
                    type = -1;
                break;
            case 'Q':
            case 'q':
                if (type == 0)
                    type = 1;
                else
                    type = -1;
                break;
            /* not supported
            case 'L': case 'l':
            case 'H': case 'h':
            case 'V': case 'v':
               if (type == 0 || type == 2) type = 2;
               else type = -1;
               break;
            */
            default:
                type = -1;
            }
            if (type == -1) {
                throw new NumberFormatException("Unrecognized path command '" + token.charAt(0) + "'");
            }
        }
    }

    if (type == 1) {
        if (tokens.size() == 8 && tokens.get(0).equals("M") && tokens.get(3).toUpperCase().equals("Q")) {
            int x0 = Integer.parseInt(tokens.get(1));
            int y0 = Integer.parseInt(tokens.get(2));
            int x1 = Integer.parseInt(tokens.get(4));
            int y1 = Integer.parseInt(tokens.get(5));
            int x2 = Integer.parseInt(tokens.get(6));
            int y2 = Integer.parseInt(tokens.get(7));
            if (tokens.get(3).equals("q")) {
                x1 += x0;
                y1 += y0;
                x2 += x0;
                y2 += y0;
            }
            Location e0 = Location.create(x0, y0);
            Location e1 = Location.create(x2, y2);
            Location ct = Location.create(x1, y1);
            return new Curve(e0, e1, ct);
        } else {
            throw new NumberFormatException("Unexpected format for curve");
        }
    } else {
        throw new NumberFormatException("Unrecognized path");
    }
}

From source file:com.fluidops.iwb.widget.GMapWidget.java

public static String[] parseGeoCoords(String coords) {
    double lat = Double.NaN, lng = Double.NaN;

    String toParse;//from   w  w  w  .j  a v  a  2 s. c o m
    if (coords.startsWith("{{coord") && coords.endsWith("}}")) {
        toParse = coords.substring(coords.indexOf('|') + 1, coords.indexOf('}'));
        // single components
        String[] cs = toParse.split("\\|");

        switch (cs.length) {
        case 0:
        case 1:
            throw new IllegalArgumentException(coords + " is not a valid GeoCoord!!");

        case 2:
        case 3: /* decimal with sign */
            lat = valueOf(cs[0]);
            lng = valueOf(cs[1]);
            break;

        case 4:
        case 5: /* have decimal coords with [NS][WE] specs */
            if (Character.isLetter(cs[1].charAt(0)) && Character.isLetter(cs[3].charAt(0))) {
                lat = valueOf(cs[0]) * convertLatSpecToSign(cs[1]);
                lng = valueOf(cs[2]) * convertLngSpecToSign(cs[3]);
            } else {
                double hrslat = valueOf(cs[0]);
                double hrslng = valueOf(cs[2]);
                lat = convertDegToDec(Math.abs(hrslat), valueOf(cs[1]), 0, (int) Math.signum(hrslat));
                lng = convertDegToDec(Math.abs(hrslng), valueOf(cs[3]), 0, (int) Math.signum(hrslng));
            }
            break;

        case 6:
        case 7: /* now degree coords with sign or in DM format (degree, min) */
            if (Character.isLetter(cs[2].charAt(0)) && Character.isLetter(cs[5].charAt(0))) {
                /* is in DM format */
                lat = convertDegToDec(valueOf(cs[0]), valueOf(cs[1]), 0.0, convertLatSpecToSign(cs[2]));
                lng = convertDegToDec(valueOf(cs[3]), valueOf(cs[4]), 0.0, convertLngSpecToSign(cs[5]));
            } else {
                /* is degree coords with sign */
                double hrslat = valueOf(cs[0]);
                double hrslng = valueOf(cs[3]);
                lat = convertDegToDec(Math.abs(hrslat), valueOf(cs[1]), valueOf(cs[2]),
                        (int) Math.signum(hrslat));
                lng = convertDegToDec(Math.abs(hrslng), valueOf(cs[4]), valueOf(cs[5]),
                        (int) Math.signum(hrslng));
                break;
            }
            break;

        default: /* have degree coords with [NS][WE] specs */
            lat = convertDegToDec(valueOf(cs[0]), valueOf(cs[1]), valueOf(cs[2]), convertLatSpecToSign(cs[3]));
            lng = convertDegToDec(valueOf(cs[4]), valueOf(cs[5]), valueOf(cs[6]), convertLngSpecToSign(cs[7]));
            break;

        }
    } else {
        String[] sep = coords.split("\\s+");
        if (sep.length == 2) {
            return sep;
        }

        sep = coords.split(",");
        if (sep.length == 2) {
            return sep;
        }
    }

    return new String[] { String.format(Locale.US, "%3.6f", lat), String.format(Locale.US, "%3.6f", lng) };
}

From source file:TextAreaDemo.java

public void insertUpdate(DocumentEvent ev) {
    if (ev.getLength() != 1) {
        return;//ww w  . j a  v  a  2s. c  o  m
    }

    int pos = ev.getOffset();
    String content = null;
    try {
        content = textArea.getText(0, pos + 1);
    } catch (BadLocationException e) {
        e.printStackTrace();
    }

    // Find where the word starts
    int w;
    for (w = pos; w >= 0; w--) {
        if (!Character.isLetter(content.charAt(w))) {
            break;
        }
    }
    if (pos - w < 2) {
        // Too few chars
        return;
    }

    String prefix = content.substring(w + 1).toLowerCase();
    int n = Collections.binarySearch(words, prefix);
    if (n < 0 && -n <= words.size()) {
        String match = words.get(-n - 1);
        if (match.startsWith(prefix)) {
            // A completion is found
            String completion = match.substring(pos - w);
            // We cannot modify Document from within notification,
            // so we submit a task that does the change later
            SwingUtilities.invokeLater(new CompletionTask(completion, pos + 1));
        }
    } else {
        // Nothing found
        mode = Mode.INSERT;
    }
}

From source file:org.apache.nutch.analysis.lang.NGramProfile.java

/**
 * Analyze a piece of text/*  ww  w  .jav  a  2 s.  c om*/
 * 
 * @param text the text to be analyzed
 */
public void analyze(StringBuilder 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:eu.sisob.uma.crawler.ResearchersCrawlers.CrawlerResearchesPagesV3Controller.java

public CrawlerResearchesPagesV3Controller(String storageFolder, File data_dir,
        List<ResearcherNameInfo> researchers) throws Exception {
    super(storageFolder, false);

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

    link_wrong_keywords = new ArrayList<String>();
    link_keywords = new ArrayList<String>();
    link_staff_keywords = new ArrayList<String>();
    link_substaff_keywords = new ArrayList<String>();
    researcher_names_info_to_search = new ArrayList<ResearcherNameInfo>();

    List<String> lst = null;
    File f = null;/*  w w  w  . j a  v  a 2  s.c  om*/
    try {
        f = new File(data_dir, STAFFLIST_RESULT_TAG + ".keywords");
        lst = FileUtils.readLines(f, "UTF-8");
        for (String keyword : lst) {
            keyword = CandidateTypeURL.getCanonicalName(keyword);
            addLinkKeyWordsOfStaffList(keyword);
        }
    } catch (Exception ex) {
        ProjectLogger.LOGGER.error(ex);
    }

    try {
        f = new File(data_dir, SUBSTAFFLIST_RESULT_TAG + ".keywords");
        lst = FileUtils.readLines(f, "UTF-8");
        for (String keyword : lst) {
            keyword = CandidateTypeURL.getCanonicalName(keyword);
            addLinkKeyWordsOfSubStaffList(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);
    }

    for (ResearcherNameInfo researcher_name_info : researchers) {
        researcher_name_info.first_name = CandidateTypeURL.getCanonicalName(researcher_name_info.first_name);
        researcher_name_info.last_name = CandidateTypeURL.getCanonicalName(researcher_name_info.last_name);
        researcher_name_info.initial = CandidateTypeURL.getCanonicalName(researcher_name_info.initial);
        researcher_name_info.whole_name = CandidateTypeURL.getCanonicalName(researcher_name_info.whole_name);
        addLinkResearchesNames(researcher_name_info);

        for (String sub_last_name : researcher_name_info.last_name.split(" ")) {
            if (Character.isLetter(sub_last_name.charAt(0)))
                addLinkKeyWordsOfSubStaffList(String.valueOf(sub_last_name.charAt(0)));
        }
    }

    clearInterestingUrlsDetected();

    if (CrawlerTrace.isTraceUrlsActive()) {
        try {
            String[] filenames = { WRONG_URLS_RESULT_TAG, KEYWORDS_RESULT_TAG, WRONG_KEYWORDS_RESULT_TAG,
                    STAFFLIST_RESULT_TAG, SUBSTAFFLIST_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:CharUtils.java

/**
 * Check if character is a letter./*from  ww  w  . j av  a  2 s  .c om*/
 * 
 * @param c
 *            Character to test.
 * 
 * @return true if character is a letter.
 */

public static boolean isLetter(char c) {
    return Character.isLetter(c);
}

From source file:org.openhab.binding.yamahareceiver.internal.protocol.xml.InputWithPresetControlXML.java

private int convertToPresetNumber(String presetValue) {
    if (StringUtils.isNotEmpty(presetValue)) {
        if (StringUtils.isNumeric(presetValue)) {
            return Integer.parseInt(presetValue);
        } else {//from  w w w  .j a va  2s  . co m
            // special handling for RX-V3900, where 'A1' becomes 101 and 'B2' becomes 202 preset
            if (presetValue.length() >= 2) {
                Character presetAlpha = presetValue.charAt(0);
                if (Character.isLetter(presetAlpha) && Character.isUpperCase(presetAlpha)) {
                    int presetNumber = Integer.parseInt(presetValue.substring(1));
                    return (ArrayUtils.indexOf(LETTERS, presetAlpha) + 1) * 100 + presetNumber;
                }
            }
        }
    }
    return -1;
}

From source file:CharUtils.java

/**
 * Check if string is a single letter./*from   w  ww .j  a  v  a  2s.  c o m*/
 * 
 * @param s
 *            String to test.
 * 
 * @return true if string is a single letter.
 */

public static boolean isLetter(String s) {
    return (s != null) && (s.length() == 1) && Character.isLetter(s.charAt(0));
}

From source file:ai.susi.mind.SusiPhrase.java

public static String extractMeat(String expression) {
    if (isRegularExpression(expression))
        return ""; // the meatsize of a regular expression is zero
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < expression.length(); i++) {
        char c = expression.charAt(i);
        if (Character.isLetter(c) || Character.isDigit(c) || c == ' ')
            sb.append(c);/*from   ww w.j a va  2s .  co m*/
    }
    return sb.toString();
}

From source file:org.apache.cocoon.util.IOUtils.java

/**
 * Return a modified filename suitable for replicating directory
 * structures below the store's base directory. The following
 * conversions are performed:/*from ww w  .jav a 2  s .c  o  m*/
 * <ul>
 * <li>Path separators are converted to regular directory names</li>
 * <li>File path components are transliterated to make them valid (?)
 *     programming language identifiers. This transformation may well
 *     generate collisions for unusual filenames.</li>
 * </ul>
 * @return The transformed filename
 */
public static String normalizedFilename(String filename) {
    if ("".equals(filename)) {
        return "";
    }
    filename = (File.separatorChar == '\\') ? filename.replace('/', '\\') : filename.replace('\\', '/');
    String[] path = StringUtils.split(filename, File.separator);
    int start = (path[0].length() == 0) ? 1 : 0;

    StringBuffer buffer = new StringBuffer();
    for (int i = start; i < path.length; i++) {

        if (i > start) {
            buffer.append(File.separator);
        }

        if (path[i].equals("..")) {
            int lio;
            for (lio = buffer.length() - 2; lio >= 0; lio--) {
                if (buffer.substring(lio).startsWith(File.separator)) {
                    break;
                }
            }
            if (lio >= 0) {
                buffer.setLength(lio);
            }
        } else {
            char[] chars = path[i].toCharArray();

            if (chars.length < 1 || !Character.isLetter(chars[0])) {
                buffer.append('_');
            }

            for (int j = 0; j < chars.length; j++) {
                if (org.apache.cocoon.util.StringUtils.isAlphaNumeric(chars[j])) {
                    buffer.append(chars[j]);
                } else {
                    buffer.append('_');
                }
            }

            // Append the suffix if necessary.
            if (isJavaKeyword(path[i]))
                buffer.append(keywordSuffix);
        }

    }
    return buffer.toString();
}