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

/**
 * Called when the user types into a text box, but before the text box gets
 * what the user typed//from ww w.  j a v  a 2  s .c o  m
 */
public void verifyText(VerifyEvent event) {
    // Assume we don't allow it
    event.doit = false;

    // Get the character typed
    char myChar = event.character;
    String text = ((Text) event.widget).getText();

    // Allow '-' if first character
    if (myChar == '-' && text.length() == 0)
        event.doit = true;

    // Allow 0-9
    if (Character.isDigit(myChar))
        event.doit = true;

    // Allow backspace
    if (myChar == '\b')
        event.doit = true;
}

From source file:de.codesourcery.eve.skills.ui.utils.IntTextFieldValidator.java

protected static boolean isInteger(String s) {
    if (StringUtils.isBlank(s)) {
        return false;
    }//from  w  w w  . j  a v  a2s . c  o m
    for (char c : s.toCharArray()) {
        if (!Character.isDigit(c) && c != '-') {
            return false;
        }
    }
    return true;
}

From source file:com.appglu.impl.util.StringUtils.java

public static boolean isDigits(String string) {
    if (isEmpty(string)) {
        return false;
    }//  w  w  w.  j  a  va2s.  c o m
    for (int i = 0; i < string.length(); i++) {
        if (!Character.isDigit(string.charAt(i))) {
            return false;
        }
    }
    return true;
}

From source file:com.blackberry.logdriver.timestamp.Rfc5424TimestampParser.java

@Override
public long parseTimestatmp(String timestamp) throws ParseException {
    try {//from   w  ww .  ja va  2s  . c o m
        // Parse the easy part of the string
        String firstPart = timestamp.substring(0, 19);
        Long time;
        time = dateCache.get(firstPart);
        if (time == null) {
            time = dateFormat.parse(firstPart).getTime();
            dateCache.put(firstPart, time);
        }
        int currentIndex = 19;
        char c = timestamp.charAt(currentIndex);

        // Check for fractional seconds to add. We only record up to millisecond
        // precision, so only grab up to three digits.
        if (timestamp.charAt(currentIndex) == '.') {
            // There are fractional seconds, so grab up to 3.
            // The first digit is guaranteed by the spec. After that, we need to
            // check if we still have digits.
            // The spec requires a timezone, so we can't run out of digits
            // before we run out of string.
            currentIndex++;
            c = timestamp.charAt(currentIndex);
            time += 100 * Character.getNumericValue(c);
            currentIndex++;
            c = timestamp.charAt(currentIndex);
            if (Character.isDigit(c)) {
                time += 10 * Character.getNumericValue(c);
                currentIndex++;
                c = timestamp.charAt(currentIndex);
                if (Character.isDigit(c)) {
                    time += Character.getNumericValue(c);
                    currentIndex++;
                    c = timestamp.charAt(currentIndex);
                    // Now just go through the digits until we're done.
                    while (Character.isDigit(c)) {
                        currentIndex++;
                        c = timestamp.charAt(currentIndex);
                    }
                }
            }

        }

        // Now adjust for timezone offset. either Z or +/-00:00
        boolean positiveTimeZone = true;
        if (c == 'Z') {
            // That's fine. No adjustment.
        } else {
            if (c == '+') {
                positiveTimeZone = true;
            } else if (c == '-') {
                positiveTimeZone = false;
            } else {
                throw new IllegalArgumentException("Malformed date:" + timestamp);
            }

            // Grab the next 2 for hour. Then skip the colon and grab the next
            // 2.
            currentIndex++;
            int hour = Integer.parseInt(timestamp.substring(currentIndex, currentIndex + 2));
            currentIndex += 2;
            c = timestamp.charAt(currentIndex);
            if (c != ':') {
                throw new IllegalArgumentException("Malformed date:" + timestamp);
            }
            currentIndex++;
            int minute = Integer.parseInt(timestamp.substring(currentIndex, currentIndex + 2));

            int offset = (60 * hour + minute) * 60 * 1000;
            if (positiveTimeZone) {
                time -= offset;
            } else {
                time += offset;
            }

        }

        // If we support daylight savings, then we need to keep checking if we're
        // in
        // daylight savings or not.
        if (daylightSavings) {
            time += tz.getOffset(time);
        } else {
            time += tzOffset;
        }

        return time;
    } catch (ParseException e) {
        throw e;
    } catch (Throwable t) {
        ParseException e = new ParseException("Unexpected Exception", 0);
        e.initCause(t);
        throw e;
    }
}

From source file:architecture.common.license.io.LicenseReader.java

private String decodeToXml(Reader in) throws IOException {
    StringBuffer text = new StringBuffer();
    char buf[] = new char[1024];
    int len;//from w w w  . j  ava 2 s  .  com
    while ((len = in.read(buf)) >= 0) {
        int j = 0;
        while (j < len) {
            char ch = buf[j];
            if (Character.isLetter(ch) || Character.isDigit(ch) || ch == '+' || ch == '/' || ch == '=')
                text.append(ch);
            j++;
        }
    }
    in.close();
    String xml = new String(
            Base64.decodeBase64(text.toString().getBytes(ApplicationConstants.DEFAULT_CHAR_ENCODING)));
    if (!assertionsDisabled && !text.toString().matches("^[^\\s]*$")) {
        throw new AssertionError();
    } else {
        log.debug(xml);
        return xml;
    }
}

From source file:com.dgtlrepublic.anitomyj.ParserHelper.java

