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:pyromaniac.IO.MMFastqImporter.java

/**
 * _read sequence.// w  ww.  ja  va  2 s .co  m
 *
 * @param pyrotagBlock the pyrotag block
 * @param pos the pos
 * @return the array list
 * @throws SeqFormattingException the seq formatting exception
 */
public ArrayList<Character> _readSequence(char[] pyrotagBlock, MutableInteger pos)
        throws SeqFormattingException {
    ArrayList<Character> characters = new ArrayList<Character>();
    char curr;
    int index = pos.value();

    //push through newlines
    while (index < pyrotagBlock.length) {
        curr = pyrotagBlock[index];

        if (!(curr == '\n' || curr == '\r'))
            break;

        index++;
    }

    //should be in nucleotides
    while (index < pyrotagBlock.length) {
        curr = pyrotagBlock[index];
        curr = Character.toUpperCase(curr);

        if (curr == '\n' || curr == '\r')
            break;

        if (Character.isLetter((char) curr)) {
            if (ACCEPTIBLE_IUPAC_CHARS.indexOf(curr) == -1) {
                String seq = new String(pyrotagBlock);

                throw new SeqFormattingException("Non-IUPAC character (" + curr + ") in sequence : " + seq,
                        this.fastqFile);
            } else {
                characters.add(curr);
            }
        }
        index++;
    }
    pos.update(index);
    return characters;
}

From source file:org.videolan.vlc.gui.audio.AudioBrowserListAdapter.java

/**
 * Calculate sections of the list/*ww  w. ja v  a2  s .  c  o  m*/
 *
 * @param type Type of the audio file sort.
 */
private void calculateSections(int type) {
    char prevFirstChar = '%';
    boolean firstSeparator = true;
    ArrayList<String> sections = new ArrayList<>();
    if (type == TYPE_PLAYLISTS)
        Collections.sort(mItems, mItemsComparator);

    for (int i = 0; i < mItems.size(); ++i) {
        String title = mItems.get(i).mTitle;
        String unknown;
        switch (type) {
        case TYPE_ALBUMS:
            unknown = mContext.getString(R.string.unknown_album);
            break;
        case TYPE_GENRES:
            unknown = mContext.getString(R.string.unknown_genre);
            break;
        case TYPE_ARTISTS:
            unknown = mContext.getString(R.string.unknown_artist);
            break;
        default:
            unknown = null;
        }
        char firstChar;
        if (title.length() > 0 && (unknown == null || !unknown.equals(title)))
            firstChar = title.toUpperCase(Locale.ENGLISH).charAt(0);
        else
            firstChar = '#'; // Blank / spaces-only song title.

        if (Character.isLetter(firstChar)) {
            String firstCharInString = String.valueOf(firstChar);
            if ((firstSeparator || firstChar != prevFirstChar) && !sections.contains(firstCharInString)) {
                ListItem item = new ListItem(firstCharInString, null, null, true, null);
                mItems.add(i, item);
                mSections.put(i, String.valueOf(firstChar));
                i++;
                prevFirstChar = firstChar;
                firstSeparator = false;
                sections.add(firstCharInString);
            }
        } else if (firstSeparator) {
            ListItem item = new ListItem("#", null, null, true, null);
            mItems.add(i, item);
            mSections.put(i, "#");
            i++;
            prevFirstChar = firstChar;
            firstSeparator = false;
        }
    }
}

From source file:org.qedeq.base.utility.StringUtility.java

/**
 * Tests if given <code>String</code> begins with a letter and contains
 * only letters and digits./*  w  ww. j  a  v  a  2  s  . c  o m*/
 *
 * @param   text    test this
 * @return  is <code>text</code> only made of letters and digits and has
 *          a leading letter?
 * @throws  NullPointerException if <code>text == null</code>
 */
public static boolean isLetterDigitString(final String text) {
    if (text.length() <= 0) {
        return false;
    }
    if (!Character.isLetter(text.charAt(0))) {
        return false;
    }
    for (int i = 1; i < text.length(); i++) {
        if (!Character.isLetterOrDigit(text.charAt(i))) {
            return false;
        }
    }
    return true;
}

From source file:com.example.phonetic.Nysiis.java

static String clean(String str) {
    if (str == null || str.length() == 0) {
        return str;
    }//from   w ww . j  a  v  a 2s  .com
    int len = str.length();
    char[] chars = new char[len];
    int count = 0;
    for (int i = 0; i < len; i++) {
        if (Character.isLetter(str.charAt(i))) {
            chars[count++] = str.charAt(i);
        }
    }
    if (count == len) {
        return str.toUpperCase(java.util.Locale.ENGLISH);
    }
    return new String(chars, 0, count).toUpperCase(java.util.Locale.ENGLISH);
}

