Example usage for java.lang Character isDigit

List of usage examples for java.lang Character isDigit

Introduction

In this page you can find the example usage for java.lang Character isDigit.

Prototype

public static boolean isDigit(int codePoint) 

Source Link

Document

Determines if the specified character (Unicode code point) is a digit.

Usage

From source file:net.sf.jabref.gui.AutoCompleteListener.java

@Override
public void keyTyped(KeyEvent e) {
    LOGGER.debug("key typed event caught " + e.getKeyCode());
    char ch = e.getKeyChar();
    if (ch == '\n') {
        // this case is handled at keyPressed(e)
        return;/*w  ww .j av a  2s  . c  om*/
    }

    if ((e.getModifiers() | InputEvent.SHIFT_MASK) == InputEvent.SHIFT_MASK) {
        // plain key or SHIFT + key is pressed, no handling of CTRL+key,  META+key, ...
        if (Character.isLetter(ch) || Character.isDigit(ch)
                || (Character.isWhitespace(ch) && completer.isSingleUnitField())) {
            JTextComponent comp = (JTextComponent) e.getSource();

            if (toSetIn == null) {
                LOGGER.debug("toSetIn is null");
            } else {
                LOGGER.debug("toSetIn: >" + toSetIn + '<');
            }

            // The case-insensitive system is a bit tricky here
            // If keyword is "TODO" and user types "tO", then this is treated as "continue" as the "O" matches the "O"
            // If keyword is "TODO" and user types "To", then this is treated as "discont" as the "o" does NOT match the "O".

            if ((toSetIn != null) && (toSetIn.length() > 1) && (ch == toSetIn.charAt(1))) {
                // User continues on the word that was suggested.
                LOGGER.debug("cont");

                toSetIn = toSetIn.substring(1);
                if (!toSetIn.isEmpty()) {
                    int cp = comp.getCaretPosition();
                    //comp.setCaretPosition(cp+1-toSetIn.);
                    //System.out.println(cp-toSetIn.length()+" - "+cp);
                    comp.select((cp + 1) - toSetIn.length(), cp);
                    lastBeginning = lastBeginning + ch;

                    e.consume();
                    lastCaretPosition = comp.getCaretPosition();

                    //System.out.println("Added char: '"+toSetIn+"'");
                    //System.out.println("LastBeginning: '"+lastBeginning+"'");

                    lastCompletions = findCompletions(lastBeginning, comp);
                    lastShownCompletion = 0;
                    for (int i = 0; i < lastCompletions.length; i++) {
                        String lastCompletion = lastCompletions[i];
                        //System.out.println("Completion["+i+"] = "+lastCompletion);
                        if (lastCompletion.endsWith(toSetIn)) {
                            lastShownCompletion = i;
                            break;
                        }

                    }
                    //System.out.println("Index now: "+lastShownCompletion);
                    if (toSetIn.length() < 2) {
                        // User typed the last character of the autocompleted word
                        // We have to replace the automcompletion word by the typed word.
                        // This helps if the user presses "space" after the completion
                        // "space" indicates that the user does NOT want the autocompletion,
                        // but the typed word
                        String text = comp.getText();
                        comp.setText(text.substring(0, lastCaretPosition - lastBeginning.length())
                                + lastBeginning + text.substring(lastCaretPosition));
                        // there is no selected text, therefore we are not updating the selection
                        toSetIn = null;
                    }
                    return;
                }
            }

            if ((toSetIn != null) && ((toSetIn.length() <= 1) || (ch != toSetIn.charAt(1)))) {
                // User discontinues the word that was suggested.
                lastBeginning = lastBeginning + ch;

                LOGGER.debug("discont toSetIn: >" + toSetIn + "'<' lastBeginning: >" + lastBeginning + '<');

                String[] completed = findCompletions(lastBeginning, comp);
                if ((completed != null) && (completed.length > 0)) {
                    lastShownCompletion = 0;
                    lastCompletions = completed;
                    String sno = completed[0];
                    // toSetIn = string used for autocompletion last time
                    // this string has to be removed
                    // lastCaretPosition is the position of the caret after toSetIn.
                    int lastLen = toSetIn.length() - 1;
                    toSetIn = sno.substring(lastBeginning.length() - 1);
                    String text = comp.getText();
                    //Util.pr(""+lastLen);
                    //we do not use toSetIn as we want to obey the casing of "sno"
                    comp.setText(text.substring(0, (lastCaretPosition - lastLen - lastBeginning.length()) + 1)
                            + sno + text.substring(lastCaretPosition));
                    int startSelect = (lastCaretPosition + 1) - lastLen;
                    int endSelect = (lastCaretPosition + toSetIn.length()) - lastLen;
                    comp.select(startSelect, endSelect);

                    lastCaretPosition = comp.getCaretPosition();
                    e.consume();
                    return;
                } else {
                    setUnmodifiedTypedLetters(comp, true, false);
                    e.consume();
                    toSetIn = null;
                    return;
                }
            }

            LOGGER.debug("case else");

            comp.replaceSelection("");

            StringBuffer currentword = getCurrentWord(comp);
            if (currentword == null) {
                currentword = new StringBuffer();
            }

            // only "real characters" end up here
            assert (!Character.isISOControl(ch));
            currentword.append(ch);
            startCompletion(currentword, e);
            return;
        } else {
            if (Character.isWhitespace(ch)) {
                assert (!completer.isSingleUnitField());
                LOGGER.debug("whitespace && !singleUnitField");
                // start a new search if end-of-field is reached

                // replace displayed letters with typed letters
                setUnmodifiedTypedLetters((JTextComponent) e.getSource(), false, true);
                resetAutoCompletion();
                return;
            }

            LOGGER.debug("No letter/digit/whitespace or CHAR_UNDEFINED");
            // replace displayed letters with typed letters 
            setUnmodifiedTypedLetters((JTextComponent) e.getSource(), false, !Character.isISOControl(ch));
            resetAutoCompletion();
            return;
        }
    }
    resetAutoCompletion();
}

