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.liferay.cucumber.util.StringUtil.java

public static boolean isUpperCase(String s) {
    if (s == null) {
        return false;
    }//from  ww w  .ja v  a 2 s  .  c o m

    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.LOWER_CASE_A) && (c <= CharPool.LOWER_CASE_Z)) {

                return false;
            }

            continue;
        }

        if (Character.isLetter(c) && Character.isLowerCase(c)) {
            return false;
        }
    }

    return true;
}

From source file:org.codice.ddf.catalog.ui.query.suggestion.UtmUpsCoordinateProcessor.java

/**
 * Private utility method that detects if a latitude band is present in a UTM input string and
 * returns it, or null if it didn't exist. The provided input <b>must</b> match {@link
 * #PATTERN_UTM_COORDINATE}./*from  w  ww.ja  v a  2s  . com*/
 *
 * @param input UTM string input to search.
 * @return the lat band character, or null if it wasn't on the input string.
 */
@Nullable
private static Character getLatBand(final String input) {
    final int indexOfLastSymbolInZoneClause = input.indexOf(SPACE_CHAR) - 1;
    final char lastSymbolInZoneClause = input.charAt(indexOfLastSymbolInZoneClause);
    if (Character.isLetter(lastSymbolInZoneClause)) {
        return lastSymbolInZoneClause;
    }
    return null;
}

From source file:org.intermine.common.swing.text.RestrictedInputDocument.java

/**
 * Insert the given text into this document, as long as it leaves the document valid.
 * /* ww w . j a v a 2s . c  om*/
 * @param offset The starting offset &gt;= 0.
 * @param str The string to insert; does nothing with null/empty strings.
 * @param attr The attributes for the inserted content.
 * 
 * @throws BadLocationException if the given insert position is not a valid
 * position within the document.
 *   
 * @see javax.swing.text.Document#insertString
 */
@Override
public void insertString(int offset, String str, AttributeSet attr) throws BadLocationException {
    if (str == null) {
        return;
    }

    if (limit < 0 || getLength() + str.length() <= limit) {
        if (convertArray == null || convertArray.length < str.length()) {
            convertArray = new char[str.length()];
        }

        CharacterIterator iter = new StringCharacterIterator(str);
        char c = iter.first();
        int index;
        for (index = 0; c != CharacterIterator.DONE; c = iter.next()) {
            if (!overrideChecks && !StringUtils.contains(allowableCharacters, c)) {

                // At this point, c is invalid. See if a case change remedies this.

                if (caseConvert && Character.isLetter(c)) {
                    if (Character.isLowerCase(c)) {
                        c = Character.toUpperCase(c);
                    } else if (Character.isUpperCase(c)) {
                        c = Character.toLowerCase(c);
                    }
                    if (!StringUtils.contains(allowableCharacters, c)) {
                        // Don't insert but otherwise ignore.
                        return;
                    }
                } else {
                    return;
                }
            }
            convertArray[index++] = c;

        }
        super.insertString(offset, new String(convertArray, 0, index), attr);
    }
}

From source file:com.prowidesoftware.swift.model.IBAN.java

/**
 * Translate letters to numbers, also ignoring non alphanumeric characters
 *
 * @param bban//from   w ww. j  a  va  2 s  .  c o  m
 * @return the translated value
 */
public String translateChars(final StringBuilder bban) {
    final StringBuilder result = new StringBuilder();
    for (int i = 0; i < bban.length(); i++) {
        char c = bban.charAt(i);
        if (Character.isLetter(c)) {
            result.append(Character.getNumericValue(c));
        } else {
            result.append((char) c);
        }
    }
    return result.toString();
}

From source file:org.cafed00d.subtitle.FileProcessor.java

/**
 * Examines the line of text given looking for words. It recognizes that a
 * word is starting when it comes across a letter. Once it finds a letter, it
 * passes control to {@link WordProcessor} which will extract the current word
 * and determine if it can be corrected.
 * /* w ww .  j  a v  a  2s  .  c o  m*/
 * @param line
 *          The line of text to process.
 * @return The processed, corrected, line of text.
 */
private String processLine(String line) {
    StringBuilder result = new StringBuilder(line);
    for (int i = 0; i < result.length(); i++) {
        if (Character.isLetter(result.charAt(i))) {
            WordProcessor word = new WordProcessor(result, i);
            i = word.process();
            if (word.isCorrectionMade()) {
                correctedCount++;
                if (generateLog) {
                    if (!correctedWords.containsKey(word.getOriginalWord())) {
                        correctedWords.put(word.getOriginalWord(), word.getCorrectedWord());
                    }
                }
            }
            wordCount++;
        }
    }
    return result.toString();
}

From source file:org.light.portal.util.StringUtils.java

