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:org.python.pydev.core.docutils.StringUtils.java

public static boolean isAllUpper(String string) {
    int len = string.length();
    for (int i = 0; i < len; i++) {
        char c = string.charAt(i);
        if (Character.isLetter(c) && !Character.isUpperCase(c)) {
            return false;
        }//from  w  ww  . j  av  a 2 s . co  m
    }
    return true;
}

From source file:org.nd4j.util.StringUtils.java

/**
 * <p>Checks if the String contains only unicode letters.</p>
 *
 * <p><code>null</code> will return <code>false</code>.
 * An empty String (length()=0) will return <code>true</code>.</p>
 *
 * <pre>//  w  w  w .ja v  a  2s  . c o m
 * StringUtils.isAlpha(null)   = false
 * StringUtils.isAlpha("")     = true
 * StringUtils.isAlpha("  ")   = false
 * StringUtils.isAlpha("abc")  = true
 * StringUtils.isAlpha("ab2c") = false
 * StringUtils.isAlpha("ab-c") = false
 * </pre>
 *
 * @param str  the String to check, may be null
 * @return <code>true</code> if only contains letters, and is non-null
 */
public static boolean isAlpha(String str) {
    if (str == null) {
        return false;
    }
    int sz = str.length();
    for (int i = 0; i < sz; i++) {
        if (!Character.isLetter(str.charAt(i))) {
            return false;
        }
    }
    return true;
}

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