From source file:mml.handler.post.MMLPostHTMLHandler.java

/**
 * Remove leading and trailing punctuation
 * @param input the raw string/*from  w w w.  j  a  v  a 2s  .  c o m*/
 * @param leading true if this is the first word of a hyphenated pair
 * @return the trimmed string
 */
private String clean(String input, boolean leading) {
    int start = 0;
    while (start < input.length())
        if (!Character.isLetter(input.charAt(start)))
            start++;
        else
            break;
    int end = input.length() - 1;
    while (end >= 0)
        if (!Character.isLetter(input.charAt(end)))
            end--;
        else
            break;
    // reset start or end after internal punctuation
    if (leading) {
        for (int i = start; i <= end; i++) {
            if (!Character.isLetter(input.charAt(i)))
                start = i + 1;
        }
    } else {
        for (int i = end; i >= start; i--) {
            if (!Character.isLetter(input.charAt(i)))
                end = i - 1;
        }
    }
    return (start <= end) ? input.substring(start, end + 1) : "";
}

From source file:com.anysoftkeyboard.AnySoftKeyboard.java

private static boolean isBackWordDeleteChar(int c) {
    return Character.isLetter(c);
}

From source file:org.alfresco.module.org_alfresco_module_wcmquickstart.benchmark.RandomTextGenerator.java

/**
 * @param totalCharacters int/* www .  j av  a  2 s . co m*/
 * @param lineWidth int
 * @param enforceFullWord boolean
 * @return String
 */
public String generateText(int totalCharacters, int lineWidth, boolean enforceFullWord) {
    StringBuffer sb = new StringBuffer();

    Random random = new Random();
    CharQueue queue = new CharQueue(prefixLength);
    float weight = 0;

    queue.set(chain1.getBootstrapPrefix());
    sb.append(queue.toString());
    int width = 0;
    int c;

    do {
        String prefix = queue.toString();

        // get a character from each chain
        c = chain1.get(prefix, random);
        int c2 = -1;
        if (chain2 != null) {
            c2 = chain2.get(prefix, random);
        }
        if (c == -1 && c2 == -1) {
            break;
        }

        // choose one if we can
        if (chain2 != null) {
            if (c == -1) {
                c = c2;
            } else if (c2 != -1 && random.nextFloat() < weight) {
                c = c2;
            }
        }
        sb.append((char) c);
        queue.put((char) c);
        width++;

        // line wrap
        if (c == ' ' && width > lineWidth) {
            sb.append("\n");
            width = 0;
        }

        // go towards second markov chain
        weight += 1.0 / totalCharacters;
    } while (weight < 1 || (/*c != '.'*/Character.isLetter(c) && enforceFullWord));

    sb.append("\n");

    String generatedText = sb.toString();

    return generatedText.substring(prefixLength + 1, prefixLength + 2).toUpperCase()
            + generatedText.substring(prefixLength + 2);
}

From source file:org.eclipse.smila.connectivity.framework.crawler.web.metadata.Metadata.java

/**
 * Normalize./*from   w w  w. j av  a2s  .  co  m*/
 * 
 * @param str
 *          the string to normalize
 * 
 * @return the string
 */
private static String normalize(final String str) {
    char c;
    final StringBuffer buf = new StringBuffer();
    for (int i = 0; i < str.length(); i++) {
        c = str.charAt(i);
        if (Character.isLetter(c)) {
            buf.append(Character.toLowerCase(c));
        }
    }
    return buf.toString();
}

From source file:com.crimelab.service.ChemistryServiceImpl.java

public static int countWords(String s) {
    int wordCount = 0;
    boolean word = false;
    int endOfLine = s.length() - 1;

    for (int i = 0; i < s.length(); i++) {
        // if the char is a letter, word = true.
        if (Character.isLetter(s.charAt(i)) && i != endOfLine) {
            word = true;//from w w  w  .j  a v  a 2  s.  c  o m
            // if char isn't a letter and there have been letters before,
            // counter goes up.
        } else if (!Character.isLetter(s.charAt(i)) && word) {
            wordCount++;
            word = false;
            // last word of String; if it doesn't end with a non letter, it
            // wouldn't count without this.
        } else if (Character.isLetter(s.charAt(i)) && i == endOfLine) {
            wordCount++;
        }
    }
    return wordCount;
}

From source file:net.spfbl.whois.Owner.java

/**
 * Atualiza os campos do registro com resultado do WHOIS.
 * @param result o resultado do WHOIS.// w ww  .j a va2s.  co  m
 * @return o ownerid real apresentado no resultado do WHOIS.
 * @throws QueryException se houver alguma falha da atualizao do registro.
 */
