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:util.misc.TextLineBreakerStringWidth.java

/**
 * Finds the best position to break the word in order to fit into a maximum
 * width./*from ww  w .jav a 2s  .c  o m*/
 *
 * @param word The word to break
 * @param maxWidth The maximum width of the word
 * @param mustBreak this word must break, even if no hyphenation is found
 * @return The position where to break the word
 */
private int findBreakPos(final String word, int maxWidth, boolean mustBreak) {
    // Reserve some space for the minus
    maxWidth -= mMinusWidth;

    // Binary search for the last fitting character
    int left = 0;
    int right = word.length() - 1;
    while (left < right) {
        int middle = (left + right + 1) / 2; // +1 to enforce taking the ceiling

        // Check whether this substring fits
        String subWord = word.substring(0, middle);
        int subWordWidth = getStringWidth(subWord);
        if (subWordWidth < maxWidth) {
            // It fits -> go on with the right side
            left = middle;
        } else {
            // It fits not -> go on with the left side
            right = middle - 1;
        }
    }
    int lastFittingPos = left;

    // Try to find a char that is no letter or digit
    // E.g. if the word is "Stadt-Land-Fluss" we try to break it in
    // "Stadt-" and "Land-Fluss" rather than "Stadt-La" and "nd-Fluss"
    for (int i = lastFittingPos - 1; i >= (lastFittingPos / 2); i--) {
        char ch = word.charAt(i);
        if (!Character.isLetterOrDigit(ch)) {
            // This char is no letter or digit -> break here
            return i + 1;
        }
    }

    if (useHyphenator) {
        int endCharacters;
        if (Character.isLetter(word.charAt(word.length() - 1))) {
            endCharacters = 2;
        } else {
            endCharacters = 3; // some words end in punctuation, so make sure at least 2 letters stay together
        }
        int startCharacters = 2;
        if (word.length() >= startCharacters + endCharacters) {
            final String hyphenated = hyphenator.hyphenate(word, endCharacters, startCharacters);
            if (hyphenated != null && hyphenated.length() > word.length()) {
                int characters = 0;
                int lastHyphen = 0;
                for (int i = 0; i < hyphenated.length(); i++) {
                    if (hyphenated.charAt(i) != '\u00AD') {
                        if (++characters > lastFittingPos) {
                            return lastHyphen;
                        }
                    } else {
                        lastHyphen = characters;
                    }
                }
            }
        }
    }

    // We did not find a better break char -> break at the last fitting char
    if (mustBreak) {
        return lastFittingPos;
    }

    return 0;
}

From source file:edu.ku.brc.specify.plugins.TaxonLabelFormatting.java

/**
 * Formats the same String./*from  ww w . jav a2s.c o  m*/
 */
protected void doFormatting() {
    drawList.clear();

    Object fmtObj = formatCBX.getValue();
    if (fmtObj == null) {
        return;
    }

    String format = fmtObj.toString();
    //System.out.println("["+format+"]");
    if (StringUtils.isNotEmpty(format) && format.length() > 0) {
        DefaultListModel model = (DefaultListModel) authorsList.getModel();

        StringBuilder chars = new StringBuilder();
        StringBuilder exp = new StringBuilder();
        int len = format.length();
        StringBuilder pat = new StringBuilder();
        for (int i = 0; i < len; i++) {
            char ch = format.charAt(i);
            if (ch == '%') {
                if (chars.length() > 0) {
                    drawList.add(new TextDrawInfo(FormatType.Plain, chars.toString()));
                    chars.setLength(0);
                }
                ch = format.charAt(++i);
                pat.setLength(0);
                pat.append('%');
                do {
                    if (Character.isLetter(ch) || Character.isDigit(ch)) {
                        pat.append(ch);
                    } else {
                        i--;
                        break;
                    }
                    i++;
                    if (i < len) {
                        ch = format.charAt(i);
                    }
                } while (i < len);

                FormatType ft = FormatType.Plain;
                String val = "";
                String token = pat.toString();
                if (token.equals("%S")) {
                    val = getByRank(taxon, 220).getName();
                    ft = FormatType.Italic;

                } else if (token.equals("%G")) {
                    val = getByRank(taxon, 180).getName();
                    ft = FormatType.Italic;

                } else if (token.charAt(1) == 'A') {
                    int authNum = Integer.parseInt(token.substring(2)) - 1;
                    if (authNum < model.getSize()) {
                        val = ((Agent) model.get(authNum)).getLastName();
                    } else {
                        val = token;
                    }
                }
                exp.append(val);
                drawList.add(new TextDrawInfo(ft, val));
            } else {
                exp.append(ch);
                chars.append(ch);
            }
        }
        if (chars.length() > 0) {
            drawList.add(new TextDrawInfo(FormatType.Plain, chars.toString()));
            chars.setLength(0);
        }
        specialLabel.repaint();
    }
}

