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.fenixedu.idcards.domain.SantanderBatch.java

private String purgeString(final String name) {
    if (!StringUtils.isAlphaSpace(name)) {
        final char[] ca = new char[name.length()];
        int j = 0;
        for (int i = 0; i < name.length(); i++) {
            final char c = name.charAt(i);
            if (Character.isLetter(c) || c == ' ') {
                ca[j++] = c;//from www .  j  av a 2  s .c  om
            }
        }
        return new String(ca);
    }
    return name;
}

From source file:ca.uhn.fhir.model.primitive.IdDt.java

private String determineLocalPrefix(String theValue) {
    if (theValue == null || theValue.isEmpty()) {
        return null;
    }/*  w ww  .jav  a2s . c om*/
    if (theValue.startsWith("#")) {
        return "#";
    }
    int lastPrefix = -1;
    for (int i = 0; i < theValue.length(); i++) {
        char nextChar = theValue.charAt(i);
        if (nextChar == ':') {
            lastPrefix = i;
        } else if (!Character.isLetter(nextChar) || !Character.isLowerCase(nextChar)) {
            break;
        }
    }
    if (lastPrefix != -1) {
        String candidate = theValue.substring(0, lastPrefix + 1);
        if (candidate.startsWith("cid:") || candidate.startsWith("urn:")) {
            return candidate;
        } else {
            return null;
        }
    } else {
        return null;
    }
}

From source file:org.eclipse.wb.internal.core.model.property.editor.style.impl.SelectionUsingEqualsStylePropertyImpl.java

private String getSource(final GenericProperty genericProperty, final String style,
        final boolean addClassAndDefault, final String separator) throws Exception {
    String currentSource = getCurrentSource(genericProperty);
    currentSource = currentSource.trim();
    // if the new style is unknown, do nothing
    if (style.equals("UNKNOWN_VALUE")) {
        // get the style string that the new source should replace
        final String flagValue = getFlagValue(genericProperty);
        if (flagValue == null) {
            // the selection doesn't include anything to clear
            return currentSource;
        }/*from ww  w. j a v  a2s  . c  o m*/
        // remove flagValue from the current source, and return the source
        // if there is no source, then don't bother, return the current source
        if (currentSource.length() == 0) {
            return currentSource;
        }
        int beginIndex = currentSource.indexOf('.' + flagValue);
        int endIndex = currentSource.indexOf('.' + flagValue) + flagValue.length() + 1;
        // adjust beginIndex to include the "*Field." part of the style bit
        for (; beginIndex > 0; beginIndex--) {
            final char ch = currentSource.charAt(beginIndex);
            if (!Character.isLetter(ch) && ch != '.') {
                break;
            }
        }
        // adjust beginIndex and endIndex to trim any whitespace
        for (; beginIndex > 0; beginIndex--) {
            final char ch = currentSource.charAt(beginIndex);
            if (!Character.isWhitespace(ch)) {
                break;
            }
        }
        for (; endIndex <= currentSource.length() - 1; endIndex++) {
            final char ch = currentSource.charAt(endIndex);
            if (!Character.isWhitespace(ch)) {
                break;
            }
        }
        // assume that a '|' is just before the beginIndex
        // else, then assume it is after the endIndex
        // else, we just assume that
        if (beginIndex > 0 && currentSource.charAt(beginIndex) == '|') {
            beginIndex--;
        } else if (endIndex < currentSource.length() && currentSource.charAt(endIndex) == '|') {
            endIndex++;
        } else {
            return currentSource;
        }
        return currentSource.substring(0, beginIndex)
                + currentSource.substring(endIndex, currentSource.length());
    }
    // else if the new style is not already in the currentSource, then add the new source
    else if (currentSource.indexOf('.' + style) == -1) {
        // get the style string that the new source should replace
        final String flagValue = getFlagValue(genericProperty);
        if (flagValue == null) {
            // if not replacing any source, simply append the new style source onto the existing source
            StringBuffer newSource = new StringBuffer();
            if (currentSource.length() != 0) {
                newSource.append(currentSource);
            }
            newSource.append(separator);
            if (addClassAndDefault) {
                newSource.append(m_className);
                newSource.append('.');
            }
            newSource.append(style);
            return newSource.toString();
        } else {
            // otherwise, replace the existing style String with the new selection
            //currentSource.subSequence(beginIndex, endIndex);
            int beginIndex = currentSource.indexOf('.' + flagValue);
            int endIndex = currentSource.indexOf('.' + flagValue) + flagValue.length() + 1;
            // adjust beginIndex to include the "*Field." part of the style bit
            for (; beginIndex > 0; beginIndex--) {
                final char ch = currentSource.charAt(beginIndex);
                if (!Character.isLetter(ch) && ch != '.') {
                    break;
                }
            }
            // modify this code segment to use the StringBuffer so that the code is in sync with
            // the coding-pattern in the rest of the method (pattern of using the StringBuffer)
            if (addClassAndDefault) {
                currentSource = currentSource.substring(0, beginIndex) + m_className + '.' + style
                        + currentSource.substring(endIndex);
            } else {
                currentSource = currentSource.substring(0, beginIndex) + style
                        + currentSource.substring(endIndex);
            }
            return currentSource;
        }
    } else {
        return currentSource;
    }
}