private String refresh(String result) throws ProcessException {
    try {
        boolean reducedLocal = false;
        String owneridResult = null;
        BufferedReader reader = new BufferedReader(new StringReader(result));
        try {
            String line;
            while ((line = reader.readLine()) != null) {
                line = line.trim();
                if (line.startsWith("owner:")) {
                    int index = line.indexOf(':') + 1;
                    owner = line.substring(index).trim();
                } else if (line.startsWith("ownerid:")) {
                    int index = line.indexOf(':') + 1;
                    owneridResult = line.substring(index).trim();
                } else if (line.startsWith("responsible:")) {
                    int index = line.indexOf(':') + 1;
                    responsible = line.substring(index).trim();
                } else if (line.startsWith("country:")) {
                    int index = line.indexOf(':') + 1;
                    country = line.substring(index).trim();
                } else if (line.startsWith("owner-c:")) {
                    int index = line.indexOf(':') + 1;
                    owner_c = line.substring(index).trim();
                } else if (line.startsWith("domain:")) {
                    int index = line.indexOf(':') + 1;
                    String domain = line.substring(index).trim();
                    domainList.add(domain);
                } else if (line.startsWith("created:")) {
                    int index = line.indexOf(':') + 1;
                    String valor = line.substring(index).trim();
                    if (valor.startsWith("before ")) {
                        index = line.indexOf(' ');
                        valor = valor.substring(index);
                    }
                    created = DATE_FORMATTER.parse(valor);
                } else if (line.startsWith("changed:")) {
                    int index = line.indexOf(':') + 1;
                    changed = DATE_FORMATTER.parse(line.substring(index).trim());
                } else if (line.startsWith("provider:")) {
                    int index = line.indexOf(':') + 1;
                    provider = line.substring(index).trim();
                } else if (line.startsWith("nic-hdl-br:")) {
                    int index = line.indexOf(':') + 1;
                    String nic_hdl_br = line.substring(index).trim();
                    line = reader.readLine().trim();
                    index = line.indexOf(':') + 1;
                    String person = line.substring(index).trim();
                    line = reader.readLine().trim();
                    index = line.indexOf(':') + 1;
                    String e_mail;
                    if (reducedLocal) {
                        e_mail = null;
                    } else {
                        e_mail = line.substring(index).trim();
                        line = reader.readLine().trim();
                        index = line.indexOf(':') + 1;
                    }
                    String created2 = line.substring(index).trim();
                    line = reader.readLine().trim();
                    index = line.indexOf(':') + 1;
                    String changed2 = line.substring(index).trim();
                    Handle handle = Handle.getHandle(nic_hdl_br);
                    handle.setPerson(person);
                    handle.setEmail(e_mail);
                    handle.setCreated(created2);
                    handle.setChanged(changed2);
                } else if (line.startsWith("% No match for domain")) {
                    throw new ProcessException("ERROR: OWNER NOT FOUND");
                } else if (line.startsWith("% Permission denied.")) {
                    throw new ProcessException("ERROR: WHOIS DENIED");
                } else if (line.startsWith("% Permisso negada.")) {
                    throw new ProcessException("ERROR: WHOIS DENIED");
                } else if (line.startsWith("% Maximum concurrent connections limit exceeded")) {
                    throw new ProcessException("ERROR: WHOIS CONCURRENT");
                } else if (line.startsWith("% Query rate limit exceeded. Reduced information.")) {
                    // Informao reduzida devido ao estouro de limite de consultas.
                    Server.removeWhoisQueryHour();
                    reducedLocal = true;
                } else if (line.startsWith("% Query rate limit exceeded")) {
                    // Restrio total devido ao estouro de limite de consultas.
                    Server.removeWhoisQueryDay();
                    throw new ProcessException("ERROR: WHOIS QUERY LIMIT");
                } else if (line.length() > 0 && Character.isLetter(line.charAt(0))) {
                    Server.logError("Linha no reconhecida: " + line);
                }
            }
        } finally {
            reader.close();
        }
        if (owneridResult == null) {
            throw new ProcessException("ERROR: OWNER NOT FOUND");
        } else {
            this.lastRefresh = System.currentTimeMillis();
            this.reduced = reducedLocal;
            this.queries = 1;
            // Atualiza flag de atualizao.
            OWNER_CHANGED = true;
            // Retorna o ownerid real indicado pelo WHOIS.
            return owneridResult;
        }
    } catch (ProcessException ex) {
        throw ex;
    } catch (Exception ex) {
        Server.logError(ex);
        throw new ProcessException("ERROR: PARSING", ex);
    }
}