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:com.manydesigns.elements.util.Util.java

public static int compare(String one, String two) {

    if (one == null && two == null) {
        return 0;
    }//from w  w w.jav a2s  .  com
    if (two == null)
        return -1;
    if (one == null)
        return 1;

    int lenone = one.length();
    int lentwo = two.length();
    StringBuilder numberOne = new StringBuilder();
    StringBuilder numberTwo = new StringBuilder();
    int i = 0, j = 0;

    for (; i < lenone && j < lentwo; i++, j++) {

        if (Character.isDigit(one.charAt(i))) {
            if (Character.isDigit(two.charAt(j))) {
                numberOne.setLength(0);
                numberTwo.setLength(0);

                while ((i < lenone) && Character.isDigit(one.charAt(i))) {
                    numberOne.append(one.charAt(i));
                    i++;
                }
                while ((j < lentwo) && Character.isDigit(two.charAt(j))) {
                    numberTwo.append(two.charAt(j));
                    j++;
                }
                long diff = Long.parseLong(numberOne.toString()) - Long.parseLong(numberTwo.toString());
                if (diff > 0) {
                    return 1;
                } else if (diff < 0) {
                    return -1;
                }
            } else {
                return -1;
            }
        } else if (Character.isDigit(two.charAt(j))) {
            return 1;
        } else {
            int diff = Character.toUpperCase(one.charAt(i)) - Character.toUpperCase(two.charAt(j));
            if (diff != 0)
                return diff;
        }
    }

    return lenone - lentwo;
}

From source file:controlador.ControladorReportes.java

@Override
public void keyTyped(KeyEvent e) {
    System.out.println(e.getKeyChar());
    if (!Character.isDigit(e.getKeyChar())) {
        System.out.println(e.getKeyChar());
        e.consume();/*from ww w . ja va 2 s.  com*/
    }
}

From source file:banner.tagging.dictionary.DictionaryTagger.java

protected String transform(String str) {
    // This has been optimized for very fast operation
    String result = str;/*from w  ww .j  ava  2  s .  com*/

    if (stemTokens) {
        String stem = stemmer.stem(str);
        // System.out.println("Stemmer; original= " + str + ", stemmed= " + stem);
        str = stem;
    }
    if (normalizeMixedCase || normalizeDigits) {
        char[] chars = str.toCharArray();
        if (normalizeMixedCase) {
            boolean hasUpper = false;
            boolean hasLower = false;
            for (int i = 0; i < chars.length && (!hasUpper || !hasLower); i++) {
                hasUpper |= Character.isUpperCase(chars[i]);
                hasLower |= Character.isLowerCase(chars[i]);
            }
            if (hasUpper && hasLower)
                for (int i = 0; i < chars.length; i++)
                    chars[i] = Character.toLowerCase(chars[i]);
        }
        // Note that this only works on single digits
        if (normalizeDigits)
            for (int i = 0; i < chars.length; i++)
                if (Character.isDigit(chars[i]))
                    chars[i] = '0';
        result = new String(chars);
    }
    return result;
}

From source file:com.github.jknack.semver.SemverParser.java

private String digits(final String expected) {
    String match = match(new Matcher() {
        @Override//from www  . j a v a  2 s .c o  m
        public boolean match(final char ch) {
            return Character.isDigit(ch) || ch == 'x' || ch == 'X';
        }
    });

    if (isEmpty(match)) {
        throw error(expected);
    }
    return match;
}

From source file:tools.descartes.bungee.viewer.RunResultView.java

