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.openedit.users.filesystem.MapPropertyContainer.java

/**
 * Determine whether the given name is valid.  In order to be a valid name, the first character
 * must be a letter or underscore, and each subsequent character must be a letter, digit,
 * underscore, or period./*from www  . jav a  2 s .  c o  m*/
 *
 * @param inName The name to query
 *
 * @return <code>true</code> if the name is valid, <code>false</code> if not
 */
protected boolean isValidName(String inName) {
    if ((inName == null) || (inName.length() == 0)) {
        return false;
    }

    char c = inName.charAt(0);

    if ((c == '_') || Character.isLetter(c)) {
        for (int i = 1; i < inName.length(); i++) {
            c = inName.charAt(i);

            if ((c != '_') && (c != '.') && !Character.isLetter(c) && !Character.isDigit(c)) {
                return false;
            }
        }
    }

    return true;
}

From source file:io.uengine.util.StringUtils.java

/**
 *  ?? escape .//from ww  w  . j ava 2 s .  c o  m
 *
 * @param string Escape  ?
 * @return escape  ?
 */
public static String escape(String string) {
    int i;
    char j;
    StringBuilder builder = new StringBuilder();
    builder.ensureCapacity(string.length() * 6);
    for (i = 0; i < string.length(); i++) {
        j = string.charAt(i);
        if (Character.isDigit(j) || Character.isLowerCase(j) || Character.isUpperCase(j))
            builder.append(j);
        else if (j < 256) {
            builder.append("%");
            if (j < 16)
                builder.append("0");
            builder.append(Integer.toString(j, 16));
        } else {
            builder.append("%u");
            builder.append(Integer.toString(j, 16));
        }
    }
    return builder.toString();
}

From source file:gov.nih.nci.cananolab.util.StringUtils.java

public static boolean isInteger(String theStr) {
    if (isEmpty(theStr)) {
        return false;
    } else {//from  w  ww  . jav  a  2 s  .  c o  m
        for (int i = 0; i < theStr.length(); i++) {
            if (!Character.isDigit(theStr.charAt(i))) {
                return false;
            }
        }
        return true;
    }
}

From source file:io.github.jeddict.jcode.util.StringHelper.java

/**
 *
 * @param input/*from   w w w.j  a va 2  s. com*/
 * @return
 * @example
 *
 * BankAccount => BANK_ACCOUNT Bank_Account => BANK_ACCOUNT
 */
public static String toConstant(String input) {
    String constant = EMPTY;
    Character lastChar = null;
    for (Character curChar : input.toCharArray()) {
        if (lastChar == null) {
            // First character
            lastChar = Character.toUpperCase(curChar);
            constant = constant + lastChar;

        } else {
            if (Character.isLowerCase(lastChar)
                    && (Character.isUpperCase(curChar) || Character.isDigit(curChar))) {
                constant = constant + '_' + curChar;
            } else {
                constant = constant + Character.toUpperCase(curChar);
            }
            lastChar = curChar;
        }

    }
    return constant;
}

From source file:net.argilo.busfollower.ocdata.OCTranspoDataFetcher.java

private void validateStopNumber(String stopNumber) {
    if (stopNumber.length() < 3 || stopNumber.length() > 4) {
        throw new IllegalArgumentException(context.getString(R.string.invalid_stop_number));
    }//ww w.  j av a2  s.  c om
    for (int i = 0; i < stopNumber.length(); i++) {
        if (!Character.isDigit(stopNumber.charAt(i))) {
            throw new IllegalArgumentException(context.getString(R.string.invalid_stop_number));
        }
    }
}

From source file:de.micromata.genome.gwiki.page.search.expr.SearchUtils.java

private static Pair<Integer, Integer> readEmp(String text, int idx) {
    StringBuilder sb = new StringBuilder();
    for (; idx < text.length(); ++idx) {
        char c = text.charAt(idx);
        if (Character.isDigit(c) == false) {
            break;
        }//from ww  w .j  a v a2  s . c o  m
        sb.append(c);
    }
    if (sb.length() == 0) {
        return Pair.make(1, idx + 1);
    }
    return Pair.make(Integer.parseInt(sb.toString()), idx);
}

From source file:za.org.opengov.stockout.service.medical.impl.ProductServiceImpl.java

@Override
public void populateDatabaseFromCSV(File file, String seperator, String textDelimeter) {

    CSVParser parser;/*w w  w .  j  a v  a  2s. c  o m*/
    try {
        parser = new CSVParser(new FileInputStream(file), seperator, textDelimeter);

        for (List<String> row : parser.getRows()) {

            String medicineName = row.get(0);
            String dosage = row.get(1);
            String fullName = row.get(8);

            // add the medicine if it isn't in the DB already
            Medicine m = medicineService.findByName(medicineName);
            if (m == null) {
                m = new Medicine();
                m.setName(medicineName.trim().toUpperCase());
                medicineService.put(m);
            }

            ArrayList<String> terminateWords = new ArrayList<String>();

            terminateWords.add("TAB");
            terminateWords.add("SOL");
            terminateWords.add("ORAL");
            terminateWords.add("CAP");
            terminateWords.add("INJ");
            terminateWords.add("SUS");
            terminateWords.add("POW");
            terminateWords.add("PAED");
            terminateWords.add("CSV");

            String productName = "";
            String suffix = "";
            boolean appendToName = true;

            // split full name into product name and description
            String[] tokens = fullName.split(" ");
            for (int i = 0; i < tokens.length; i++) {
                if (!tokens[i].isEmpty()) {
                    if (!appendToName) {
                        suffix += tokens[i] + " ";
                    } else {
                        // inspect token to see if it terminates the product
                        // name
                        if (Character.isDigit(tokens[i].charAt(0)) || terminateWords.contains(tokens[i])) {
                            appendToName = false;
                            suffix += tokens[i] + " ";
                            continue;
                        }
                        productName += tokens[i] + " ";
                    }
                }
            }

            productName = productName.trim();
            suffix = suffix.trim();

            Product p = new Product();
            p.setUid(generateProductCode(fullName));
            p.setMedicine(m);
            p.setName(productName);
            p.setDescription(suffix);

            put(p);

        }
    } catch (FileNotFoundException e) {
        System.err.println("Could not load CSV file: " + file.getPath());
    }

}

From source file:com.ery.ertc.estorm.util.ToolUtil.java

public static long toLong(String val) {
    long l = 0;/* w w  w .  ja v a  2 s. com*/
    for (char c : val.toCharArray()) {
        if (Character.isDigit(c))
            l = l * 10 + c - 48;
        else
            break;
    }
    return l;
}

From source file:org.openmrs.module.clinicalsummary.web.controller.utils.ExtendedDataEncounterController.java

private Boolean isDigit(String string) {
    for (int i = 0; i < string.length(); i++)
        if (!Character.isDigit(string.charAt(i)))
            return Boolean.FALSE;
    return Boolean.TRUE;
}