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

static int getServiceVersionNumberInternal(String version) {
    if (!version.equals("@" + "version" + "@")) {
        try {/*  w w w. j a v a  2 s .com*/
            int firstDot = version.indexOf(".");
            int secondDot = version.indexOf(".", firstDot + 1);

            int p = secondDot + 1;
            int q = p;

            while (q < version.length() && Character.isDigit(version.charAt(q))) {
                q++;
            }

            if (p != q) {
                String service = version.substring(p, q);
                return new Integer(service).intValue();
            }
        } catch (NumberFormatException nfe) {
        }
    }
    // in case this is a mainline version or NFE was caught (strange)
    return 0;
}

From source file:Main.java

public static String formatMoneyAmount(double amount, Locale locale) {
    NumberFormat format = NumberFormat.getCurrencyInstance(locale);

    String amountTxt = format.format(amount);
    String amountTxtValue = "";
    for (int i = 0; i < amountTxt.length(); i++) {
        if (Character.isDigit(amountTxt.charAt(i)) || amountTxt.charAt(i) == '.' || amountTxt.charAt(i) == ',')
            amountTxtValue = amountTxtValue + amountTxt.charAt(i);
    }// w w  w. j  av  a  2 s.  com

    amountTxt = amountTxtValue;

    if (amountTxt.endsWith(",00"))
        return (amountTxt.replace(",00", ""));
    return (amountTxt);
}

From source file:Main.java

public static String formatMoneyAmountBills(double amount, Locale locale) {
    NumberFormat format = NumberFormat.getCurrencyInstance(locale);

    String amountTxt = format.format(amount);
    String amountTxtValue = "";
    for (int i = 0; i < amountTxt.length(); i++) {
        if (Character.isDigit(amountTxt.charAt(i)) || amountTxt.charAt(i) == '.' || amountTxt.charAt(i) == ',')
            amountTxtValue = amountTxtValue + amountTxt.charAt(i);
    }//  w  w  w  . j a  v a  2 s. co  m

    amountTxt = amountTxtValue;

    return (amountTxt);
}

From source file:Main.java

public static boolean isIsracardValid(String cardNumber) {
    int sum = 0;//from   w  w  w. j a v  a2 s  .  c  o m
    int len = cardNumber.length();

    // If the number is less than 9 digits
    if (len == 8) {
        cardNumber = "0" + cardNumber;
        len++;
    }

    for (int i = 0; i < len; i++) {
        final char c = cardNumber.charAt(i);
        if (!Character.isDigit(c)) {
            throw new IllegalArgumentException(String.format("Not a digit: '%s'", c));
        }

        final int digit = Character.digit(c, 10);
        sum = sum + (digit * (9 - i));
    }
    return sum % 11 == 0;
}

From source file:Main.java

/**
 * Checks if a string passed in is numeric (IE pass in "2" and it will return true)
 * @param str String to check against//from w  w w .j  av  a  2  s  .c  om
 * @return Return true if it is numeric, false if it is not
 */
public static boolean isNumeric(String str) {
    if (str == null) {
        return false;
    }

    final int sz = str.length();
    for (int i = 0; i < sz; i++) {
        if (Character.isDigit(str.charAt(i)) == false) {
            return false;
        }
    }
    return true;
}

From source file:Main.java

private static String unEscape(String s) {
    StringBuffer sbuf = new StringBuffer();
    int l = s.length();
    int ch = -1;/*w  ww .j a va 2  s.  c  o m*/
    int b, sumb = 0;
    for (int i = 0, more = -1; i < l; i++) {
        /* Get next byte b from URL segment s */
        switch (ch = s.charAt(i)) {
        case '%':
            ch = s.charAt(++i);
            int hb = (Character.isDigit((char) ch) ? ch - '0' : 10 + Character.toLowerCase((char) ch) - 'a')
                    & 0xF;
            ch = s.charAt(++i);
            int lb = (Character.isDigit((char) ch) ? ch - '0' : 10 + Character.toLowerCase((char) ch) - 'a')
                    & 0xF;
            b = (hb << 4) | lb;
            break;
        case '+':
            b = ' ';
            break;
        default:
            b = ch;
        }
        /* Decode byte b as UTF-8, sumb collects incomplete chars */
        if ((b & 0xc0) == 0x80) { // 10xxxxxx (continuation byte)
            sumb = (sumb << 6) | (b & 0x3f); // Add 6 bits to sumb
            if (--more == 0)
                sbuf.append((char) sumb); // Add char to sbuf
        } else if ((b & 0x80) == 0x00) { // 0xxxxxxx (yields 7 bits)
            sbuf.append((char) b); // Store in sbuf
        } else if ((b & 0xe0) == 0xc0) { // 110xxxxx (yields 5 bits)
            sumb = b & 0x1f;
            more = 1; // Expect 1 more byte
        } else if ((b & 0xf0) == 0xe0) { // 1110xxxx (yields 4 bits)
            sumb = b & 0x0f;
            more = 2; // Expect 2 more bytes
        } else if ((b & 0xf8) == 0xf0) { // 11110xxx (yields 3 bits)
            sumb = b & 0x07;
            more = 3; // Expect 3 more bytes
        } else if ((b & 0xfc) == 0xf8) { // 111110xx (yields 2 bits)
            sumb = b & 0x03;
            more = 4; // Expect 4 more bytes
        } else /* if ((b & 0xfe) == 0xfc) */ { // 1111110x (yields 1 bit)
            sumb = b & 0x01;
            more = 5; // Expect 5 more bytes
        }
        /* We don't test if the UTF-8 encoding is well-formed */
    }
    return sbuf.toString();
}

