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:SystemIDResolver.java

/**
* Return true if the local path is a Windows absolute path.
*
* @param systemId The path string//from   ww  w . j  a  va 2 s . c  o  m
* @return true if the path is a Windows absolute path
*/
private static boolean isWindowsAbsolutePath(String systemId) {
    if (!isAbsolutePath(systemId))
        return false;
    // On Windows, an absolute path starts with "[drive_letter]:\".
    if (systemId.length() > 2 && systemId.charAt(1) == ':' && Character.isLetter(systemId.charAt(0))
            && (systemId.charAt(2) == '\\' || systemId.charAt(2) == '/'))
        return true;
    else
        return false;
}

From source file:org.marketcetera.trade.ConvertibleBond.java

/**
 * Gets the ISIN for this security using the given country code.
 *
 * @param inCountryCode a <code>String</code> value
 * @return a <code>String</code> value
 *//*from   w  w  w.j  a  v a 2s. c om*/
public String getIsin(String inCountryCode) {
    StringBuilder output = new StringBuilder();
    output.append(inCountryCode).append(cusip);
    int sum = 0;
    int index = 0;
    for (int i = cusip.length() - 1; i >= 0; i--) {
        char c = cusip.charAt(i);
        int asciiValue = (int) c;
        if (Character.isLetter(c)) {
            asciiValue = ((int) Character.toUpperCase(c)) - 55;
        } else {
            asciiValue -= 48;
        }
        if (index++ % 2 == 0) {
            asciiValue *= 2;
            String asciiValueAsString = String.valueOf(asciiValue);
            for (char asciiValueChar : asciiValueAsString.toCharArray()) {
                int innerValue = (int) asciiValueChar - 48;
                sum += innerValue;
            }
        } else {
            sum += asciiValue;
        }
    }
    int subtrahend = sum;
    while (subtrahend % 10 != 0) {
        subtrahend += 1;
    }
    sum = subtrahend - sum;
    output.append(sum);
    return output.toString();
}

From source file:com.mifos.mifosxdroid.formwidgets.FormWidget.java

/**
 * takes a property name and modifies/*from w  w  w.j av  a  2 s . c  o m*/
 *
 * @param s
 * @return
 */
public String toTitleCase(String s) {
    char[] chars = s.trim().toLowerCase().toCharArray();
    boolean found = false;

    for (int i = 0; i < chars.length; i++) {
        if (!found && Character.isLetter(chars[i])) {
            chars[i] = Character.toUpperCase(chars[i]);
            found = true;
        } else if (Character.isWhitespace(chars[i])) {
            found = false;
        }
    }

    return String.valueOf(chars);
}

From source file:edu.illinois.cs.cogcomp.edison.features.lrec.TestWordTypeInformation.java

