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:kltn.geocoding.Geocoding.java

public static boolean checkContainNumber(String str) {
    for (int i = 0; i < str.length(); i++) {
        char c = str.charAt(i);
        if (Character.isDigit(c)) {
            return true;
        }/* w  ww  .j  a va 2s. c  o m*/
    }
    return false;
}

From source file:IPDomainValidator.java

/**
 * Returns 0 if the char array {@code part} is invalid.
 */// ww  w .j a va2s  . c  om
public static int tokenValidate(char[] part, int start, int len) {
    int digitCount = 0, lastHyphen = -1;
    for (int i = 0; i < len; i++) {
        char c = part[start++];
        if (Character.isDigit(c))
            digitCount++;
        else if (!Character.isLetter(c)) {
            if (c == '-') {
                if (i < len - 1) {
                    if (lastHyphen + 1 == i || lastHyphen - 1 == i) {
                        // invalid placement of hyphens (succeeding, prefix)                            
                        return INVALID;
                    }
                    lastHyphen = i;
                } else {
                    // invalid placement of hyphens (suffix)  
                    return INVALID;
                }
            } else
                return INVALID;
        }
    }
    if (digitCount == len)
        return IP;

    if (digitCount == 0)
        return lastHyphen == -1 ? PLAIN : HYPHENATED;

    return lastHyphen == -1 ? ALPHANUMERIC : MIXED;
}

From source file:com.inkubator.hrm.util.StringsUtils.java

public static boolean isHaveNumber(String toCheck) {
    Boolean isCondition = Boolean.FALSE;
    for (int i = toCheck.length() - 1; i >= 0; i--) {

        if (Character.isDigit(toCheck.charAt(i))) {
            isCondition = Boolean.TRUE;
        }//from   w ww. j a  va  2  s  . c om
    }
    return isCondition;
}

From source file:Main.java

/**
 * Parse the given name.//from ww w. j a va2s . co m
 *
 * @param sourceName
 * @param separator
 * @return some stuff parsed from the name
 */
private static List<String> parseName(String sourceName, char separator) {
    List<String> result = new ArrayList<String>();
    if (sourceName != null) {
        StringBuilder currentWord = new StringBuilder(64);
        boolean lastIsLower = false;
        int index;
        int length;
        for (index = 0, length = sourceName.length(); index < length; ++index) {
            char curChar = sourceName.charAt(index);
            if (!Character.isJavaIdentifierPart(curChar)) {
                curChar = separator;
            }
            if (Character.isUpperCase(curChar) || (!lastIsLower && Character.isDigit(curChar))
                    || curChar == separator) {

                if (lastIsLower && currentWord.length() > 1
                        || curChar == separator && currentWord.length() > 0) {
                    result.add(currentWord.toString());
                    currentWord = new StringBuilder(64);
                }
                lastIsLower = false;
            } else {
                if (!lastIsLower) {
                    int currentWordLength = currentWord.length();
                    if (currentWordLength > 1) {
                        char lastChar = currentWord.charAt(--currentWordLength);
                        currentWord.setLength(currentWordLength);
                        result.add(currentWord.toString());
                        currentWord = new StringBuilder(64);
                        currentWord.append(lastChar);
                    }
                }
                lastIsLower = true;
            }

            if (curChar != separator) {
                currentWord.append(curChar);
            }
        }

        result.add(currentWord.toString());
    }
    return result;
}

From source file:com.hj.blog.common.utils.StringUtils.java

static boolean isNumeric(final CharSequence cs) {
    if (isEmpty(cs)) {
        return false;
    }// w w w .j  ava  2  s .  co  m
    final int sz = cs.length();
    for (int i = 0; i < sz; i++) {
        if (Character.isDigit(cs.charAt(i)) == false) {
            return false;
        }
    }
    return true;
}

From source file:ctrus.pa.bow.term.filter.NumericFilter.java

public boolean filter(String term) {
    boolean filterTerm = false;
    if (NumberUtils.isDigits(term) || Character.isDigit(term.charAt(0)))
        filterTerm = true;/*from   ww w .jav a  2  s . c o  m*/
    return filterTerm;
}

From source file:com.viettel.ws.client.JDBCUtil.java

public static String convertToOrigin(String s) {
    String newStr = "";
    for (char c : s.toCharArray()) {
        if (!Character.isDigit(c) && Character.isUpperCase(c)) {
            newStr += ("_" + String.valueOf(c));
        } else if (!Character.isDigit(c) && Character.isLowerCase(c)) {
            newStr += String.valueOf(c).toUpperCase();
        } else {/*  w  ww .ja  va  2 s .  c o m*/
            newStr += String.valueOf(c);
        }
    }
    return newStr;
}

From source file:Main.java

/**
 * <p>Checks if the String contains only unicode digits.
 * A decimal point is not a unicode digit and returns false.</p>
 *
 * <p><code>null</code> will return <code>false</code>.
 * An empty String ("") will return <code>true</code>.</p>
 *
 * <pre>/*from   w w  w  .  ja v  a 2 s  . c  o  m*/
 * StringUtils.isNumeric(null)   = false
 * StringUtils.isNumeric("")     = true
 * StringUtils.isNumeric("  ")   = false
 * StringUtils.isNumeric("123")  = true
 * StringUtils.isNumeric("12 3") = false
 * StringUtils.isNumeric("ab2c") = false
 * StringUtils.isNumeric("12-3") = false
 * StringUtils.isNumeric("12.3") = false
 * </pre>
 *
 * @param str  the String to check, may be null
 * @return <code>true</code> if only contains digits, and is non-null
 */
public static boolean isNumeric(String str) {
    if (str == null) {
        return false;
    }
    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:edu.illinois.cs.cogcomp.ner.StringStatisticsUtils.MyString.java

public static String collapseDigits(String s) {
    StringBuilder res = new StringBuilder(s.length() * 2);
    for (int i = 0; i < s.length(); i++) {
        if (Character.isDigit(s.charAt(i))) {
            while (i < s.length() && Character.isDigit(s.charAt(i)))
                i++;/*w  w w  . j a v  a  2s. co m*/
            res.append("*D*");
            if (i < s.length())
                res.append(s.charAt(i));
        } else {
            res.append(s.charAt(i));
        }
    }
    return res.toString();
}

From source file:Main.java

/**
 * Checks if the String contains only unicode digits or space
 * (<code>' '</code>)./*from  w  ww . j  a  va 2  s  .c  om*/
 * A decimal point is not a unicode digit and returns false.
 *
 * <code>null</code> will return <code>false</code>.
 * An empty String ("") will return <code>true</code>.
 *
 * <pre>
 * StringUtils.isNumeric(null)   = false
 * StringUtils.isNumeric("")     = true
 * StringUtils.isNumeric("  ")   = true
 * StringUtils.isNumeric("123")  = true
 * StringUtils.isNumeric("12 3") = true
 * StringUtils.isNumeric("ab2c") = false
 * StringUtils.isNumeric("12-3") = false
 * StringUtils.isNumeric("12.3") = false
 * </pre>
 *
 * @param str  the String to check, may be null
 * @return <code>true</code> if only contains digits or space,
 *  and is non-null
 */
public static boolean isNumericSpace(String str) {
    if (str == null) {
        return false;
    }
    int sz = str.length();
    for (int i = 0; i < sz; i++) {
        if ((Character.isDigit(str.charAt(i)) == false) && (str.charAt(i) != ' ')) {
            return false;
        }
    }
    return true;
}