private ArrayList<String> checkerClusters() {
    ArrayList<String> tempList = new ArrayList<>();
    //String van klas halen uit SP
    String klasTextS = PreferenceManager.getDefaultSharedPreferences(getApplicationContext())
            .getString("pref_klas", "");
    String url = "http://www.rsgtrompmeesters.nl/roosters/roosterwijzigingen/Lijsterbesstraat/subst_001.htm";
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    //Clusters ophalen uit SP
    ArrayList<String> clusters = new ArrayList<>();
    for (int a = 1; a < 15; a++) {
        //String initializen, anders kan hij hem niet toevoegen
        String clusterLowCase = "";
        String cluster = sp.getString("pref_cluster" + a, "");
        //If om nullpointer te voorkomen
        if (!cluster.equals("")) {
            clusterLowCase = cluster.substring(0, 1).toLowerCase() + cluster.substring(1);
        }//  w  w w  . j a  v  a 2 s  . c o m
        clusters.add(clusterLowCase);
    }

    //Lege clusters weghalen uit arraylist TODO: Kijken of singleton werkt/wat het is
    clusters.removeAll(Collections.singleton(""));
    //Er moeten wel clusters zijn ingevoerd: Zo nee, komt AlertDialog via onPostExecute
    if (clusters.isEmpty()) {
        tempList.add("geenClusters");
        return tempList;
    }
    //Checken of klas niet leeg is
    if (klasTextS.equals("")) {
        tempList.add("geenKlas");
        return tempList;
    }
    //Eerste teken klas mag geen letter zijn
    if (Character.isLetter(klasTextS.charAt(0))) {
        tempList.add("EersteTekenLetter");
        return tempList;
    }
    //String opsplitsen in 2 delen, om naar hoofdletters te converteren
    char charcijfer = klasTextS.charAt(0);
    String klascijfer = String.valueOf(charcijfer);
    char charafdeling = klasTextS.charAt(1);
    String klasafdelingBig = String.valueOf(charafdeling).toUpperCase();
    //Onderstaand voor hoofdlettercorrectie
    String klasCorrect; //KlasCorrect is klas na hoofdlettercorrectie
    switch (klasTextS.length()) {
    case 2:
        klasCorrect = klascijfer + klasafdelingBig;
        break;
    case 3:
        char klasabc = klasTextS.charAt(2);
        String klasabcSmall = String.valueOf(klasabc).toLowerCase();
        klasCorrect = klascijfer + klasafdelingBig + klasabcSmall;
        break;
    case 4:
        char klasafdeling2 = klasTextS.charAt(2);
        String klasafdeling2Big = String.valueOf(klasafdeling2).toUpperCase();
        klasabc = klasTextS.charAt(3);
        klasabcSmall = String.valueOf(klasabc).toLowerCase();

        klasCorrect = klascijfer + klasafdelingBig + klasafdeling2Big + klasabcSmall;
        break;
    default:
        tempList.add("klasMeerDan4Tekens");
        return tempList;
    }
    //Try en catch in het geval dat de internetverbinding mist
    try {
        Document doc = Jsoup.connect(url).get();
        Elements tables = doc.select("table");
        if (tables.size() < 1) {
            //Geen geschikte tabel aanwezig
            tempList.add("geenTabel");
            return tempList;
        }
        Element table = tables.get(1);
        Elements rows = table.select("tr");
        //Eerste loop is om 2e loop te herhalen voor iedere cluster, tweede loop
        //doorzoekt dan op zowel klas als cluster
        for (int b = 0; b < clusters.size(); b++) {
            for (int i = 2; i < rows.size(); i++) {
                Element row = rows.get(i);
                Elements cols = row.select("td");

                if (cols.get(0).text().contains(klasCorrect) && cols.get(2).text().contains(clusters.get(b))) {
                    String vakOud = Jsoup.parse(cols.get(2).toString()).text();
                    String docentOud = Jsoup.parse(cols.get(3).toString()).text();
                    String vakNieuw = Jsoup.parse(cols.get(4).toString()).text();
                    String docentNieuw = Jsoup.parse(cols.get(5).toString()).text();
                    //If in geval van uitval, else ingeval van wijziging
                    if (Jsoup.parse(cols.get(6).toString()).text().contains("--")) {
                        //2 opties: wordt verplaatst of valt uit
                        if (Jsoup.parse(cols.get(8).toString()).text().contains("Uitval")) {
                            String wijziging = Jsoup.parse(cols.get(1).toString()).text() + "e uur "
                                    + Jsoup.parse(cols.get(2).toString()).text() + " valt uit";
                            tempList.add(wijziging);
                        } else {
                            //Uur wordt verplaatst
                            String wijziging = Jsoup.parse(cols.get(1).toString()).text() + "e uur "
                                    + "wordt verplaatst naar " + Jsoup.parse(cols.get(8).toString()).text();
                            tempList.add(wijziging);
                        }
                    } else if (vakOud.equals(vakNieuw) && docentOud.equals(docentNieuw)) {
                        String wijziging = Jsoup.parse(cols.get(1).toString()).text() + "e uur " + vakOud
                                + " wordt verplaatst naar " + Jsoup.parse(cols.get(6).toString()).text();
                        tempList.add(wijziging);
                    } else {
                        String wijzigingKaal =
                                // Voegt alle kolommen samen tot 1 string
                                // .text() zorgt voor leesbare text
                                // Spaties voor leesbaarheid
                                Jsoup.parse(cols.get(1).toString()).text() + "e uur "
                                        + Jsoup.parse(cols.get(2).toString()).text() + " "
                                        + Jsoup.parse(cols.get(3).toString()).text() + " wordt "
                                        + Jsoup.parse(cols.get(4).toString()).text() + " "
                                        + Jsoup.parse(cols.get(5).toString()).text() + " in "
                                        + Jsoup.parse(cols.get(6).toString()).text();

                        //ipv en naar bevatten een "/" ivm uren (ma 12-04 / 4)
                        String ipv = "";
                        if (Jsoup.parse(cols.get(7).toString()).text().contains("/")) {
                            ipv = "ipv " + Jsoup.parse(cols.get(7).toString()).text();
                        }
                        String naar = "";
                        if (Jsoup.parse(cols.get(8).toString()).text().contains("/")) {
                            naar = "naar " + Jsoup.parse(cols.get(8).toString()).text() + " ";
                        }
                        String vervangingsTekst = "";
                        //&nbsp; staat in lege cell, encoding enz, zie volgende link:
                        // http://stackoverflow.com/questions/26837034/how-to-tell-if-a-html-table-has-an-empty-cell-nbsp-using-jsoup
                        if (cols.size() > 9) {
                            if (!Jsoup.parse(cols.get(9).toString()).text().equals("\u00a0")) {
                                vervangingsTekst = "(" + Jsoup.parse(cols.get(9).toString()).text() + ")";
                            }
                        }
                        String wijziging = wijzigingKaal + " " + ipv + " " + naar + " " + vervangingsTekst;
                        tempList.add(wijziging);
                    }

                }
                //Geen wijzigingen pas bij laatste rij en de laatste cluster
                if (i == rows.size() - 1 && b == clusters.size() - 1) {
                    //Checken of tempList leeg is, zo ja 1 ding toevoegen
                    if (tempList.isEmpty()) {
                        tempList.add("Er zijn geen wijzigingen");
                    }
                    //Dag waarvoor wijzigingen zijn ophalen
                    Element dag = doc.select("body > div > div:nth-child(2) > p > b > span").first();
                    //Compatibiliteit met andere opmaak, om NPE te voorkomen
                    if (dag == null) {
                        dag = doc.select("body > center:nth-child(2) > div").first();
                    }
                    String dagStr = dag.text().toLowerCase();
                    // Woorden staan verkeerd om: omwisselen
                    int indexVanSpatie = dagStr.indexOf(" ");
                    String datum = dagStr.substring(0, indexVanSpatie);
                    String rest = dagStr.substring(indexVanSpatie + 1);
                    String dagGoed = rest + " " + datum;
                    tempList.add(dagGoed);

                    //Stand ophalen: staat in 1e tabel van HTML
                    Element tableDate = doc.select("table").get(0);
                    String dateFullText = tableDate.getElementsContainingOwnText("Stand:").text();
                    //Deel achter "Stand:" pakken
                    String FullTextSplit[] = dateFullText.split("Stand:");
                    tempList.add(FullTextSplit[1]);
                    return tempList;

                }
            }
        }
    } catch (java.io.IOException e) {
        //Error toevoegen aan tempList, dat wordt weergegeven in messagebox
        tempList.clear();
        tempList.add("verbindFout");
        return tempList;
    }
    //Zover hoort de method NOOIT te komen
    tempList.add("andereFout");
    return tempList;
}