public final void test() throws EdisonException {

    log.debug("WordTypeInformation");
    // Using the first TA and a constituent between span of 0 - 20 as a test
    TextAnnotation ta = tas.get(1);/* w ww  .  j  a  va 2 s.  c  o m*/
    View TOKENS = ta.getView("TOKENS");

    log.debug("GOT TOKENS FROM TEXTAnn");

    List<Constituent> testlist = TOKENS.getConstituentsCoveringSpan(0, 20);
    String[] teststrings = new String[5];

    int i = 0, start = 1, end = 6;

    for (Constituent c : testlist) {
        log.debug(c.getSurfaceForm());
        if (i >= start && i < end) {
            teststrings[i - start] = c.getSurfaceForm();
        }
        i++;
    }

    log.debug("Testlist size is " + testlist.size());

    Constituent test = testlist.get(3);

    log.debug("The constituent we are extracting features from in this test is: " + test.getSurfaceForm());

    WordTypeInformation wti = new WordTypeInformation("WordTypeInformation");

    log.debug("Startspan is " + test.getStartSpan() + " and Endspan is " + test.getEndSpan());

    Set<Feature> feats = wti.getFeatures(test);
    String[] expected_outputs = { "WordTypeInformation:c0(false)", "WordTypeInformation:d0(false)",
            "WordTypeInformation:c1(false)", "WordTypeInformation:d1(false)", "WordTypeInformation:c2(false)",
            "WordTypeInformation:d2(false)", "WordTypeInformation:c2(true)", "WordTypeInformation:c3(false)",
            "WordTypeInformation:d3(false)", "WordTypeInformation:c4(false)", "WordTypeInformation:d4(false)",
            "WordTypeInformation:c4(true)" };

    Set<String> __result = new LinkedHashSet<String>();
    String __id;
    String __value;
    String classifier = "WordTypeInformation";

    if (feats == null) {
        log.debug("Feats are returning NULL.");
        assertFalse(true);
    }

    log.debug("Printing Set of Features");
    for (Feature f : feats) {
        log.debug(f.getName());
        assert (ArrayUtils.contains(expected_outputs, f.getName()));
    }

    for (; (start < end && teststrings[start - 1] != null); start++) {

        boolean allCapitalized = true, allDigits = true, allNonLetters = true;

        for (int j = 0; j < teststrings[start - 1].length(); ++j) {

            allCapitalized &= Character.isUpperCase(teststrings[start - 1].charAt(j));
            allDigits &= Character.isDigit(teststrings[start - 1].charAt(j));
            allNonLetters &= !Character.isLetter(teststrings[start - 1].charAt(j));

        }
        __id = classifier + ":" + ("c" + (start - 1));
        __value = "(" + (allCapitalized) + ")";
        __result.add(__id + __value);
        __id = classifier + ":" + ("d" + (start - 1));
        __value = "(" + (allDigits) + ")";
        __result.add(__id + __value);
        __id = classifier + ":" + ("c" + (start - 1));
        __value = "(" + (allNonLetters) + ")";
        __result.add(__id + __value);
    }

    for (Feature feat : feats) {
        if (!__result.contains(feat.getName())) {
            assertFalse(true);
        }
    }

    // System.exit(0);
}

From source file:de.tudarmstadt.ukp.dkpro.core.jazzy.SpellChecker.java

@Override
public void process(final JCas jcas) throws AnalysisEngineProcessException {
    for (Token t : select(jcas, Token.class)) {
        String tokenText = t.getCoveredText();
        if (tokenText.matches("[\\.\\?\\!]")) {
            continue;
        }/*from   w  ww.  j ava2s.co m*/
        if (!dict.isCorrect(tokenText)) {
            SpellingAnomaly anomaly = new SpellingAnomaly(jcas, t.getBegin(), t.getEnd());

            // only try to correct single character tokens if they are letters
            if (tokenText.length() == 1 && !Character.isLetter(tokenText.charAt(0))) {
                continue;
            }

            @SuppressWarnings("unchecked")
            List<Word> suggestions = dict.getSuggestions(tokenText, scoreThreshold);

            SuggestionCostTuples tuples = new SuggestionCostTuples();
            for (Word suggestion : suggestions) {
                String suggestionString = suggestion.getWord();
                int cost = suggestion.getCost();

                if (suggestionString != null) {
                    tuples.addTuple(suggestionString, cost);
                }
            }

            if (tuples.size() > 0) {
                FSArray actions = new FSArray(jcas, tuples.size());
                int i = 0;
                for (SuggestionCostTuple tuple : tuples) {
                    SuggestedAction action = new SuggestedAction(jcas);
                    action.setReplacement(tuple.getSuggestion());
                    action.setCertainty(tuple.getNormalizedCost(tuples.getMaxCost()));

                    actions.set(i, action);
                    i++;
                }
                anomaly.setSuggestions(actions);
                anomaly.addToIndexes();
            }
        }
    }
}

From source file:com.gargoylesoftware.htmlunit.source.JQueryExtractor.java

/**
 * Generates the java code of the test cases.
 * @param testClass the class containing the tests
 * @param dir the directory which holds the expectations
 * @throws Exception if an error occurs.
 *///from w  w  w  .  j  ava2s . c om