From source file:nl.ru.cmbi.vase.parse.StockholmParser.java

private static ResidueInfo getResidueInfoFor(Alignment alignment, char chainID, ResidueInfoSet residueInfoSet,
        int columnIndex) {

    String alignedPDBSeq = getAlignedPDBSeq(alignment);

    char aa = alignedPDBSeq.charAt(columnIndex);
    if (Character.isLetter(aa)) {

        int residueInfoIndex = alignedPDBSeq.substring(0, columnIndex).replace(".", "").length();

        return residueInfoSet.getResidueFromOrder(chainID, residueInfoIndex);
    } else//  ww  w . j av  a2  s. c  om
        return null; // If it's a gap
}

From source file:org.pentaho.di.jdbc.SQLParser.java

/**
 * Processes the JDBC escape sequences.//from   www.  jav a2s  .c o m
 * 
 * @throws SQLException
 */
private void escape() throws SQLException {
    char tc = terminator;
    terminator = '}';
    StringBuffer escBuf = new StringBuffer();
    s++;
    skipWhiteSpace();

    if (in[s] == '?') {
        copyParam("@return_status", -1);
        skipWhiteSpace();
        mustbe('=', false);
        skipWhiteSpace();

        while (Character.isLetter(in[s])) {
            escBuf.append(Character.toLowerCase(in[s++]));
        }

        skipWhiteSpace();
        String esc = escBuf.toString();

        if ("call".equals(esc)) {
            callEscape();
        } else {
            throw new SQLException(
                    BaseMessages.getString(PKG, "error.parsesql.syntax", "call", String.valueOf(s)), "22019");
        }
    } else {
        while (Character.isLetter(in[s])) {
            escBuf.append(Character.toLowerCase(in[s++]));
        }

        skipWhiteSpace();
        String esc = escBuf.toString();

        if ("call".equals(esc)) {
            callEscape();
        } else if ("t".equals(esc)) {
            if (!getDateTimeField(timeMask)) {
                throw new SQLException(
                        BaseMessages.getString(PKG, "error.parsesql.syntax", "time", String.valueOf(s)),
                        "22019");
            }
        } else if ("d".equals(esc)) {
            if (!getDateTimeField(dateMask)) {
                throw new SQLException(
                        BaseMessages.getString(PKG, "error.parsesql.syntax", "date", String.valueOf(s)),
                        "22019");
            }
        } else if ("ts".equals(esc)) {
            if (!getDateTimeField(timestampMask)) {
                throw new SQLException(
                        BaseMessages.getString(PKG, "error.parsesql.syntax", "timestamp", String.valueOf(s)),
                        "22019");
            }
        } else {
            throw new SQLException(BaseMessages.getString(PKG, "error.parsesql.badesc", esc, String.valueOf(s)),
                    "22019");
        }
    }

    mustbe('}', false);
    terminator = tc;
}

From source file:com.vuze.android.remote.adapter.TorrentListAdapter.java

