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.msg.wmTestHelper.file.NameExtractor.java

private static int getVersion(String[] input) {
    String mainPart = input[2];/*from w  w w .  j a va  2  s. c o  m*/

    int i = mainPart.length();
    while (i > 0 && Character.isDigit(mainPart.charAt(i - 1))) {
        i--;
    }
    return Integer.parseInt(mainPart.substring(i));
}

From source file:Main.java

/**
 * Returns whether the string supplied could be used as a valid XML name.
 * @param name The string to test for XML name validity.
 * @return true if the string can be used as a valid XML name, false otherwise.
 *///from   ww  w .ja va 2 s.  co  m
public static boolean isValidXMLName(String name) {
    String trimmedName = name.trim();

    boolean currentCharacterValid;

    if (name == null || trimmedName.length() == 0) {
        return false;
    }

    // ensure that XML standard reserved names are not used

    if (trimmedName.toUpperCase().startsWith("XML")) {
        return false;
    }

    // test that name starts with a valid XML name-starting character

    if (!Character.isUpperCase(trimmedName.charAt(0)) && !Character.isLowerCase(trimmedName.charAt(0))
            && trimmedName.charAt(0) != '_') {
        return false;
    }

    // test that remainder name chars are a valid XML name characters 

    if (name.trim().length() > 0) {
        for (int i = 1; i < trimmedName.length(); i++) {
            currentCharacterValid = false;

            if (Character.isUpperCase(trimmedName.charAt(i)) || Character.isLowerCase(trimmedName.charAt(i))
                    || Character.isDigit(trimmedName.charAt(i))) {
                currentCharacterValid = true;
            }

            if (trimmedName.charAt(i) == '_' || trimmedName.charAt(i) == '-' || trimmedName.charAt(i) == '.') {
                currentCharacterValid = true;
            }

            if (!currentCharacterValid) {
                return false;
            }
        }
    }
    return true;
}

From source file:be.fgov.minfin.webForm.util.ISINValidationUtil.java

public int calculcateModulus(String code, boolean includesCheckDigit) throws CheckDigitException {
    StringBuilder transformed = new StringBuilder(code.length() * 2);
    if (includesCheckDigit) {
        char checkDigit = code.charAt(code.length() - 1); // Choppe le dernier caractre
        if (!Character.isDigit(checkDigit)) {
            throw new CheckDigitException("Invalid checkdigit[" + checkDigit + "] in " + code);
        }/*from  w w  w.j  a v  a2s. c  o  m*/
    }
    for (int i = 0; i < code.length(); i++) {
        int charValue = Character.getNumericValue(code.charAt(i));
        if (charValue < 0 || charValue > 35) {
            throw new CheckDigitException("Invalid Character[" + (i + 1) + "] = '" + charValue + "'");
        }
        transformed.append(charValue);
    }
    //Doit retourner 0 pour que ce soit valide
    return super.calculateModulus(transformed.toString(), includesCheckDigit);
}

From source file:ips1ap101.lib.base.util.TemporalAddend.java

public TemporalAddend(String string) {
    init();//from   www .  ja v  a2  s  .c  o  m
    String trimmed = StringUtils.trimToNull(string);
    if (trimmed != null) {
        int end = trimmed.length() - 1;
        char unit = trimmed.charAt(end);
        boolean digit = Character.isDigit(unit);
        _quantity = digit ? quantityOf(trimmed) : quantityOf(trimmed.substring(0, end));
        _unit = ArrayUtils.contains(_validUnits, unit) ? unit : digit ? 'D' : '?';
    }
}

From source file:Main.java