public static void generateTestCases(final Class<? extends WebDriverTestCase> testClass, final File dir)
        throws Exception {
    final Browser[] browsers = Browser.values();
    // main browsers regardless of version e.g. "FF"
    final List<String> mainNames = new ArrayList<>();
    for (final Browser b : browsers) {
        final String name = b.name();
        if (!"NONE".equals(name) && Character.isLetter(name.charAt(name.length() - 1))) {
            mainNames.add(name);
        }
    }

    final Map<String, List<String>> browserVersions = new HashMap<>();
    for (final Browser b : browsers) {
        final String name = b.name();
        for (final String mainName : mainNames) {
            if (!name.equals(mainName) && name.startsWith(mainName)) {
                List<String> list = browserVersions.get(mainName);
                if (list == null) {
                    list = new ArrayList<>();
                    browserVersions.put(mainName, list);
                }
                list.add(name);
            }
        }
    }
    final Map<String, Expectations> browserExpectations = new HashMap<>();
    for (final File file : dir.listFiles()) {
        if (file.isFile() && file.getName().endsWith(".txt")) {
            for (final Browser b : browsers) {
                final String browserName = b.name();
                if (file.getName().equalsIgnoreCase("results." + browserName.replace('_', '.') + ".txt")) {
                    browserExpectations.put(browserName, Expectations.readExpectations(file));
                }
            }
        }
    }

    // gather all the tests (some tests don't get executed for all browsers)
    final List<Test> allTests = computeTestsList(browserExpectations);

    final Collection<String> availableBrowserNames = new TreeSet<>(browserExpectations.keySet());
    for (final Test test : allTests) {
        final Map<String, String> testExpectation = new TreeMap<>();
        final Map<Integer, List<String>> lineToBrowser = new TreeMap<>();
        for (final String browserName : availableBrowserNames) {
            final Expectation expectation = browserExpectations.get(browserName).getExpectation(test);
            if (expectation != null) {
                List<String> browsersForLine = lineToBrowser.get(expectation.getLine());
                if (browsersForLine == null) {
                    browsersForLine = new ArrayList<>();
                    lineToBrowser.put(expectation.getLine(), browsersForLine);
                }
                browsersForLine.add(browserName);
                final String str = expectation.getTestResult();
                testExpectation.put(browserName,
                        str.replaceAll("\\\\", "\\\\\\\\").replaceAll("\\\"", "\\\\\""));
            }
        }
        System.out.println("    /**");
        System.out.println("     * Test " + lineToBrowser + ".");
        System.out.println("     * @throws Exception if an error occurs");
        System.out.println("     */");
        System.out.println("    @Test");
        System.out.print("    @Alerts(");

        final boolean allSame = testExpectation.size() == availableBrowserNames.size()
                && new HashSet<>(testExpectation.values()).size() == 1;
        if (allSame) {
            final String first = testExpectation.keySet().iterator().next();
            String expectation = testExpectation.get(first);
            if (expectation.length() > 100) {
                expectation = expectation.substring(0, 50) + "\"\n            + \"" + expectation.substring(50);
            }
            System.out.print("\"" + expectation + '"');
        } else {
            boolean first = true;
            for (final String browserName : availableBrowserNames) {
                final String expectation = testExpectation.get(browserName);
                if (expectation == null) {
                    continue; // test didn't run for this browser
                }
                if (!first) {
                    System.out.println(",");
                    System.out.print("        ");
                }
                System.out.print(browserName + " = \"" + expectation + '"');
                first = false;
            }
        }
        System.out.println(")");

        final String methodName = test.getName().replaceAll("\\W", "_");
        try {
            final Method method = testClass.getMethod(methodName);
            final NotYetImplemented notYetImplemented = method.getAnnotation(NotYetImplemented.class);
            if (null != notYetImplemented) {
                final Browser[] notYetImplementedBrowsers = notYetImplemented.value();
                if (notYetImplementedBrowsers.length > 0) {
                    final List<String> browserNames = new ArrayList<>(notYetImplementedBrowsers.length);
                    for (Browser browser : notYetImplementedBrowsers) {
                        browserNames.add(browser.name());
                    }
                    Collections.sort(browserNames);

                    // TODO dirty hack
                    if (browserNames.size() == 3 && browserNames.contains("CHROME")
                            && browserNames.contains("FF") && browserNames.contains("IE")) {
                        System.out.println("    @NotYetImplemented");
                    } else {
                        System.out.print("    @NotYetImplemented(");
                        if (browserNames.size() > 1) {
                            System.out.print("{ ");
                        }
                        System.out.print(StringUtils.join(browserNames, ", "));
                        if (browserNames.size() > 1) {
                            System.out.print(" }");
                        }
                        System.out.println(")");
                    }
                }
            }
        } catch (final NoSuchMethodException e) {
            // ignore
        }

        System.out
                .println("    public void " + test.getName().replaceAll("\\W", "_") + "() throws Exception {");
        System.out.println("        runTest(\"" + test.getName().replace("\"", "\\\"") + "\");");
        System.out.println("    }");
        System.out.println();
    }
}