private static boolean isAlphabetic(int c) {
    // Seems to return symbolic languages
    //      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
    //         return Character.isAlphabetic(c);
    //      }// w  w  w .j  a  va  2  s.  co  m
    if (!Character.isLetter(c)) {
        return false;
    }
    int type = Character.getType(c);
    return type == Character.UPPERCASE_LETTER || type == Character.LOWERCASE_LETTER;
    // Simple, but doesn't include letters with hats on them ;)
    //return ('A' <= c && c <= 'Z') || ('a' <= c && c <= 'z');
}

From source file:com.rickendirk.rsgwijzigingen.ZoekService.java

private Wijzigingen checkerNieuw(boolean clusters_enabled) {
    Wijzigingen wijzigingen = new Wijzigingen(false, null);
    //String halen uit SP
    String klasTextS = PreferenceManager.getDefaultSharedPreferences(getApplicationContext())
            .getString("pref_klas", "");
    //Checken of klas niet leeg is
    if (klasTextS.equals("")) {
        wijzigingen.setFout("geenKlas");
        return wijzigingen;
    }//  w ww  . ja v  a2s . co m
    //Eerste teken klas mag geen letter zijn
    if (Character.isLetter(klasTextS.charAt(0))) {
        wijzigingen.setFout("EersteTekenLetter");
        return wijzigingen;
    }
    String klasGoed = corrigeerKlas(klasTextS);
    if (klasGoed.equals("TeLangeKlas")) {
        wijzigingen.setFout("klasMeerDan4Tekens");
        return wijzigingen;
    }
    ArrayList<String> clusters = new ArrayList<>();
    if (clusters_enabled) {
        clusters.addAll(getClusters());
        //Lege clusters weghalen
        clusters.removeAll(Collections.singleton(""));
        //Clusters moeten aanwezig zijn
        if (clusters.isEmpty()) {
            wijzigingen.setFout("geenClusters");
            return wijzigingen;
        }
    }
    Document doc;
    try {
        doc = Jsoup.connect(TABLE_URL).get();
    } catch (java.io.IOException e) {
        wijzigingen.setFout("verbindFout");
        return wijzigingen;
    }
    Elements tables = doc.select("table");
    if (tables.size() < 2) {
        //Geen geschikte tabel aanwezig
        wijzigingen.setFout("geenTabel");
        return wijzigingen;
    }
    Element table = tables.get(1);
    Elements rows = table.select("tr");
    ArrayList<Element> rowsList;
    if (clusters_enabled) {
        rowsList = getWijzigingenListClusters(rows, klasGoed, clusters);
    } else {
        rowsList = getwijzigingenListKlas(rows, klasGoed);
    }
    if (rowsList.isEmpty()) {
        //Geen wijzigingen TODO: Onderstaande comment weghalen als alles werkt
        //list.add("Er zijn geen roosterwijzigingen");
        wijzigingen.zijnWijzigingen = false;
    } else {
        maakWijzigingenKlas(rowsList, wijzigingen);
    }
    addDagEnDatum(wijzigingen, doc);
    addMessage(wijzigingen, doc);
    return wijzigingen;
}

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

/**
 * detects if string alpha chars are purely lower case.
 * //from   ww  w.j a  va2  s  .c  om
 * @param text
 *            text
 * @param textcase
 *            1 lower, 2 upper
 * @return if case matches given textcase param
 */
public static boolean checkCase(String text, int textcase) {
    if (text == null) {
        return false;
    }
    int caseCount = 0;

    for (char c : text.toCharArray()) {
        if (!Character.isLetter(c)) {
            continue;
        }
        if (textcase == 1) {
            if (Character.isUpperCase(c)) {
                // Checking for lower case; Fail if upper case is found.
                return false;
            } else if (Character.isLowerCase(c)) {
                ++caseCount;
            }
        } else if (textcase == 2) {
            if (Character.isLowerCase(c)) {
                // Checking for upper case; Fail if lower case is found.
                return false;
            } else if (Character.isUpperCase(c)) {
                ++caseCount;
            }
        }
    }
    // IF at least one letter found in the case, return true.
    // It is possible that mixed-language text that has no case-sense 
    // is mixed up with ASCII or Romance language text. 
    //   test     LOWER   UPPER
    //   A b  ==>  no      no
    //   A  ==>  no      yes
    //   a  ==>  yes      no
    return caseCount > 0;
}

