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.pfarrell.utils.misc.TextTools.java

/**
 * strip out any thing other than letters or space in the middle, 
 * @param arg any string//from w  ww .  jav a2  s  .com
 * @return letters or spaces, after trim()
 */
public static String justLetterOrSpace(String arg) {
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < arg.length(); i++) {
        char c = arg.charAt(i);
        if (Character.isLetter(c) || c == ' ') {
            sb.append(c);
        }
    }
    return sb.toString().trim();
}

From source file:com.novartis.pcs.ontology.service.parser.obo.SynonymTagHandler.java

private Synonym.Type parseType(String value, MutableInt fromIndex) {
    Synonym.Type type = Synonym.Type.RELATED;

    while (fromIndex.intValue() < value.length()
            && Character.isWhitespace(value.charAt(fromIndex.intValue()))) {
        fromIndex.increment();/*from  w  ww.  j  a  v a2s. co  m*/
    }

    int start = fromIndex.intValue();

    while (fromIndex.intValue() < value.length() && Character.isLetter(value.charAt(fromIndex.intValue()))) {
        fromIndex.increment();
    }

    if (start < fromIndex.intValue()) {
        String scope = value.substring(start, fromIndex.intValue());
        try {
            type = Synonym.Type.valueOf(scope.toUpperCase());
        } catch (IllegalArgumentException e) {
            type = Synonym.Type.RELATED;
            fromIndex.setValue(start);
        }
    }

    return type;
}

From source file:architecture.common.license.io.LicenseReader.java

private String decodeToXml(Reader in) throws IOException {
    StringBuffer text = new StringBuffer();
    char buf[] = new char[1024];
    int len;//from   w  ww .  j  a  v  a  2s .c o  m
    while ((len = in.read(buf)) >= 0) {
        int j = 0;
        while (j < len) {
            char ch = buf[j];
            if (Character.isLetter(ch) || Character.isDigit(ch) || ch == '+' || ch == '/' || ch == '=')
                text.append(ch);
            j++;
        }
    }
    in.close();
    String xml = new String(
            Base64.decodeBase64(text.toString().getBytes(ApplicationConstants.DEFAULT_CHAR_ENCODING)));
    if (!assertionsDisabled && !text.toString().matches("^[^\\s]*$")) {
        throw new AssertionError();
    } else {
        log.debug(xml);
        return xml;
    }
}

From source file:nl.surfsara.warcexamples.datascience.WordCountMapper.java

public static HashMap<String, Integer> countWords(String s) {
    HashMap<String, Integer> counter = new HashMap<String, Integer>();

    boolean word = false;
    String currentWord = "";
    int endOfLine = s.length() - 1;

    for (int i = 0; i < s.length(); i++) {
        char c = s.charAt(i);
        boolean isLetter = Character.isLetter(c);
        // if the char is a letter, word = true.
        if (isLetter && i != endOfLine) {
            word = true;//  ww  w  . ja  v  a2 s . c  o  m
            currentWord += c;
            // if char isn't a letter and there have been letters before,
            // counter goes up.
        } else if (!isLetter && word) {
            word = false;
            Integer count = counter.get(currentWord);
            counter.put(currentWord, count == null ? 1 : count + 1);
            currentWord = "";
            // last word of String; if it doesn't end with a non letter, it
            // wouldn't count without this.
        } else if (isLetter && i == endOfLine) {
            currentWord += c;
            Integer count = counter.get(currentWord);
            counter.put(currentWord, count == null ? 1 : count + 1);
            currentWord = "";
        }
    }
    return counter;
}

From source file:net.tenorite.game.Field.java

public int getNrOfSpecials() {
    int count = 0;
    for (int i = HEIGHT - 1; i >= 0; i--) {
        for (int j = 0; j < WIDTH; j++) {
            if (Character.isLetter(field[j][i])) {
                count++;//from   w  w w  .  j  ava  2 s.  c o  m
            }
        }
    }
    return count;
}

From source file:de.jfachwert.post.PLZ.java

private static boolean hasLandeskennung(String plz) {
    char kennung = plz.charAt(0);
    return Character.isLetter(kennung);
}

From source file:com.manydesigns.elements.util.Util.java

static boolean isAllUpperCase(String s) {
    for (int i = 0; i < s.length(); i++) {
        char c = s.charAt(i);
        if (Character.isLetter(c) && Character.isLowerCase(c)) {
            return false;
        }//from w w w .  j  a  v a 2 s.c o  m
    }
    return true;
}

From source file:de.jfachwert.post.Adresse.java

/**
 * Validiert die uebergebene Adresse auf moegliche Fehler.
 *
 * @param ort        der Ort//from w ww .  ja va  2  s .  c  o  m
 * @param strasse    die Strasse
 * @param hausnummer die Hausnummer
 */
public static void validate(Ort ort, String strasse, String hausnummer) {
    if (!ort.getPLZ().isPresent()) {
        throw new InvalidValueException(ort, "postal_code");
    }
    if (StringUtils.isBlank(strasse)) {
        throw new InvalidValueException(strasse, "street");
    }
    if (StringUtils.isBlank(hausnummer)) {
        throw new InvalidValueException(hausnummer, "house_number");
    }
    if (Character.isDigit(strasse.trim().charAt(0)) && (Character.isLetter(hausnummer.trim().charAt(0)))
            && (strasse.length() < hausnummer.length())) {
        throw new InvalidValueException(strasse + " " + hausnummer, "values_exchanged");
    }
}

From source file:net.sf.jasperreports.engine.util.JRResourcesUtil.java

private static boolean protocolValid(String protocol) {
    int length = protocol.length();
    if (length < 1) {
        return false;
    }//from w  w w. j a  v  a2 s  .com

    if (!Character.isLetter(protocol.charAt(0))) {
        return false;
    }

    for (int i = 1; i < length; ++i) {
        char c = protocol.charAt(i);
        if (!(Character.isLetterOrDigit(c) || c == '+' || c == '-' || c == '.')) {
            return false;
        }
    }

    return true;
}

From source file:eu.annocultor.converters.europeana.EuropeanaLabelExtractor.java

private boolean specialCharacterFilter(String label) {

    // in full-text labels should be capitalised
    if (fullTextMode && !Character.isUpperCase(label.charAt(0))) {
        return false;
    }//  ww  w.  j  a  v  a 2 s.com

    // otherwise make it lower case
    label = label.toLowerCase();
    for (int i = 0; i < label.length(); i++) {
        int words = 0;
        char c = label.charAt(i);
        if (Character.isLetter(c) || c == ' ' || c == '-') {
            if (c == ' ' || c == '-') {
                words++;
            }
            if (words > 3) {
                // multi-word names sound suspicious
                return false;
            }
            // ok
        } else {
            return false;
        }
    }
    return true;
}