From source file:org.apache.lucene.analysis.de.GermanStemmer.java

/**
  * Checks if a term could be stemmed.//from   ww w .  j a  v a  2  s  .c o  m
  * 
  * @return true if, and only if, the given term consists in letters.
  */
 private boolean isStemmable(String term) {
     for (int c = 0; c < term.length(); c++) {
         if (!Character.isLetter(term.charAt(c)))
             return false;
     }
     return true;
 }

From source file:io.horizondb.model.core.fields.TimestampField.java

/**    
 * {@inheritDoc}/*  ww  w  .  j av  a 2  s  .c om*/
 */
@Override
public Field setValueFromString(TimeZone timeZone, String s) {

    if (s.startsWith("'") && s.endsWith("'")) {

        String dateTime = s.substring(1, s.length() - 1);
        long timeInMillis = TimeUtils.parseDateTime(timeZone, dateTime);
        setTimestampInMillis(timeInMillis);

    } else {

        int length = s.length();
        int index = length - 1;

        while (Character.isLetter(s.charAt(index))) {

            index--;
        }

        String symbol = s.substring(index + 1);
        String t = s.substring(0, index + 1);

        setTimestamp(Long.parseLong(t), getTimeUnit(symbol));
    }

    return this;
}

From source file:org.seo.rank.impl.BaiduCopyChecker.java

/**
 * title2??title1//from   ww  w.  j  av a  2 s  .c  o  m
 * @param title2
 * @param title1
 * @return
 */
private static boolean contains(String title2, String title1) {
    StringBuilder str2 = new StringBuilder();
    StringBuilder str1 = new StringBuilder();
    for (char c : title2.toCharArray()) {
        if (Character.isLetter(c)) {
            str2.append(c);
        }
    }
    for (char c : title1.toCharArray()) {
        if (Character.isLetter(c)) {
            str1.append(c);
        }
    }
    LOGGER.debug("??" + title2);
    LOGGER.debug("??" + str2.toString());
    LOGGER.debug("??" + title1);
    LOGGER.debug("??" + str1.toString());
    if (str2.toString().contains(str1.toString())) {
        LOGGER.debug(title2 + " ?? " + title1);
        return true;
    }
    LOGGER.debug(title2 + " ??? " + title1);
    return false;
}

From source file:de.nava.informa.utils.FormatDetector.java

/**
 * Gets the name of the root element and the attributes (inclusive
 * namespace declarations).//from  w  w  w.  j  a  v a  2s .com
 */
private static String getRootElement(byte[] b) {
    String s = new String(b);
    int startPos = 0;
    int endPos = 0;
    boolean inComment = false;
    for (int i = 0; i < s.length(); i++) {
        if (s.charAt(i) == '<' && Character.isLetter(s.charAt(i + 1)) && !inComment) {
            startPos = i + 1;
            for (int j = i + 1; j < s.length(); j++) {
                if (s.charAt(j) == '>') {
                    endPos = j;
                    break;
                }
            }
            break;
        } else if (!inComment && s.charAt(i) == '<' && s.charAt(i + 1) == '!' && s.charAt(i + 2) == '-'
                && s.charAt(i + 3) == '-')
            inComment = true;
        else if (inComment && s.charAt(i) == '-' && s.charAt(i + 1) == '-' && s.charAt(i + 2) == '>')
            inComment = false;
    } // for i
    if (startPos >= 0 && endPos >= 0 && endPos > startPos) {
        return s.substring(startPos, endPos);
    } else {
        throw new IllegalArgumentException("Unable to retrieve root " + "element from " + s);
    }
}