@Override
public void createPartControl(final Composite parent) {
    VerifyListener numberVerifier = new VerifyListener() {
        @Override// w  w  w.j  a v  a  2  s . c  o m
        public void verifyText(VerifyEvent event) {
            switch (event.keyCode) {
            case SWT.BS: // Backspace  
            case SWT.DEL: // Delete  
            case SWT.HOME: // Home  
            case SWT.END: // End  
            case SWT.ARROW_LEFT: // Left arrow  
            case SWT.ARROW_RIGHT: // Right arrow  
                return;
            }

            if (!Character.isDigit(event.character)) {
                event.doit = false; // disallow the action  
            }
        }
    };

    Composite composite = new Composite(parent, SWT.NONE);
    GridData gridData = new GridData();
    gridData.verticalAlignment = GridData.FILL;
    gridData.grabExcessVerticalSpace = true;
    gridData.horizontalAlignment = GridData.FILL;
    gridData.grabExcessHorizontalSpace = true;
    Composite compositeChecks1 = new Composite(composite, SWT.NONE);
    compositeChecks1.setLayout(new GridLayout(2, false));
    Text sanityText = new Text(compositeChecks1, SWT.NONE);
    sanityText.setText("Passed Sanity Check:");
    sanityCheckValue = new Button(compositeChecks1, SWT.CHECK);
    sanityCheckValue.setEnabled(false);
    Composite compositeSChecks2 = new Composite(composite, SWT.NONE);
    compositeSChecks2.setLayout(new GridLayout(2, false));
    Text scheduleText = new Text(compositeSChecks2, SWT.NONE);
    scheduleText.setText("Passed Schedule Check:");
    scheduleCheckValue = new Button(compositeSChecks2, SWT.CHECK);
    scheduleCheckValue.setEnabled(false);
    Text completedText = new Text(compositeChecks1, SWT.NONE);
    completedText.setText("Run completed:");
    completedCheckValue = new Button(compositeChecks1, SWT.CHECK);
    completedCheckValue.setEnabled(false);
    Text successText = new Text(compositeSChecks2, SWT.NONE);
    successText.setText("Run successful:");
    successCheckValue = new Button(compositeSChecks2, SWT.CHECK);
    successCheckValue.setEnabled(false);
    Text timingMeanText = new Text(composite, SWT.NONE);
    timingMeanText.setText("Schedule deviation mean: ");
    timingMeanValue = new Text(composite, SWT.SINGLE);
    timingMeanValue.setText("");
    Text timingStdText = new Text(composite, SWT.NONE);
    timingStdText.setText("Schedule deviation std: ");
    timingStdValue = new Text(composite, SWT.SINGLE);
    timingStdValue.setText("");
    Text responseTimeMeanText = new Text(composite, SWT.NONE);
    responseTimeMeanText.setText("Responsetime mean: ");
    responseTimeMeanValue = new Text(composite, SWT.SINGLE);
    responseTimeMeanValue.setText("");
    Text responseTimeStdText = new Text(composite, SWT.NONE);
    responseTimeStdText.setText("Responsetime std: ");
    responseTimeStdValue = new Text(composite, SWT.SINGLE);
    responseTimeStdValue.setText("");
    Text chartWidthText = new Text(composite, SWT.NONE);
    chartWidthText.setText("Chart width: ");
    final Text chartWidthValue = new Text(composite, SWT.BORDER);
    chartWidthValue.setText("800");
    chartWidthValue.addVerifyListener(numberVerifier);
    Text chartHeightText = new Text(composite, SWT.NONE);
    chartHeightText.setText("Chart height: ");
    final Text chartHeightValue = new Text(composite, SWT.BORDER);
    chartHeightValue.setText("400");
    chartHeightValue.addVerifyListener(numberVerifier);
    showScheduleChartButton = new Button(composite, SWT.NONE);
    showScheduleChartButton.setText("Show Schedule Chart");
    showScheduleChartButton.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event e) {
            switch (e.type) {
            case SWT.Selection:
                showScheduleChart(Integer.parseInt(chartWidthValue.getText()),
                        Integer.parseInt(chartHeightValue.getText()));
                break;
            }
        }
    });
    saveScheduleChartButton = new Button(composite, SWT.NONE);
    saveScheduleChartButton.setText("Save Schedule Chart");
    saveScheduleChartButton.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event e) {
            //            optional window
            Display display = Display.getDefault();
            Shell dialogShell = new Shell(display, SWT.APPLICATION_MODAL);
            MessageBox dialog = new MessageBox(dialogShell, SWT.ICON_WARNING | SWT.OK);
            dialog.setText("Licence Problem");
            dialog.setMessage(
                    "This feature is currently disabled! \n If you want to reenable it, check out the code.");
            dialog.open();
            //            end of optional window
            switch (e.type) {
            case SWT.Selection:
                saveScheduleChart(Integer.parseInt(chartWidthValue.getText()),
                        Integer.parseInt(chartHeightValue.getText()));
                break;
            }
        }
    });
    showResponseChartButton = new Button(composite, SWT.NONE);
    showResponseChartButton.setText("Show Response Chart");
    showResponseChartButton.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event e) {
            switch (e.type) {
            case SWT.Selection:
                showResponseChart(Integer.parseInt(chartWidthValue.getText()),
                        Integer.parseInt(chartHeightValue.getText()));
                break;
            }
        }
    });
    saveResponseChartButton = new Button(composite, SWT.NONE);
    saveResponseChartButton.setText("Save Response Chart");
    saveResponseChartButton.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event e) {
            //            optional window
            Display display = Display.getDefault();
            Shell dialogShell = new Shell(display, SWT.APPLICATION_MODAL);
            MessageBox dialog = new MessageBox(dialogShell, SWT.ICON_WARNING | SWT.OK);
            dialog.setText("Licence problem");
            dialog.setMessage(
                    "This feature is currently disabled! \n If you want to reenable it, check out the code.");
            dialog.open();
            //            end of optional window
            switch (e.type) {
            case SWT.Selection:
                saveResponseChart(Integer.parseInt(chartWidthValue.getText()),
                        Integer.parseInt(chartHeightValue.getText()));
                break;
            }
        }
    });
    getSite().getWorkbenchWindow().getSelectionService().addSelectionListener(this);
    composite.setLayout(new GridLayout(2, false));
    this.parent = parent;
}