From source file:nl.gridline.zieook.data.rest.RatingEventsImpl.java

private String createCaseInsensitive(String search) {
    StringBuilder b = new StringBuilder("(");
    for (int i = 0; i < search.length(); i++) {
        char c = search.charAt(i);
        if (Character.isLetter(c)) {
            b.append('(').append(Character.toUpperCase(c)).append('|').append(Character.toLowerCase(c))
                    .append(')');
        } else {// w  w  w  . ja v a2 s. co  m
            b.append(b);
        }
    }
    b.append(")");
    String result = b.toString();
    LOG.debug("crafted regexp: '{}'", result);
    return result;
}

From source file:com.unsa.view.MainView.java

private Metadata loadMetadata(AlgorithmsWord alg) {

    String temp = "";
    String tempTitle = "";
    String[] titulos = { "t.s.", "bach. arq.", "bachiller arq.", "bachiller", "lic.", "la profesora", "prof.",
            "mag.", "ing.", "magister", "ingeniero", "ingeniera", "dr.", "dra.", "doctora", "doctor" };

    Metadata metadata = new Metadata();
    metadata.setDescription("");
    metadata.setGrantor(lblInstitucion.getText() + ". " + alg.getDescriptionOptional());

    temp = alg.getTitle2().toLowerCase().trim();

    if (!temp.equals("")) {
        tempTitle = temp.substring(0, 1).toUpperCase() + temp.substring(1, temp.length());
    }//from   w w  w. ja  v a  2 s .  c  o m

    System.out.println(tempTitle);
    metadata.setTitle(tempTitle);
    metadata.setIssued(alg.getIssued());
    List<String> autor = alg.getCreator();
    String v_autores = "";
    String na = "";
    String capitalize = "";
    if (autor != null) {
        for (int i = 0; i < autor.size(); i++) {
            String temporal = autor.get(i).toLowerCase().trim();
            String val_final = "";
            String result = "";

            for (int j = 0; j < titulos.length; j++) {
                temporal = temporal.replaceAll(titulos[j], "");
            }

            //System.out.println("val: "+ val_final);
            val_final = temporal;

            for (int j = 0; j < val_final.length(); j++) {
                if (Character.isLetter(val_final.charAt(j)) || val_final.charAt(j) == ' ') {
                    result += val_final.charAt(j);
                }
            }

            v_autores += result.trim() + "||";
        }
        if (!v_autores.equals("")) {
            if (v_autores.length() > 3) {
                na = v_autores.substring(0, v_autores.length() - 3).trim();
            }
        }

        String[] rules = { " De ", " La ", " Los ", " El ", " Y ", " En " };
        String[] rules_change = { " de ", " la ", " los ", " el ", " y ", " en " };
        capitalize = WordUtils.capitalize(na.toLowerCase().trim());
        //capitalize = capitalize.replaceAll("\t", " ");
        for (int i = 0; i < rules.length; i++) {
            capitalize = capitalize.replaceAll(rules[i], rules_change[i]);
        }

    }

    metadata.setAuthor(capitalize);

    metadata.setCreator(capitalize);
    metadata.setAdvisor("");
    metadata.setSubject(alg.getSubject());

    metadata.setAbstract_doc(alg.getAbstract());
    metadata.setPublisher(lblInstitucion.getText());
    metadata.setSource(lblInstitucion.getText() + " - " + lblSiglas.getText() + "||Repositorio Institucional - "
            + lblSiglas.getText());
    metadata.setType(String.valueOf(cbTipo.getSelectedItem()));
    metadata.setLanguage_iso(lblIdioma.getText());
    metadata.setOther("");
    metadata.setEscuela(alg.getSchool());

    metadata.setDegreeName(alg.getDegreeName());
    metadata.setUri_rights(txtUri.getText());
    metadata.setRights(txtUriRight.getText());
    metadata.setDegreeLevel(alg.getSegundaEspecialidad());
    metadata.setUri_description(alg.getUriDescription());

    //System.out.println(metadata.getEscuela());

    Estadistica stadistic = new Estadistica();
    stadistic.setSizeAbstract(metadata.getAbstract_doc().length());
    stadistic.setSizeAutors(metadata.getCreator().length());
    stadistic.setSizeEscuela(metadata.getEscuela().length());
    stadistic.setSizeFacultad(metadata.getDescription().length());
    stadistic.setSizeKeyWords(metadata.getSubject().length());
    //stadistic.setSizeSegundaEsp(sSegundaEsp);
    stadistic.setSizeTitle(metadata.getTitle().length());

    String[] dn = metadata.getDegreeName().split(" ");
    if (dn.length != 0) {
        stadistic.setSizeDegreeName(dn.length);
    } else {
        stadistic.setSizeDegreeName(0);
    }

    metadata.setStadistic(stadistic);
    return metadata;
}