From source file:Main.java

private static String addSpaceIfRequired(String value, int index) {
    if (index == 0)
        return VOID_STRING;
    char precedingChar = value.charAt(index - 1);
    char thisChar = value.charAt(index);
    if (Character.isLowerCase(precedingChar) && Character.isUpperCase(thisChar)
            || Character.isLetter(precedingChar) && Character.isDigit(thisChar)
            || Character.isDigit(precedingChar) && Character.isLetter(thisChar)) {
        return SPACE;
    }/*w  ww. j a v  a  2s.co  m*/
    if (index + 1 == value.length())
        return VOID_STRING;
    char nextChar = value.charAt(index + 1);
    if (Character.isUpperCase(precedingChar) && Character.isUpperCase(thisChar)
            && Character.isLowerCase(nextChar)) {
        return SPACE;
    }
    return VOID_STRING;
}

From source file:Main.java

public static String formatMoneyAmountItemised(double amount, Locale locale) {

    NumberFormat format = NumberFormat.getCurrencyInstance(locale);

    format.setMinimumFractionDigits(0);/*ww w .  j  av  a2 s.c  o m*/
    format.setMaximumFractionDigits(3);

    String amountTxt = format.format(amount);

    String amountTxtValue = "";
    for (int i = 0; i < amountTxt.length(); i++) {
        if (Character.isDigit(amountTxt.charAt(i)) || amountTxt.charAt(i) == '.' || amountTxt.charAt(i) == ',')
            amountTxtValue = amountTxtValue + amountTxt.charAt(i);
    }

    amountTxt = amountTxtValue;

    if (amountTxt.endsWith(",0"))
        return (amountTxt.replace(",0", ""));
    else if (amountTxt.endsWith(",00"))
        return (amountTxt.replace(",00", ""));
    else if (amountTxt.endsWith(",000"))
        return (amountTxt.replace(",000", ""));
    else
        return (amountTxt);

}

From source file:Main.java

public static final int ReadInt(PushbackInputStream in, int def) {
    int b;/*from www  .  j  a v  a2  s  .c om*/
    boolean neg = false;
    int i = 0, digits = 0;
    try {
        while (true) {
            b = (int) in.read() & 0xff;
            if (b == '-' && digits == 0)
                neg = !neg;
            else if (Character.isDigit(b)) {
                i = 10 * i + (b - (int) '0');
                ++digits;
            } else if (digits != 0 || !Character.isSpace((char) b)) {
                if (b != -1)
                    in.unread(b);
                break;
            }
        }
    } catch (IOException e) {
    }
    try {
        while ((b = in.read()) != '/' && b != -1)
            ;
    } catch (IOException e) {
    }
    if (neg)
        i = -i;
    return digits > 0 ? i : def;
}

From source file:Main.java

public static String formatMoneyAmountOne(double amount) {
    Locale locale = new Locale("ru", "RU");
    NumberFormat format = NumberFormat.getCurrencyInstance(locale);
    format.setMinimumFractionDigits(0);//from  w  w w  . j ava 2s.  c  om
    format.setMaximumFractionDigits(1);
    String amountTxt = format.format(amount);
    String amountTxtValue = "";
    for (int i = 0; i < amountTxt.length(); i++) {
        if (Character.isDigit(amountTxt.charAt(i)) || amountTxt.charAt(i) == '.' || amountTxt.charAt(i) == ',')
            amountTxtValue = amountTxtValue + amountTxt.charAt(i);
    }

    amountTxt = amountTxtValue;

    if (amountTxt.endsWith(",00"))
        return (amountTxt.replace(",00", ""));
    else if (amountTxt.endsWith("0") && amountTxt.contains(",")) {
        return (amountTxt.substring(0, amountTxt.length() - 1));
    } else
        return (amountTxt);
}