From source file:ch.cyberduck.core.threading.BackgroundException.java

/**
 * @return Detailed message from the underlying cause.
 *///w w w  .j  a v a  2 s  .  c o m
public String getDetailedCauseMessage() {
    final Throwable cause = this.getCause();
    StringBuilder buffer = new StringBuilder();
    if (null != cause) {
        if (StringUtils.isNotBlank(cause.getMessage())) {
            String m = StringUtils.chomp(cause.getMessage());
            buffer.append(m);
            if (!m.endsWith(".")) {
                buffer.append(".");
            }
        }
        if (cause instanceof ServiceException) {
            final ServiceException s3 = (ServiceException) cause;
            if (StringUtils.isNotBlank(s3.getResponseStatus())) {
                // HTTP method status
                buffer.append(" ").append(s3.getResponseStatus()).append(".");
            }
            if (StringUtils.isNotBlank(s3.getErrorMessage())) {
                // S3 protocol message
                buffer.append(" ").append(s3.getErrorMessage());
            }
        } else if (cause instanceof SardineException) {
            final SardineException http = (SardineException) cause;
            if (StringUtils.isNotBlank(http.getResponsePhrase())) {
                buffer.delete(0, buffer.length());
                // HTTP method status
                buffer.append(http.getResponsePhrase()).append(".");
            }
        } else if (cause instanceof org.jets3t.service.impl.rest.HttpException) {
            final org.jets3t.service.impl.rest.HttpException http = (org.jets3t.service.impl.rest.HttpException) cause;
            buffer.append(" ").append(http.getResponseCode());
            if (StringUtils.isNotBlank(http.getResponseMessage())) {
                buffer.append(" ").append(http.getResponseMessage());
            }
        } else if (cause instanceof CloudFrontServiceException) {
            final CloudFrontServiceException cf = (CloudFrontServiceException) cause;
            if (StringUtils.isNotBlank(cf.getErrorMessage())) {
                buffer.append(" ").append(cf.getErrorMessage());
            }
            if (StringUtils.isNotBlank(cf.getErrorDetail())) {
                buffer.append(" ").append(cf.getErrorDetail());
            }
        } else if (cause instanceof FilesException) {
            final FilesException cf = (FilesException) cause;
            final StatusLine status = cf.getHttpStatusLine();
            if (null != status) {
                if (StringUtils.isNotBlank(status.getReasonPhrase())) {
                    buffer.append(" ").append(status.getReasonPhrase());
                }
            }
        } else if (cause instanceof AmazonServiceException) {
            final AmazonServiceException a = (AmazonServiceException) cause;
            final String status = a.getErrorCode();
            if (StringUtils.isNotBlank(status)) {
                buffer.append(" ").append(status);
            }
        }
    }
    String message = buffer.toString();
    if (!StringUtils.isEmpty(message)) {
        if (Character.isLetter(message.charAt(message.length() - 1))) {
            message = message + ".";
        }
    }
    return Locale.localizedString(message, "Error");
}