From source file:org.cesecore.util.CertTools.java

public static List<String> getPartsFromDNInternal(final String dn, final String dnPart,
        final boolean onlyReturnFirstMatch) {
    if (log.isTraceEnabled()) {
        log.trace(">getPartsFromDNInternal: dn:'" + dn + "', dnpart=" + dnPart + ", onlyReturnFirstMatch="
                + onlyReturnFirstMatch);
    }//w  w w  . j a va2s . c o m
    final List<String> parts = new ArrayList<String>();
    if (dn != null && dnPart != null) {
        final String dnPartLowerCase = dnPart.toLowerCase();
        final int dnPartLenght = dnPart.length();
        boolean quoted = false;
        boolean escapeNext = false;
        int currentStartPosition = -1;
        for (int i = 0; i < dn.length(); i++) {
            final char current = dn.charAt(i);
            // Toggle quoting for every non-escaped "-char
            if (!escapeNext && current == '"') {
                quoted = !quoted;
            }
            // If there is an unescaped and unquoted =-char we need to investigate if it is a match for the sought after part
            if (!quoted && !escapeNext && current == '=' && dnPartLenght <= i) {
                // Check that the character before our expected partName isn't a letter (e.g. dnsName=.. should not match E=..)
                if (i - dnPartLenght - 1 < 0 || !Character.isLetter(dn.charAt(i - dnPartLenght - 1))) {
                    boolean match = true;
                    for (int j = 0; j < dnPartLenght; j++) {
                        if (Character.toLowerCase(dn.charAt(i - dnPartLenght + j)) != dnPartLowerCase
                                .charAt(j)) {
                            match = false;
                            break;
                        }
                    }
                    if (match) {
                        currentStartPosition = i + 1;
                    }
                }
            }
            // When we have found a start marker, we need to be on the lookout for the ending marker
            if (currentStartPosition != -1 && ((!quoted && !escapeNext && (current == ',' || current == '+'))
                    || i == dn.length() - 1)) {
                int endPosition = (i == dn.length() - 1) ? dn.length() - 1 : i - 1;
                // Remove white spaces from the end of the value
                while (endPosition > currentStartPosition && dn.charAt(endPosition) == ' ') {
                    endPosition--;
                }
                // Remove white spaces from the beginning of the value
                while (endPosition > currentStartPosition && dn.charAt(currentStartPosition) == ' ') {
                    currentStartPosition++;
                }
                // Only return the inner value if the part is quoted
                if (dn.charAt(currentStartPosition) == '"' && dn.charAt(endPosition) == '"') {
                    currentStartPosition++;
                    endPosition--;
                }
                parts.add(dn.substring(currentStartPosition, endPosition + 1));
                if (onlyReturnFirstMatch) {
                    break;
                }
                currentStartPosition = -1;
            }
            if (escapeNext) {
                // This character was escaped, so don't escape the next one
                escapeNext = false;
            } else {
                if (!quoted && current == '\\') {
                    // This escape character is not escaped itself, so the next one should be
                    escapeNext = true;
                }
            }
        }
    }
    if (log.isTraceEnabled()) {
        log.trace("<getPartsFromDNInternal: resulting DN part=" + parts.toString());
    }
    return parts;
}