/** Returns whether or not the {@code string} is a resolution. */
public static boolean isResolution(String string) {
    if (StringUtils.isEmpty(string))
        return false;
    int minWidthSize = 3;
    int minHeightSize = 3;

    // *###x###*/*from   ww w. ja  v  a  2s  .  c  o  m*/
    if (string.length() >= minWidthSize + 1 + minHeightSize) {
        int pos = StringUtils.indexOfAny(string, "xX\u00D7");
        if (pos != -1 && pos >= minWidthSize && pos <= string.length() - (minHeightSize + 1)) {
            for (int i = 0; i < string.length(); i++) {
                if (i != pos && !Character.isDigit(string.charAt(i)))
                    return false;
            }

            return true;
        }

        // *###p
    } else if (string.length() >= minHeightSize + 1) {
        if (Character.toLowerCase(string.charAt(string.length() - 1)) == 'p') {
            for (int i = 0; i < string.length() - 1; i++) {
                if (!Character.isDigit(string.charAt(i)))
                    return false;
            }

            return true;
        }
    }

    return false;
}

From source file:com.nesscomputing.mojo.numbers.NumberField.java

private boolean isNumber(final CharSequence c) {
    for (int i = 0; i < c.length(); i++) {
        if (!Character.isDigit(c.charAt(i))) {
            return false;
        }/*from w  ww .ja  v a 2 s .  c o m*/
    }
    return true;
}

From source file:aula1.Aula1.java

public static String calculaPolonesaINversa(String entrada, String info) {
    Stack<String> pilha = new Stack<>();
    Stack<Op> operadores = new Stack<>();
    String[] operadoresSuportados = { "+", "-", "*", "/", "^", "(", ")", "sen" };

    for (int i = 0; i < entrada.length(); i++) {
        String s = "";
        if (entrada.charAt(i) == 's') {

            if (entrada.contains("sen")) {
                int ind = entrada.indexOf("sen");
                ind += 2;//  w w w .  ja  v a  2 s  .c  om
                i = 0;
                entrada = entrada.substring(ind + 1);
                s = "sen";
            }
        } else
            s = String.valueOf(entrada.charAt(i));
        if (Character.isDigit(entrada.charAt(i)) || entrada.charAt(i) == 'x') {
            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++;
                }
            }
            pilha.push(s);
        } else if (Arrays.asList(operadoresSuportados).contains(s)) {
            String n1 = "";
            String n2 = "";
            if (s.equals("sen"))
                n1 = pilha.pop();
            else {
                n1 = pilha.pop();
                n2 = pilha.pop();
            }
            String resultado;

            if (n1.equals("x"))
                n1 = info;
            else if (n2.equals("x"))
                n2 = info;
            try {
                switch (s) {
                case "+":
                    resultado = Operadores.soma(n2, n1);
                    pilha.push(resultado);
                    break;
                case "-":
                    resultado = Operadores.sub(n2, n1);
                    pilha.push(resultado);
                    break;
                case "*":
                    resultado = Operadores.M(n2, n1);
                    pilha.push(resultado);
                    break;
                case "/":
                    resultado = Operadores.D(n2, n1);
                    pilha.push(resultado);
                    break;
                case "^":
                    resultado = Operadores.pow(n2, n1);
                    pilha.push(resultado);
                    break;
                case "sen":
                    resultado = Operadores.sen(n1);
                    pilha.push(resultado);
                    break;
                }
            } catch (Exception e) {
                System.out.println("Erro: " + e.getMessage());
            }
        }
    }
    return pilha.peek();
}

From source file:com.baifendian.swordfish.execserver.parameter.placeholder.CalculateUtil.java

/**
 * ??//from w  w w.  j ava  2s . co m
 *
 * @param postOrder
 * @return 
 */
private static Integer calculate(List<String> postOrder) {
    Stack<Integer> stack = new Stack<>();
    for (int i = 0; i < postOrder.size(); i++) {
        if (Character.isDigit(postOrder.get(i).charAt(0))) {
            stack.push(Integer.parseInt(postOrder.get(i)));
        } else {
            Integer back = stack.pop();
            Integer front = 0;
            char op = postOrder.get(i).charAt(0);
            if (!(op == 'P' || op == 'S')) { // ?? "?" 
                front = stack.pop();
            }

            Integer res = 0;
            switch (postOrder.get(i).charAt(0)) {
            case 'P':
                res = front + back;
                break;
            case 'S':
                res = front - back;
                break;
            case '+':
                res = front + back;
                break;
            case '-':
                res = front - back;
                break;
            case '*':
                res = front * back;
                break;
            case '/':
                res = front / back;
                break;
            }
            stack.push(res);
        }
    }

    return stack.pop();
}

From source file:au.org.ala.delta.util.Utils.java

public static int strtol(String buf, int[] endpos, int radix) {
    StringBuffer digits = new StringBuffer();
    int i = 0;/*from   www  .  ja v  a2  s.  co m*/
    for (; i < buf.length(); ++i) {
        char ch = buf.charAt(i);
        if (Character.isDigit(ch) || (i == 0 && ch == '-')
                || ((radix > 10) && ((ch >= 65 && ch <= 90) || (ch >= 97 && ch <= 122)))) {
            digits.append(ch);
        } else {
            break;
        }
    }

    if (endpos != null && endpos.length > 0) {
        endpos[0] = i;
    }

    if (digits.length() > 0) {
        return Integer.parseInt(digits.toString(), radix);
    } else {
        return 0;
    }

}