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:egovframework.com.utl.sys.fsm.service.FileSystemUtils.java

/**
 * Parses the Windows dir response last line
 *
 * @param line  the line to parse//from   ww w .  jav  a 2s  . co  m
 * @param path  the path that was sent
 * @return the number of bytes
 * @throws IOException if an error occurs
 */
long parseDir(String line, String path) throws IOException {
    // read from the end of the line to find the last numeric
    // character on the line, then continue until we find the first
    // non-numeric character, and everything between that and the last
    // numeric character inclusive is our free space bytes count
    int bytesStart = 0;
    int bytesEnd = 0;
    int j = line.length() - 1;
    innerLoop1: while (j >= 0) {
        char c = line.charAt(j);
        if (Character.isDigit(c)) {
            // found the last numeric character, this is the end of
            // the free space bytes count
            bytesEnd = j + 1;
            break innerLoop1;
        }
        j--;
    }
    innerLoop2: while (j >= 0) {
        char c = line.charAt(j);
        if (!Character.isDigit(c) && c != ',' && c != '.') {
            // found the next non-numeric character, this is the
            // beginning of the free space bytes count
            bytesStart = j + 1;
            break innerLoop2;
        }
        j--;
    }
    if (j < 0) {
        throw new IOException("Command line 'dir /-c' did not return valid info " + "for path '" + path + "'");
    }

    // remove commas and dots in the bytes count
    StringBuffer buf = new StringBuffer(line.substring(bytesStart, bytesEnd));
    for (int k = 0; k < buf.length(); k++) {
        if (buf.charAt(k) == ',' || buf.charAt(k) == '.') {
            buf.deleteCharAt(k--);
        }
    }
    return parseBytes(buf.toString(), path);
}

From source file:org.yawlfoundation.yawl.engine.interfce.Interface_Client.java

/**
 * Sends data to the specified url via a HTTP POST, and returns the reply
 * @param urlStr the url to connect to//w ww  .  j a v a 2s . c  o  m
 * @param paramsMap a map of attribute=value pairs representing the data to send
 * @param post true if this was originally a POST request, false if a GET request
 * @return the response from the url
 * @throws IOException when there's some kind of communication problem
 */
private String send(String urlStr, Map<String, String> paramsMap, boolean post) throws IOException {

    String p = "http://(.*):";
    Pattern pattern = Pattern.compile(p);

    Matcher matcher = pattern.matcher(urlStr);

    String host = null;
    while (matcher.find()) {
        host = matcher.group(1);
    }

    if (!Character.isDigit(host.charAt(0))) {
        InetAddress address = InetAddress.getByName(host);

        String a = address.toString();

        a = a.substring(a.indexOf('/') + 1);

        urlStr = urlStr.replace(host, a);
    }
    List<NameValuePair> list = new ArrayList<NameValuePair>();
    for (String key : paramsMap.keySet()) {

        BasicNameValuePair pair = new BasicNameValuePair(key, paramsMap.get(key));
        list.add(pair);
    }

    String result = client.forwardRequest(urlStr, list);
    if (post) {
        return stripOuterElement(result);
    } else {
        return result;
    }

}

From source file:org.onebusaway.nyc.presentation.impl.NycSearchServiceImpl.java

public boolean isStop(String s) {
    // stops are 6 digits
    int n = s.length();
    if (n != 6)//w w  w  .  j a va  2 s  .c  om
        return false;
    for (int i = 0; i < n; i++) {
        if (!Character.isDigit(s.charAt(i))) {
            return false;
        }
    }
    return true;
}

From source file:de.micromata.genome.gwiki.auth.GWikiSimpleUserAuthorization.java

/**
 * /*from  w w  w  . j  a v a  2  s . c  o m*/
 * @param plainText
 * @return possible combinations of password.
 */
public static long getPasswortCombinations(String plainText) {
    if (plainText == null) {
        return 0;
    }
    int r = 0;
    boolean lc = false;
    boolean uc = false;
    boolean dig = false;
    boolean other = false;
    char[] chars = plainText.toCharArray();
    for (int c : chars) {
        if (Character.isLowerCase(c) == true) {
            if (lc == false) {
                r += 26;
            }
            lc = true;
        } else if (Character.isUpperCase(c) == true) {
            if (uc == false) {
                r += 26;
                uc = true;
            }
        } else if (Character.isDigit(c) == true) {
            if (dig == false) {
                r += 10;
                dig = true;
            }
        } else {
            if (other == false) {
                r += 50;
                other = true;
            }
        }
    }
    return (long) Math.pow(r, plainText.length());
}

From source file:Data.Storage.java

/**
 * add an attribute, best use with xml/*from   ww  w.j a  va 2s.c  o  m*/
 * @param path the path of the element
 * @param attrKey the key of the attribute being added
 * @param attrValue value of the attribute being added
 */