From source file:org.rdkit.knime.wizards.RDKitNodesWizardsPage.java

/**
 * Validates the page, e.g. checks whether the text fields contain valid
 * values.//from  ww  w  . j ava  2 s.c om
 *
 * @return Returns true, if all information on page is correct. False otherwise.
 */
protected boolean validatePage() {
    // Check existing project setting
    if (getProjectName().trim().equals("")) { //$NON-NLS-1$
        setErrorMessage(null);
        setMessage("Please select an existing project.");
        return false;
    }

    // Check the node name
    String nodeName = m_textNodeName.getText();
    if (nodeName.trim().isEmpty()) {
        setErrorMessage(null);
        setMessage("Please provide a valid node name.");
        return false;
    }
    if ((!Character.isLetter(nodeName.charAt(0))) || (nodeName.charAt(0) != nodeName.toUpperCase().charAt(0))) {
        setErrorMessage("The node name must start with an uppercase letter.");
        return false;
    }

    String strClassName = getNodeClassName();
    for (int i = 0; i < strClassName.length(); i++) {
        char c = strClassName.charAt(i);
        if (!(i == 0 && Character.isJavaIdentifierStart(c)) && !(i > 0 && Character.isJavaIdentifierPart(c))) {
            setErrorMessage("The class name '" + strClassName + "' is invalid.");
            return false;
        }
    }

    // Check package name
    String basePackage = m_textBasePackage.getText();
    if (basePackage.length() == 0) {
        setErrorMessage(null);
        setMessage("Please provide a package name.");
        return false;
    }
    for (int i = 0; i < basePackage.length(); i++) {
        char c = basePackage.charAt(i);
        if (!(Character.isLowerCase(c) || Character.isDigit(c) || c == '.' || c == '_')) {
            setErrorMessage("The package name '" + basePackage + "' is invalid.");
            return false;
        }
    }

    // Check for existing classes (naming conflict?)
    IProject project = RDKitNodesWizards.getProjectForName(getProjectName());
    String path = "src/" + m_textBasePackage.getText().trim().replace('.', '/') + "/" + nodeName;
    IFile file = project.getFile(new Path(path + "NodeModel.java"));
    if (file.exists()) {
        setErrorMessage("A node with the given name exists already. Please provide another name or package.");
        return false;
    }

    // Check percentages for pre- and post processing
    try {
        double dPrePerc = getPreProcessingPercentage();
        double dPostPerc = getPostProcessingPercentage();

        if (dPrePerc + dPostPerc > 1.0d) {
            setErrorMessage("The total of pre and post processing activities cannot be greater than 100%.");
            return false;
        }
    } catch (NumberFormatException exc) {
        setErrorMessage("Bad number format: " + exc.getMessage());
        return false;
    }

    // Everything is ok so far
    setErrorMessage(null);
    setMessage(null);
    return true;
}