private static JSpinner makeDigitsOnlySpinnerUsingDocumentFilter() {
    JSpinner spinner = new JSpinner(new SpinnerNumberModel());
    JSpinner.NumberEditor jsEditor = (JSpinner.NumberEditor) spinner.getEditor();
    JFormattedTextField textField = jsEditor.getTextField();
    DocumentFilter digitOnlyFilter = new DocumentFilter() {
        @Override//  w  w w .  j  a  v a2  s.  c  o m
        public void insertString(FilterBypass fb, int offset, String string, AttributeSet attr)
                throws BadLocationException {
            if (stringContainsOnlyDigits(string)) {
                super.insertString(fb, offset, string, attr);
            }
        }

        @Override
        public void remove(FilterBypass fb, int offset, int length) throws BadLocationException {
            super.remove(fb, offset, length);
        }

        @Override
        public void replace(FilterBypass fb, int offset, int length, String text, AttributeSet attrs)
                throws BadLocationException {
            if (stringContainsOnlyDigits(text)) {
                super.replace(fb, offset, length, text, attrs);
            }
        }

        private boolean stringContainsOnlyDigits(String text) {
            for (int i = 0; i < text.length(); i++) {
                if (!Character.isDigit(text.charAt(i))) {
                    return false;
                }
            }
            return true;
        }
    };

    NumberFormat format = NumberFormat.getPercentInstance();
    format.setGroupingUsed(false);
    format.setGroupingUsed(true);
    format.setMaximumIntegerDigits(10);
    format.setMaximumFractionDigits(2);
    format.setMinimumFractionDigits(5);
    textField.setFormatterFactory(new DefaultFormatterFactory(new InternationalFormatter(format) {
        @Override
        protected DocumentFilter getDocumentFilter() {
            return digitOnlyFilter;
        }
    }));
    return spinner;
}

From source file:Main.java

public static Date parseDA(TimeZone tz, String s, boolean ceil) {
    Calendar cal = cal(tz);//from w w  w.j  av  a  2  s .c o  m
    int length = s.length();
    if (!(length == 8 || length == 10 && !Character.isDigit(s.charAt(4))))
        throw new IllegalArgumentException(s);
    try {
        int pos = 0;
        cal.set(Calendar.YEAR, Integer.parseInt(s.substring(pos, pos + 4)));
        pos += 4;
        if (!Character.isDigit(s.charAt(pos)))
            pos++;
        cal.set(Calendar.MONTH, Integer.parseInt(s.substring(pos, pos + 2)) - 1);
        pos += 2;
        if (!Character.isDigit(s.charAt(pos)))
            pos++;
        cal.set(Calendar.DAY_OF_MONTH, Integer.parseInt(s.substring(pos)));
        if (ceil)
            ceil(cal, Calendar.DAY_OF_MONTH);
    } catch (NumberFormatException e) {
        throw new IllegalArgumentException(s);
    }
    return cal.getTime();
}

From source file:biblivre3.marcutils.Indexer.java

public static String listIsbn(Record record) {
    String retorno = "";

    DataField dataField = MarcUtils.getDataField(record, MarcConstants.ISBN);
    if (dataField != null) {
        Subfield subField = dataField.getSubfield('a');
        String isbn = subField != null ? subField.getData() : null;
        if (StringUtils.isNotBlank(isbn)) {
            if (Character.isDigit(isbn.charAt(0)) && (isbn.length() >= 10)) {
                retorno = isbn;/* w w w .  ja v  a 2  s .  c o  m*/
            }
        }
    }

    return retorno;
}

From source file:com.github.jknack.css.expression.NumberExpression.java

private static String[] split(final String value) {
    for (int i = 0; i < value.length(); i++) {
        char ch = value.charAt(i);
        if (!Character.isDigit(ch) && ch != '.') {
            return new String[] { value.substring(0, i), value.substring(i) };
        }/*w w w  . j a v  a2 s .c  o  m*/
    }
    return new String[] { value, null };
}

From source file:Main.java

public void focusLost(FocusEvent evt) {
    final JTextComponent c = (JTextComponent) evt.getSource();
    String s = c.getText();/*from w  ww  .  j  a v  a2s  .  co m*/

    if (evt.isTemporary()) {
        return;
    }
    for (int i = 0; i < s.length(); i++) {
        if (!Character.isDigit(s.charAt(i))) {
            System.out.println("must only contain digits");
            c.requestFocus();
            break;
        }
    }
}

From source file:Main.java

public static double getJavaVersion() {
    if (javaVersion == null) {
        try {//from  www .  j  av  a 2  s  . co m
            String ver = System.getProperties().getProperty("java.version");
            String version = "";
            boolean firstPoint = true;
            for (int i = 0; i < ver.length(); i++) {
                if (ver.charAt(i) == '.') {
                    if (firstPoint) {
                        version += ver.charAt(i);
                    }
                    firstPoint = false;
                } else if (Character.isDigit(ver.charAt(i))) {
                    version += ver.charAt(i);
                }
            }
            javaVersion = new Double(version);
        } catch (Exception ex) {
            javaVersion = new Double(1.3);
        }
    }
    return javaVersion.doubleValue();
}