public void putAttribute(String[] path, String attrKey, String attrValue) {
    int lastIndex = path.length - 1;
    String lastKey = path[lastIndex];
    //don't do anything if its an array, the key would be a number if an array
    boolean isNumber = true;
    for (char c : lastKey.toCharArray()) {
        if (!Character.isDigit(c)) {
            isNumber = false;
        }
    }
    //not supporting array attributes or adding attributes to non existent elements
    if (isNumber || !has(path))
        return;

    path[lastIndex] = lastKey + Converter.attributesId;

    //create attributes json
    if (!has(path)) {
        put(path, new JSONObject());
    }

    //create new array
    String[] attrPath = new String[path.length + 1];
    //populate the path to the attribute
    for (int i = 0; i < path.length; ++i) {
        attrPath[i] = path[i];
    }
    attrPath[path.length] = attrKey;

    put(attrPath, attrValue);
    //change the data back to how it was
    path[lastIndex] = lastKey;
}

From source file:XmlChars.java

private static boolean isDigit(char c) {
    // [88] Digit ::= ...

    ////from ww w .  j  a  v  a 2  s  .c  o m
    // java.lang.Character.isDigit is correct from the XML point
    // of view except that it allows "fullwidth" digits.
    //
    return Character.isDigit(c) && !((c >= 0xff10) && (c <= 0xff19));
}

From source file:com.miz.functions.MizLib.java

/**
 * Returns any digits (numbers) in a String
 * @param s (Input string)//from   ww  w  . ja  v  a  2s .  c  o m
 * @return A string with any digits from the input string
 */
public static String getNumbersInString(String s) {
    if (TextUtils.isEmpty(s))
        return "";

    StringBuilder result = new StringBuilder();
    char[] charArray = s.toCharArray();
    int count = charArray.length;
    for (int i = 0; i < count; i++)
        if (Character.isDigit(charArray[i]))
            result.append(charArray[i]);

    return result.toString();
}

From source file:Main.java

/**
 * <p>Checks whether the <code>String</code> contains only
 * digit characters.</p>/*ww  w . jav a 2s  .  c  om*/
 *
 * <p><code>Null</code> and empty String will return
 * <code>false</code>.</p>
 *
 * @param str  the <code>String</code> to check
 * @return <code>true</code> if str contains only unicode numeric
 */
public static boolean isDigits(String str) {
    if ((str == null) || (str.length() == 0)) {
        return false;
    }
    for (int i = 0; i < str.length(); i++) {
        if (!Character.isDigit(str.charAt(i))) {
            return false;
        }
    }
    return true;
}

From source file:net.antidot.semantic.rdf.rdb2rdf.r2rml.tools.R2RMLToolkit.java

/**
 * The IRI-safe version of a string is obtained by applying the following
 * transformation in [RFC3987].// ww  w . j  ava  2  s . com
 * 
 * @throws R2RMLDataError
 * @throws MalformedURLException
 */
public static String getIRISafeVersion(String value) {
    // Any character that is not in the iunreserved production
    // iunreserved = ALPHA / DIGIT / "-" / "." / "_" / "~" / ucschar
    StringBuffer buff = new StringBuffer(value.length());
    Set<Character> unreservedChars = new HashSet<Character>();

    unreservedChars.add('-');
    unreservedChars.add('.');
    unreservedChars.add('_');
    unreservedChars.add('~');
    unreservedChars.add('*');
    unreservedChars.add('\'');
    unreservedChars.add('(');
    unreservedChars.add(')');
    unreservedChars.add('!');
    unreservedChars.add('=');

    for (int i = 0; i < value.length(); i++) {
        char c = value.charAt(i);
        if (!(Character.isDigit(c) || Character.isLetter(c) || unreservedChars.contains(c))) {
            // Percent-encode each octet
            buff.append('%');
            buff.append(Integer.toHexString(c).toUpperCase());
        } else {
            buff.append(c);
        }
    }
    return buff.toString();
}

From source file:org.yawlfoundation.yawl.engine.interfce.Interface_Client.java

private void asyncSend(String urlStr, Map<String, String> paramsMap, boolean post) throws IOException {

    String p = "http://(.*):";
    Pattern pattern = Pattern.compile(p);

    Matcher matcher = pattern.matcher(urlStr);

    String host = null;// w w  w  . ja v a  2 s  . c o  m
    while (matcher.find()) {
        host = matcher.group(1);
    }

    if (!Character.isDigit(host.charAt(0))) {
        InetAddress address = InetAddress.getByName(host);

        String a = address.toString();

        a = a.substring(a.indexOf('/') + 1);

        urlStr = urlStr.replace(host, a);
    }
    List<NameValuePair> list = new ArrayList<NameValuePair>();
    for (String key : paramsMap.keySet()) {

        BasicNameValuePair pair = new BasicNameValuePair(key, paramsMap.get(key));
        list.add(pair);
    }

    client.asyncForwardRequest(urlStr, list);

}