From source file:XmlChars.java

private static boolean isDigit(char c) {
    // [88] Digit ::= ... 

    ///*from  w  ww.j  a va  2s  . c o  m*/
    // java.lang.Character.isDigit is correct from the XML point
    // of view except that it allows "fullwidth" digits.
    //
    return Character.isDigit(c) && !((c >= 0xff10) && (c <= 0xff19));
}

From source file:clus.algo.tdidt.tune.CDTuneSizeConstrPruning.java

public final XValMainSelection getXValSelection(Settings sett, int nbrows) throws IOException, ClusException {
    String value = sett.getTuneFolds();
    if (value.length() > 0 && Character.isDigit(value.charAt(0))) {
        try {/*from  w  w  w. j ava  2s. c o  m*/
            int nbfolds = Integer.parseInt(value);
            Random random = new Random(0);
            return new XValRandomSelection(nbrows, nbfolds, random);
        } catch (NumberFormatException e) {
            throw new ClusException("Illegal number of folds: " + value);
        }
    } else {
        return XValDataSelection.readFoldsFile(value, nbrows);
    }
}

From source file:net.sf.jailer.Configuration.java

/**
  * Sets replacement map for special characters in string literals.
  *//*from w w w.j  a v  a  2s. c o m*/
public void setStringLiteralEscapeSequences(Map<String, String> stringLiteralEscapeSequences) {
    this.stringLiteralEscapeSequences = stringLiteralEscapeSequences;
    try {
        for (Map.Entry<String, String> e : stringLiteralEscapeSequences.entrySet()) {
            if (e.getKey().startsWith("\\")) {
                char c;
                char c2 = e.getKey().charAt(1);
                if (Character.isDigit(c2)) {
                    c = (char) Integer.parseInt(e.getKey().substring(1));
                } else if (c2 == '\\') {
                    c = '\\';
                } else if (c2 == 'b') {
                    c = '\b';
                } else if (c2 == 'n') {
                    c = '\n';
                } else if (c2 == 't') {
                    c = '\t';
                } else if (c2 == 'r') {
                    c = '\r';
                } else {
                    throw new RuntimeException("illegal escape sequence: " + e.getKey());
                }
                charToEscapeSequence.put(c, e.getValue());
            } else {
                charToEscapeSequence.put(e.getKey().charAt(0), e.getValue());
            }
        }
        keysOfCharToEscapeSequence = new char[charToEscapeSequence.keySet().size()];
        int i = 0;
        for (char c : charToEscapeSequence.keySet()) {
            keysOfCharToEscapeSequence[i++] = c;
        }
    } catch (Exception e) {
        throw new RuntimeException("cannot recognize key of stringLiteralEscapeSequences-entry", e);
    }
}

From source file:hudson.org.apache.tools.ant.taskdefs.cvslib.ChangeLogTask.java