From source file:org.eclipse.rdf4j.repository.manager.RepositoryManager.java

/**
 * Generates an ID for a new repository based on the specified base name. The base name may for example be
 * a repository name entered by the user. The generated ID will contain a variant of this name that does
 * not occur as a repository ID in this manager yet and is suitable for use as a file name (e.g. for the
 * repository's data directory)./*from  w  ww.  j  av  a  2s.  c o m*/
 * 
 * @param baseName
 *        The String on which the returned ID should be based, must not be <tt>null</tt>.
 * @return A new repository ID derived from the specified base name.
 * @throws RepositoryException
 * @throws RepositoryConfigException
 */
public String getNewRepositoryID(String baseName) throws RepositoryException, RepositoryConfigException {
    if (baseName != null) {
        // Filter exotic characters from the base name
        baseName = baseName.trim();

        int length = baseName.length();
        StringBuilder buffer = new StringBuilder(length);

        for (char c : baseName.toCharArray()) {
            if (Character.isLetter(c) || Character.isDigit(c) || c == '-' || c == '_' || c == '.') {
                // Convert to lower case since file names are case insensitive on
                // some/most platforms
                buffer.append(Character.toLowerCase(c));
            } else if (c != '"' && c != '\'') {
                buffer.append('-');
            }
        }

        baseName = buffer.toString();
    }

    // First try if we can use the base name without an appended index
    if (baseName != null && baseName.length() > 0 && !hasRepositoryConfig(baseName)) {
        return baseName;
    }

    // When the base name is null or empty, generate one
    if (baseName == null || baseName.length() == 0) {
        baseName = "repository-";
    } else if (!baseName.endsWith("-")) {
        baseName += "-";
    }

    // Keep appending numbers until we find an unused ID
    int index = 2;
    while (hasRepositoryConfig(baseName + index)) {
        index++;
    }

    return baseName + index;
}

From source file:com.gzj.tulip.jade.rowmapper.BeanPropertyRowMapper.java

/**
 * Convert a name in camelCase to an underscored name in lower case.
 * Any upper case letters are converted to lower case with a preceding
 * underscore./*from  w  w w . ja v  a2  s  .  com*/
 * 
 * @param camelCaseName the string containing original name
 * @return the converted name
 */
private String[] underscoreName(String camelCaseName) {
    StringBuilder result = new StringBuilder();
    if (camelCaseName != null && camelCaseName.length() > 0) {
        result.append(camelCaseName.substring(0, 1).toLowerCase());
        for (int i = 1; i < camelCaseName.length(); i++) {
            char ch = camelCaseName.charAt(i);
            if (Character.isUpperCase(ch)) {
                result.append("_");
                result.append(Character.toLowerCase(ch));
            } else {
                result.append(ch);
            }
        }
    }
    String name = result.toString();
    // nameuser1_name2name2user_1_name_2
    // user_1_name_2user1Name2
    String name2 = null;
    boolean digitFound = false;
    for (int i = name.length() - 1; i >= 0; i--) {
        if (Character.isDigit(name.charAt(i))) {
            // ??continue,???continue
            digitFound = true;
            continue;
        }
        // ???
        if (digitFound && i < name.length() - 1 && i > 0) {
            if (name2 == null) {
                name2 = name;
            }
            name2 = name2.substring(0, i + 1) + "_" + name2.substring(i + 1);
        }
        digitFound = false;
    }
    return new String[] { name, name2 };
}