From source file:CharUtils.java

/**
 * Check if character is a capital letter.
 * // w  ww .j  a  va  2 s. co m
 * @param c
 *            Character to test.
 * 
 * @return true if character is a capital letter.
 */

public static boolean isCapitalLetter(char c) {
    return Character.isLetter(c) && Character.isUpperCase(c);
}

From source file:au.org.ala.bhl.TaxonGrab.java

private Set<String> loadLexicon() {
    HashSet<String> set = new HashSet<String>();
    String path = "/au/org/ala/bhl/english.txt";
    InputStream is = TaxonGrab.class.getResourceAsStream(path);
    try {// w  w w  . ja v  a 2 s.c  o m
        @SuppressWarnings("unchecked")
        List<String> lines = IOUtils.readLines(is);
        int count = 0;
        for (String line : lines) {
            StringBuilder word = new StringBuilder();
            for (int i = 0; i < line.length(); ++i) {
                char ch = line.charAt(i);
                if (Character.isLetter(ch)) {
                    word.append(ch);
                }
            }
            count++;
            set.add(word.toString().toLowerCase());
        }

        System.out.println("" + count + " words loaded.");
    } catch (IOException e) {
        e.printStackTrace();
    }

    return set;
}

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

/**
 * Private utility method for updating a UTM string in-place with a new latitude band. The
 * provided input <b>must</b> match {@link #PATTERN_UTM_COORDINATE}.
 *
 * @param input UTM string input; must match {@link #PATTERN_UTM_COORDINATE}.
 * @param newLatBand character to use as the new latitude band for the new UTM string.
 * @return a new UTM string with the provided {@code newLatBand}, regardless if the original UTM
 *     {@code input} had a lat band or not.
 *///from   www.j a va 2s . co m
private static String setLatBand(final String input, final Character newLatBand) {
    notNull(newLatBand, "newLatBand cannot be null");
    final int indexOfFirstWhiteSpace = input.indexOf(SPACE_CHAR);
    final int indexOfFirstWhiteSpaceOrLatBand = Character.isLetter(input.charAt(indexOfFirstWhiteSpace - 1))
            ? indexOfFirstWhiteSpace - 1 // Use lat band index instead
            : indexOfFirstWhiteSpace;
    return input.substring(0, indexOfFirstWhiteSpaceOrLatBand).concat(Character.toString(newLatBand))
            .concat(input.substring(indexOfFirstWhiteSpace));
}

From source file:importer.filters.CceFilter.java

/**
 * Convert all the files in a directory 
 * @param input the raw text input string
 * @param name the name of the new version
 * @param cortext a cortext mvd archive/* w  ww  .j  av  a  2s  . c o m*/
 * @param corcode a corcode mvd archive
 * @return the log
 */