/**
 * Rip off from {@link CvsVersion#supportsCvsLogWithSOption()}
 * but we need to check both client and server.
 *///from   ww w . ja v a 2s. c  o m
private boolean supportsCvsLogWithSOption(String versionString) {
    if (versionString == null) {
        return false;
    }
    StringTokenizer mySt = new StringTokenizer(versionString, ".");
    long counter = MULTIPLY * MULTIPLY;
    long version = 0;
    while (mySt.hasMoreTokens()) {
        String s = mySt.nextToken();
        int startpos;
        // find the first digit char
        for (startpos = 0; startpos < s.length(); startpos++) {
            if (Character.isDigit(s.charAt(startpos))) {
                break;
            }
        }
        // ... and up to the end of this digit set
        int i;
        for (i = startpos; i < s.length(); i++) {
            if (!Character.isDigit(s.charAt(i))) {
                break;
            }
        }
        String s2 = s.substring(startpos, i);
        version = version + counter * Long.parseLong(s2);
        if (counter == 1) {
            break;
        }
        counter = counter / MULTIPLY;
    }
    return (version >= VERSION_1_11_2);
}

From source file:net.sf.jabref.gui.autocompleter.AutoCompleteListener.java

@Override
public void keyTyped(KeyEvent e) {
    LOGGER.debug("key typed event caught " + e.getKeyCode());
    char ch = e.getKeyChar();
    if (ch == '\n') {
        // this case is handled at keyPressed(e)
        return;//from  w w  w  .j a  v a 2  s .  co  m
    }

    // don't do auto completion inside words
    if (!atEndOfWord((JTextComponent) e.getSource())) {
        return;
    }

    if ((e.getModifiers() | InputEvent.SHIFT_MASK) == InputEvent.SHIFT_MASK) {
        // plain key or SHIFT + key is pressed, no handling of CTRL+key,  META+key, ...
        if (Character.isLetter(ch) || Character.isDigit(ch)
                || (Character.isWhitespace(ch) && completer.isSingleUnitField())) {
            JTextComponent comp = (JTextComponent) e.getSource();

            if (toSetIn == null) {
                LOGGER.debug("toSetIn is null");
            } else {
                LOGGER.debug("toSetIn: >" + toSetIn + '<');
            }

            // The case-insensitive system is a bit tricky here
            // If keyword is "TODO" and user types "tO", then this is treated as "continue" as the "O" matches the "O"
            // If keyword is "TODO" and user types "To", then this is treated as "discont" as the "o" does NOT match the "O".

            if ((toSetIn != null) && (toSetIn.length() > 1) && (ch == toSetIn.charAt(1))) {
                // User continues on the word that was suggested.
                LOGGER.debug("cont");

                toSetIn = toSetIn.substring(1);
                if (!toSetIn.isEmpty()) {
                    int cp = comp.getCaretPosition();
                    //comp.setCaretPosition(cp+1-toSetIn.);
                    comp.select((cp + 1) - toSetIn.length(), cp);
                    lastBeginning = lastBeginning + ch;

                    e.consume();
                    lastCaretPosition = comp.getCaretPosition();

                    lastCompletions = findCompletions(lastBeginning);
                    lastShownCompletion = 0;
                    for (int i = 0; i < lastCompletions.size(); i++) {
                        String lastCompletion = lastCompletions.get(i);
                        if (lastCompletion.endsWith(toSetIn)) {
                            lastShownCompletion = i;
                            break;
                        }

                    }
                    if (toSetIn.length() < 2) {
                        // User typed the last character of the autocompleted word
                        // We have to replace the automcompletion word by the typed word.
                        // This helps if the user presses "space" after the completion
                        // "space" indicates that the user does NOT want the autocompletion,
                        // but the typed word
                        String text = comp.getText();
                        comp.setText(text.substring(0, lastCaretPosition - lastBeginning.length())
                                + lastBeginning + text.substring(lastCaretPosition));
                        // there is no selected text, therefore we are not updating the selection
                        toSetIn = null;
                    }
                    return;
                }
            }

            if ((toSetIn != null) && ((toSetIn.length() <= 1) || (ch != toSetIn.charAt(1)))) {
                // User discontinues the word that was suggested.
                lastBeginning = lastBeginning + ch;

                LOGGER.debug("discont toSetIn: >" + toSetIn + "'<' lastBeginning: >" + lastBeginning + '<');

                List<String> completed = findCompletions(lastBeginning);
                if ((completed != null) && (!completed.isEmpty())) {
                    lastShownCompletion = 0;
                    lastCompletions = completed;
                    String sno = completed.get(0);
                    // toSetIn = string used for autocompletion last time
                    // this string has to be removed
                    // lastCaretPosition is the position of the caret after toSetIn.
                    int lastLen = toSetIn.length() - 1;
                    toSetIn = sno.substring(lastBeginning.length() - 1);
                    String text = comp.getText();
                    //we do not use toSetIn as we want to obey the casing of "sno"
                    comp.setText(text.substring(0, (lastCaretPosition - lastLen - lastBeginning.length()) + 1)
                            + sno + text.substring(lastCaretPosition));
                    int startSelect = (lastCaretPosition + 1) - lastLen;
                    int endSelect = (lastCaretPosition + toSetIn.length()) - lastLen;
                    comp.select(startSelect, endSelect);

                    lastCaretPosition = comp.getCaretPosition();
                    e.consume();
                    return;
                } else {
                    setUnmodifiedTypedLetters(comp, true, false);
                    e.consume();
                    toSetIn = null;
                    return;
                }
            }

            LOGGER.debug("case else");

            comp.replaceSelection("");

            StringBuffer currentword = getCurrentWord(comp);

            // only "real characters" end up here
            assert (!Character.isISOControl(ch));
            currentword.append(ch);
            startCompletion(currentword, e);
            return;
        } else {
            if (Character.isWhitespace(ch)) {
                assert (!completer.isSingleUnitField());
                LOGGER.debug("whitespace && !singleUnitField");
                // start a new search if end-of-field is reached

                // replace displayed letters with typed letters
                setUnmodifiedTypedLetters((JTextComponent) e.getSource(), false, true);
                resetAutoCompletion();
                return;
            }

            LOGGER.debug("No letter/digit/whitespace or CHAR_UNDEFINED");
            // replace displayed letters with typed letters
            setUnmodifiedTypedLetters((JTextComponent) e.getSource(), false, !Character.isISOControl(ch));
            resetAutoCompletion();
            return;
        }
    }
    resetAutoCompletion();
}