From source file:gov.nih.nci.cananolab.util.StringUtils.java

public static boolean isDouble(String theStr) {
    int decimalCount = 0;

    if (isEmpty(theStr)) {
        return false;
    } else {/*from   ww  w  .  ja va 2s .c om*/
        for (int i = 0; i < theStr.length(); i++) {
            if (!Character.isDigit(theStr.charAt(i))) {
                if (theStr.charAt(i) == ('.')) {
                    decimalCount++;
                    continue;
                } else {
                    return false;
                }
            }
        }

        if (decimalCount == 1)
            return true;
        else
            return false;
    }
}

From source file:au.org.ala.delta.directives.args.DirectiveArgsParser.java

protected List<Integer> readSet(IntegerValidator validator, char setTerminatorChar) throws ParseException {
    List<Integer> values = new ArrayList<Integer>();
    while (_currentInt > 0 && (Character.isDigit(_currentChar) || _currentChar == SET_VALUE_SEPARATOR)) {
        values.addAll(readSetComponent(validator));
    }//from   w w w.  j  ava 2s.co m

    return values;
}

From source file:aula1.Aula1.java

public static String conversor(String entrada, String info) throws Exception {
    Pilha<String> input = new Pilha<>();
    Pilha<String> simbolos = new Pilha<>();
    Stack<Op> operadores = new Stack<>();
    Pilha<String> saida = new Pilha<>();
    String[] operadoresSuportados = { "+", "-", "*", "/", "^", "(", ")", "sen" };

    for (int i = 0; i < entrada.length(); i++) {
        String s = "";
        try {/*from ww w  . j a  va2s.  co  m*/
            if (Character.isDigit(entrada.charAt(i))) {
                s = String.valueOf(entrada.charAt(i));
                while (Character.isDigit(entrada.charAt(i + 1))) {
                    s += String.valueOf(entrada.charAt(i + 1));
                    i++;
                }
            } else {
                if (entrada.charAt(i) == 's' && entrada.contains("sen")) {
                    int ind = entrada.indexOf("sen");
                    String ent = entrada.substring(ind);
                    int ini = ent.indexOf("sen(") + 4;
                    int fim = ent.indexOf(")/");
                    CharSequence x = ent.subSequence(ini, fim);
                    if (entrada.contains("sen(" + x + ")/" + x)) {
                        entrada = entrada.replace("sen(" + x + ")/" + x, "1");
                        s = "1";
                    } else {
                        ind += 2;
                        i = -1;
                        entrada = entrada.substring(ind + 1);
                        if (entrada.charAt(0) != '(')
                            throw new Exception("Falta de '(' aps sen");
                        s = "sen";
                    }
                } else
                    s = String.valueOf(entrada.charAt(i));
            }
            simbolos.push(s);
            input.push(s);
        } catch (IndexOutOfBoundsException ex) {
            s = String.valueOf(entrada.charAt(i));
            simbolos.push(s);
            input.push(s);
        }
    }
    while (!simbolos.isEMpty()) {
        String simbolo = simbolos.pop();

        if (Character.isDigit(simbolo.charAt(0)) || simbolo.charAt(0) == 'x')
            saida.push(simbolo);
        else if (Arrays.asList(operadoresSuportados).contains(simbolo)) {
            Op operador = new Op(simbolo);
            Op topOperador;
            try {
                topOperador = operadores.peek();
            } catch (EmptyStackException e) {
                topOperador = null;
            }
            if (simbolo.equals(")")) {
                while (topOperador != null && !topOperador.op().equals("(")) {
                    saida.push(topOperador.op());
                    operadores.pop();
                    topOperador = operadores.peek();
                }
                operadores.pop();
            } else if (simbolo.equals("(")) {
                operadores.push(operador);
            } else {
                while (topOperador != null && topOperador.Precedencia() > operador.Precedencia()) {
                    saida.push(topOperador.op());
                    operadores.pop();
                    try {
                        topOperador = operadores.peek();
                    } catch (EmptyStackException e) {
                        topOperador = null;
                    }
                }
                operadores.push(operador);
            }
        }
    }
    while (!operadores.isEmpty()) {
        Op operador = operadores.pop();
        saida.push(operador.op());
    }
    String resultado = "";
    for (String s : saida) {
        System.out.println("saida: " + s);
        resultado += s + " ";
    }
    resultado = calculaPolonesaINversa(resultado, info);
    return resultado;

}