public String convert(String input, String name, Archive cortex, Archive corcode) throws ImporterException {
    try {
        init();
        CharArrayWriter txt = new CharArrayWriter();
        String lastWord = "";
        String firstWord = "";
        String lineEnd = findLineEnding(input);
        String[] lines = input.split(lineEnd);
        paraSeen = true;
        for (int i = 0; i < lines.length; i++) {
            String str = lines[i].trim();
            firstWord = getFirstWord(str);
            if (str.startsWith(".") && str.length() > 1 && Character.isLetter(str.charAt(1))) {
                convertDotCommand(str, txt);
                if (!lastEndsInHyphen && written > 0)
                    writeCurrent(txt, SPACE);
                // don't reset lastWord
                continue;
            } else if (lines[i].startsWith("   ")) {
                Range r;
                if (!paraSeen)
                    paraSeen = true;
                else if (written > paraStart) {
                    // write previous para range
                    r = new Range("p", paraStart, written - paraStart);
                    markup.add(r);
                }
                if (written > 0)
                    writeCurrent(txt, CR);
                paraStart = written;
                // markup new paragraphs with 4 spaces for readability
                r = new Range(CSSStyles.PARA_START, written, 4);
                markup.add(r);
                writeLineContents("    " + str, txt);
            } else {
                if (lastEndsInHyphen) {
                    Range r;
                    if (isHardHyphen(lastWord, firstWord)) {
                        r = new Range(CSSStyles.STRONG, written - 1, 1);
                        markup.add(r);
                    } else {
                        r = new Range(CSSStyles.WEAK, written - 1, 1);
                        markup.add(r);
                    }
                    writeCurrent(txt, CR);
                    r = new Range(CSSStyles.HYPHEN_CR, written - 1, 1);
                    markup.add(r);
                } else if (written > 0) {
                    writeCurrent(txt, CR);
                    if (written == paraStart + 1)
                        paraStart = written;
                }
                writeLineContents(str, txt);
            }
            if (!lineCommands.isEmpty()) {
                for (int j = lineCommands.size() - 1; j >= 0; j--) {
                    Range r = new Range(lineCommands.get(j), paraStart, written - paraStart);
                    markup.add(r);
                }
                lineCommands.clear();
                paraStart = written;
            }
            lastWord = getLastWord(str);
        }
        // write closing para range
        if (written > paraStart) {
            Range r = new Range("p", paraStart, written - paraStart);
            markup.add(r);
        }
        markup.sort();
        char[] chars = txt.toCharArray();
        cortex.put(name, chars);
        String json = markup.toSTILDocument().toString();
        corcode.put(name, json.toCharArray());
    } catch (Exception e) {
        e.printStackTrace(System.out);
    }
    return "";
}

From source file:com.oncore.calorders.core.utils.FormatHelper.java

/**
 * The <code>isNameValid</code> method checks if the CharSequence contains
 * only unicode letters, spaces, apostrophes, and reverse apostrophes
 *
 * <pre>//from w ww  .j a  v  a2 s . c o  m
 * PageUtilities.isNameValid(null) = false
 * PageUtilities.isNameValid("") = false
 * PageUtilities.isNameValid(" ") = false
 * PageUtilities.isNameValid("abc") = true
 * PageUtilities.isNameValid("ab c") = true
 * PageUtilities.isNameValid("ab2c") = false
 * PageUtilities.isNameValid("ab-c") = false
 * PageUtilities.isNameValid("9999") = false
 * PageUtilities.isNameValid("For instance, this is bla") = false
 * PageUtilities.isNameValid("John Doe") = true
 * PageUtilities.isNameValid("John O'Brien") = true
 * PageUtilities.isNameValid("John O`Brien") = true
 * PageUtilities.isNameValid("John") = true
 * PageUtilities.isNameValid("Smith") = true
 * PageUtilities.isNameValid("John O@Brien") = false
 * </pre>
 *
 * @author OnCore Consulting LLC
 *
 * @param cs the CharSequence to check, may be null
 *
 * @return true if only unicode letters, spaces, apostrophes, and reverse
 * apostrophes, false otherwise
 */
@SuppressWarnings("empty-statement")
public static Boolean isNameValid(final CharSequence cs) {
    if (StringUtils.isBlank(String.valueOf(cs))) {
        return Boolean.FALSE;
    }

    final int size = cs.length();

    for (int i = 0; i < size; i++) {
        if ('\'' == cs.charAt(i) || '`' == cs.charAt(i) || cs.charAt(i) == ' '
                || (Character.isLetter(cs.charAt(i)) == true)) {
            ; // do nothing
        } else {
            return Boolean.FALSE;
        }
    }

    return Boolean.TRUE;
}

From source file:org.apache.brooklyn.util.net.Urls.java

/** returns the protocol (e.g. http) if one appears to be specified, or else null;
 * 'protocol' here should consist of 2 or more _letters_ only followed by a colon
 * (2 required to prevent {@code c:\xxx} being treated as a url)
 *///from  w w  w.j  a va2  s  . co  m
public static String getProtocol(String url) {
    if (url == null)
        return null;
    int i = 0;
    StringBuilder result = new StringBuilder();
    while (true) {
        if (url.length() <= i)
            return null;
        char c = url.charAt(i);
        if (Character.isLetter(c))
            result.append(c);
        else if (c == ':') {
            if (i >= 2)
                return result.toString().toLowerCase();
            return null;
        } else
            return null;
        i++;
    }
}