From source file:org.jsonschema2pojo.rules.EnumRule.java

protected String getConstantName(String nodeName, String customName) {
    if (isNotBlank(customName)) {
        return customName;
    }/* w w w .j a  v  a 2 s  .co  m*/

    List<String> enumNameGroups = new ArrayList<String>(asList(splitByCharacterTypeCamelCase(nodeName)));

    String enumName = "";
    for (Iterator<String> iter = enumNameGroups.iterator(); iter.hasNext();) {
        if (containsOnly(ruleFactory.getNameHelper().replaceIllegalCharacters(iter.next()), "_")) {
            iter.remove();
        }
    }

    enumName = upperCase(join(enumNameGroups, "_"));

    if (isEmpty(enumName)) {
        enumName = "__EMPTY__";
    } else if (Character.isDigit(enumName.charAt(0))) {
        enumName = "_" + enumName;
    }

    return enumName;
}

From source file:de.xwic.sandbox.base.model.StringUtil.java

/**
 * @param maybeNumber//from   w  ww .  j  ava  2s  .co  m
 *            parameter to check
 * @return true only if the string contains only digits or false if it's null, empty or has any other characters (even whitespace)
 */
public static boolean isNumber(final String maybeNumber) {
    if (isEmpty(maybeNumber)) {
        return false;
    }
    for (final char c : maybeNumber.toCharArray()) {
        if (!Character.isDigit(c)) {
            return false;
        }
    }
    return true;
}

From source file:gov.nih.nci.ncicb.cadsr.evs.LexEVSQueryServiceImpl.java

private String findBestContainsAlgorithm(String matchText) {
    if (matchText == null)
        return "nonLeadingWildcardLiteralSubString";
    matchText = matchText.trim();/*from   w  w  w  .java2 s .c om*/
    if (matchText.length() == 0)
        return "nonLeadingWildcardLiteralSubString"; // or null
    if (matchText.length() > 1)
        return "nonLeadingWildcardLiteralSubString";
    char ch = matchText.charAt(0);
    if (Character.isDigit(ch))
        return "literal";
    else if (Character.isLetter(ch))
        return "LuceneQuery";
    else
        return "literalContains";
}

From source file:com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.distributed.kubernetes.v2.KubernetesV2Service.java

default boolean characterAlphanumeric(String value, int index) {
    return Character.isAlphabetic(value.charAt(index)) || Character.isDigit(value.charAt(index));
}