public static String encode(String s) {
    int maxBytesPerChar = 10;
    StringBuffer out = new StringBuffer(s.length());
    java.io.ByteArrayOutputStream buf = new java.io.ByteArrayOutputStream(maxBytesPerChar);
    java.io.OutputStreamWriter writer = new java.io.OutputStreamWriter(buf);

    for (int i = 0; i < s.length(); i++) {
        int c = (int) s.charAt(i);
        if (dontNeedEncoding.get(c)) {
            out.append((char) c);
        } else {/* ww  w .j  a  v  a  2s.  co m*/
            // convert to external encoding before hex conversion
            try {
                writer.write(c);
                writer.flush();
            } catch (java.io.IOException e) {
                buf.reset();
                continue;
            }
            byte[] ba = buf.toByteArray();
            for (int j = 0; j < ba.length; j++) {
                out.append('x');
                char ch = Character.forDigit((ba[j] >> 4) & 0xF, 16);
                // converting to use uppercase letter as part of
                // the hex value if ch is a letter.
                if (Character.isLetter(ch)) {
                    ch -= caseDiff;
                }
                out.append(ch);
                ch = Character.forDigit(ba[j] & 0xF, 16);
                if (Character.isLetter(ch)) {
                    ch -= caseDiff;
                }
                out.append(ch);
            }
            buf.reset();
        }
    }

    return out.toString();
}

From source file:org.apache.beam.runners.apex.ApexYarnLauncher.java

/**
 * From the current classpath, find the jar files that need to be deployed
 * with the application to run on YARN. Hadoop dependencies are provided
 * through the Hadoop installation and the application should not bundle them
 * to avoid conflicts. This is done by removing the Hadoop compile
 * dependencies (transitively) by parsing the Maven dependency tree.
 *
 * @return list of jar files to ship//  w w w . j  a  va 2s. co  m
 * @throws IOException when dependency information cannot be read
 */
public static List<File> getYarnDeployDependencies() throws IOException {
    try (InputStream dependencyTree = ApexRunner.class.getResourceAsStream("dependency-tree")) {
        try (BufferedReader br = new BufferedReader(new InputStreamReader(dependencyTree))) {
            String line;
            List<String> excludes = new ArrayList<>();
            int excludeLevel = Integer.MAX_VALUE;
            while ((line = br.readLine()) != null) {
                for (int i = 0; i < line.length(); i++) {
                    char c = line.charAt(i);
                    if (Character.isLetter(c)) {
                        if (i > excludeLevel) {
                            excludes.add(line.substring(i));
                        } else {
                            if (line.substring(i).startsWith("org.apache.hadoop")) {
                                excludeLevel = i;
                                excludes.add(line.substring(i));
                            } else {
                                excludeLevel = Integer.MAX_VALUE;
                            }
                        }
                        break;
                    }
                }
            }

            Set<String> excludeJarFileNames = Sets.newHashSet();
            for (String exclude : excludes) {
                String[] mvnc = exclude.split(":");
                String fileName = mvnc[1] + "-";
                if (mvnc.length == 6) {
                    fileName += mvnc[4] + "-" + mvnc[3]; // with classifier
                } else {
                    fileName += mvnc[3];
                }
                fileName += ".jar";
                excludeJarFileNames.add(fileName);
            }

            ClassLoader classLoader = ApexYarnLauncher.class.getClassLoader();
            URL[] urls = ((URLClassLoader) classLoader).getURLs();
            List<File> dependencyJars = new ArrayList<>();
            for (int i = 0; i < urls.length; i++) {
                File f = new File(urls[i].getFile());
                // dependencies can also be directories in the build reactor,
                // the Apex client will automatically create jar files for those.
                if (f.exists() && !excludeJarFileNames.contains(f.getName())) {
                    dependencyJars.add(f);
                }
            }
            return dependencyJars;
        }
    }
}

From source file:edu.stanford.muse.xword.Crossword.java

private static boolean wordHasOnlyLetters(String w) {
    for (char c : w.toCharArray())
        if (!Character.isLetter(c))
            return false;
    return true;/* ww w .  j  a  v a 2 s.c  o m*/
}

From source file:com.l2jfree.gameserver.util.Util.java

/**
 * Capitalizes the first letter of a string, and returns the result.<BR>
 * (Based on ucfirst() function of PHP)//www .  java2 s . com
 * 
 * @param String str
 * @return String containing the modified string.
 */
public static String capitalizeFirst(String str) {
    str = str.trim();

    if (str.length() > 0 && Character.isLetter(str.charAt(0)))
        return str.substring(0, 1).toUpperCase() + str.substring(1);

    return str;
}

From source file:org.apache.oozie.util.XLogUserFilterParam.java

private int getOffsetInMinute(String offset) throws IOException {

    if (Character.isLetter(offset.charAt(offset.length() - 1))) {
        switch (offset.charAt(offset.length() - 1)) {
        case 'h':
            return Integer.parseInt(offset.substring(0, offset.length() - 1)) * 60;
        case 'm':
            return Integer.parseInt(offset.substring(0, offset.length() - 1));
        default://from   w w  w .  ja  v  a  2  s  . c o  m
            throw new IOException("Unsupported offset " + offset);
        }
    } else {
        if (StringUtils.isNumeric(offset)) {
            return Integer.parseInt(offset) * 60;
        } else {
            throw new IOException("Unsupported time : " + offset);
        }
    }
}