From source file:org.novoj.utils.datePattern.DatePatternConverter.java

/**
 * This method decomposes original pattern into the recognizable chunks. Chunks are composed of:
 * - same letters/*from ww  w  .  ja va 2  s .c  om*/
 * - parts escaped with apostrophe (anything could be inside)
 * - unknown characters whose are not letters (comma, dot, double dot, space and so on)
 *
 * @param pattern
 * @return
 */
@SuppressWarnings({ "OverlyLongMethod", "ImplicitNumericConversion" })
public List<String> getPatternDecomposition(String pattern) {
    List<String> patternDecomposition = new ArrayList<String>();
    boolean escaped = false;
    char lastLetter = (char) 0;
    StringBuilder buffer = new StringBuilder();
    for (int i = 0; i < pattern.length(); i++) {
        char letter = pattern.charAt(i);
        if (letter == '\'') {
            if (escaped) {
                if (pattern.charAt(i + 1) == '\'') {
                    i++;
                    buffer.append("\'\'");
                } else {
                    escaped = false;
                    buffer.append('\'');
                    buffer = resetBuffer(patternDecomposition, buffer);
                }
            } else {
                buffer = resetBuffer(patternDecomposition, buffer);
                escaped = true;
                buffer.append('\'');
            }
        } else if (escaped) {
            buffer.append(letter);
        } else if (Character.isLetter(letter)) {
            if (letter == lastLetter || lastLetter == (char) 0) {
                buffer.append(letter);
            } else {
                buffer = resetBuffer(patternDecomposition, buffer);
                buffer.append(letter);
            }
        } else if (specialCharacters.contains(new Character(letter))) {
            buffer = resetBuffer(patternDecomposition, buffer);
            patternDecomposition.add(String.valueOf(letter));
        } else {
            if (buffer.length() > 0 && Character.isLetter(buffer.charAt(0))) {
                buffer = resetBuffer(patternDecomposition, buffer);
            }
            buffer.append(letter);
        }
        lastLetter = letter;
    }
    resetBuffer(patternDecomposition, buffer);
    return patternDecomposition;
}

From source file:com.nridge.core.base.std.StrUtl.java

/**
 * Uses a simple Caesar-cypher encryption to replace each English letter
 * with the one 13 places forward or back along the alphabet, so that
 * "The butler did it!" becomes "Gur ohgyre qvq vg!".   major advantage
 * of rot13 over rot(N) for other N is that it is self-inverse, so the
 * same code can be used for encoding and decoding.
 *
 * @param aString A plain text string to encode.
 * @return An encrypted <i>String</i> object.
 *//*from w  w w  .  j a  v a  2 s  .co m*/
public static String simple13Rotation(String aString) {
    char ch, chUp;
    int strLength;
    StringBuilder strBuilder;

    if (StringUtils.isEmpty(aString))
        return aString;
    else {
        strBuilder = new StringBuilder();

        strLength = aString.length();
        for (int i = 0; i < strLength; i++) {
            ch = aString.charAt(i);
            if (Character.isLetter(ch)) {
                chUp = Character.toUpperCase(ch);
                if ((chUp >= 'A') && (chUp <= 'M'))
                    ch += 13;
                else
                    ch -= 13;
            }
            strBuilder.append(ch);
        }

        return strBuilder.toString();
    }
}

From source file:edu.cornell.mannlib.vedit.util.Stemmer.java