From source file:org.onecmdb.core.internal.ccb.workers.SimpleCiRfcWorker.java

/**
 * Validate alias name.//ww  w .j  ava  2 s  .  com
 * 
 * <li>Can not start with numeric.</li>
 * <li>Can not contain space</li>
 * <li>Can not contain special characters</li>
 * @param alias
 * @return
 */
private String acceptAlias(String alias) {

    Character c = alias.charAt(0);
    if (!Character.isLetter(c)) {
        return ("First char in alias '" + alias + "' must be a letter");
    }

    int index = alias.indexOf(' ');
    if (index > 0) {
        return ("Alias '" + alias + "' can not contain spaces");
    }
    index = alias.indexOf(':');
    if (index > 0) {
        return ("Alias '" + alias + "' can not contain ':' characters");
    }

    return (null);
}

From source file:org.dasein.cloud.rackspace.compute.CloudServers.java

private String validateName(String name, boolean safeName) throws InternalException, CloudException {
    if (safeName) {
        name = name.toLowerCase().replaceAll(" ", "-");
    }//from   w  w  w. j a v a2  s .c o m
    if (name.length() > NAME_LIMIT) {
        name = name.substring(0, NAME_LIMIT);
    }
    StringBuilder str = new StringBuilder();

    for (int i = 0; i < name.length(); i++) {
        char c = name.charAt(i);

        if (!safeName) {
            if (Character.isLetterOrDigit(c) || c == '-' || c == ' ') {
                if (str.length() > 0 || Character.isLetter(c)) {
                    str.append(c);
                }
            }
        } else {
            if ((c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || c == '-') {
                if (str.length() > 0 || Character.isLetter(c)) {
                    str.append(c);
                }
            }
        }
    }
    if (str.length() < 1) {
        return makeUpName(name);
    }
    name = str.toString();
    while (!Character.isLetterOrDigit(name.charAt(name.length() - 1))) {
        if (name.length() < 2) {
            return makeUpName(name);
        }
        name = name.substring(0, name.length() - 1);
    }
    if (serverExists(name)) {
        return makeUpName(name);
    }
    return name;
}

From source file:javax.faces.component.UIComponentBase.java

/**
 * @param string the component id, that should be a vaild one.
 *//* w  w w  .  j  a  v a 2s. co m*/
private void isIdValid(String string) {

    //is there any component identifier ?
    if (string == null)
        return;

    //Component identifiers must obey the following syntax restrictions:
    //1. Must not be a zero-length String.
    if (string.length() == 0) {
        throw new IllegalArgumentException("component identifier must not be a zero-length String");
    }

    //let's look at all chars inside of the ID if it is a valid ID!
    char[] chars = string.toCharArray();

    //2. First character must be a letter or an underscore ('_').
    if (!Character.isLetter(chars[0]) && chars[0] != '_') {
        throw new IllegalArgumentException(
                "component identifier's first character must be a letter or an underscore ('_')! But it is \""
                        + chars[0] + "\"");
    }
    for (int i = 1; i < chars.length; i++) {
        //3. Subsequent characters must be a letter, a digit, an underscore ('_'), or a dash ('-').
        if (!Character.isDigit(chars[i]) && !Character.isLetter(chars[i]) && chars[i] != '-'
                && chars[i] != '_') {
            throw new IllegalArgumentException(
                    "Subsequent characters of component identifier must be a letter, a digit, an underscore ('_'), or a dash ('-')! But component identifier contains \""
                            + chars[i] + "\"");
        }
    }
}