public static String StemString(String inputStr, int maxLength) {
    String outputStr = "";

    int previousCh = 0;
    char[] w = new char[maxLength];
    char[] inputArray = inputStr.toCharArray();
    Stemmer s = new Stemmer();
    int inputArrayIndex = 0, stemmerInputBufferIndex = 0, ch = 0;
    for (inputArrayIndex = 0; inputArrayIndex < inputArray.length; inputArrayIndex++) {
        ch = inputArray[inputArrayIndex];
        if (Character.isLetter((char) ch)) {
            stemmerInputBufferIndex = 0; // start collecting letters for a new word
            while (inputArrayIndex < inputArray.length) { // keep reading until hit character other than a letter
                ch = Character.toLowerCase((char) ch);
                w[stemmerInputBufferIndex] = (char) ch;
                if (stemmerInputBufferIndex < maxLength - 1) {
                    stemmerInputBufferIndex++;
                }/* w w  w .  j  av a2 s .c o m*/
                if (inputArrayIndex < inputArray.length - 1) {
                    previousCh = ch;
                    ch = inputArray[++inputArrayIndex];
                    if (!Character.isLetter((char) ch)) { // parse the word in preparation for starting a new one
                        for (int c = 0; c < stemmerInputBufferIndex; c++) { // copy to stemmer internal buffer
                            s.add(w[c]);
                        }
                        s.stem();
                        {
                            String u;
                            u = s.toString();
                            outputStr += u;
                            if (ch == '-') { // replace - with space
                                outputStr += " ";
                            } else if (ch == '.') {
                                if (Character.isDigit((char) previousCh)) {
                                    outputStr += ".";
                                } else {
                                    outputStr += " ";
                                    //previousCh = 32; // set to whitespace; extra spaces should be filtered out on next pass
                                }
                            } else {
                                Character Ch = new Character((char) ch);
                                outputStr += Ch.toString();
                            }
                            stemmerInputBufferIndex = 0; // to avoid repeats after )
                        }
                        break;
                    }
                } else {
                    break;
                }
            }
        } else if (Character.isWhitespace((char) ch)) {
            if (!Character.isWhitespace((char) previousCh)) {
                if (previousCh != '.') {
                    Character Ch = new Character((char) ch);
                    outputStr += Ch.toString();
                }
            }
        } else if (ch == '(') { // open paren; copy all characters until close paren
            while (ch != ')') {
                if (inputArrayIndex < inputArray.length) {
                    ch = inputArray[inputArrayIndex++];
                } else {
                    log.trace("");
                    log.trace("1 short of EOS in paren at pos: " + inputArrayIndex + " of " + inputStr);
                    break;
                }
                Character Ch = new Character((char) ch);
                //outputStr += Ch.toString();
                //System.out.print( Ch.toString() );
            }
            //log.trace("");
            /* not needed -- just duplicates close paren
            if ( ch == ')') {
            Character Ch = new Character((char) ch);
            outputStr += Ch.toString();
            log.trace( Ch.toString() );
            }
            */
            stemmerInputBufferIndex = 0;
        } else if (ch == ')') { // when is last character of input string
            Character Ch = new Character((char) ch);
            outputStr += Ch.toString();
            log.trace(Ch.toString());
            log.trace("found close paren at position: " + inputArrayIndex + " of input term " + inputStr);
        } else if (ch == '-') { // replace - with space
            outputStr += " ";
        } else if (ch == '.') {
            if (Character.isDigit((char) previousCh)) {
                outputStr += ".";
            } else {
                outputStr += " ";
                //previousCh = 32; // set to whitespace; extra spaces should be filtered out on next pass
            }
        } else {
            Character Ch = new Character((char) ch);
            outputStr += Ch.toString();
        }
        previousCh = ch;
        if (ch < 0)
            break;
    }

    if (stemmerInputBufferIndex > 0) {
        for (int c = 0; c < stemmerInputBufferIndex; c++) {
            s.add(w[c]);
        }
        s.stem();

        String u;
        u = s.toString();
        outputStr += u;
    }

    return outputStr == null ? (outputStr.equals("") ? null : outputStr.trim()) : outputStr.trim();
}