Example usage for org.apache.commons.lang NumberUtils isDigits

List of usage examples for org.apache.commons.lang NumberUtils isDigits

Introduction

In this page you can find the example usage for org.apache.commons.lang NumberUtils isDigits.

Prototype

public static boolean isDigits(String str) 

Source Link

Document

Checks whether the String contains only digit characters.

Null and empty String will return false.

Usage

From source file:org.kuali.rice.kns.util.PagingBannerUtils.java

/**
 * find the number string in a method to call parameter with the following format parameterPrefix.1 or
 * parameterPrefix.1.bleh/*  ww  w .j  av  a2s.c o  m*/
 * 
 * @param paramPrefix the 
 * @param parameterNames the parameter names.
 * @return the numerical value or -1
 */
public static int getNumbericalValueAfterPrefix(String paramPrefix, Enumeration<String> parameterNames) {

    for (String parameterName : CollectionUtils.toIterable(parameterNames)) {
        if (parameterName.startsWith(paramPrefix)) {
            parameterName = WebUtils.endsWithCoordinates(parameterName) ? parameterName : parameterName + ".x";
            String numberStr = StringUtils.substringBetween(parameterName, paramPrefix, ".");
            if (NumberUtils.isDigits(numberStr)) {
                return Integer.parseInt(numberStr);
            }
        }
    }

    return -1;
}

From source file:org.ut.biolab.medsavant.shared.vcf.VariantRecord.java

private static Object parse(Class c, String value) {

    if (c == String.class) {
        if (value.equals(nullString)) {
            return "";
        }/*from  w ww.  j av a 2s  . co  m*/
        return value;
    }

    if (value.equals(nullString)) {
        return null;
    }

    if (c == Long.class) {
        try {
            return NumberUtils.isDigits(value) ? Long.parseLong(value) : null;
        } catch (Exception e) {
            return null;
        }
    }

    if (c == Float.class) {
        try {
            return NumberUtils.isNumber(value) ? Float.parseFloat(value) : null;
        } catch (Exception e) {
            return null;
        }
    }

    //if flag exists, set to true
    if (c == Boolean.class) {
        return true;
    }

    if (c == Integer.class) {
        try {
            return NumberUtils.isDigits(value) ? Integer.parseInt(value) : null;
        } catch (Exception e) {
            return null;
        }
    }

    throw new UnsupportedOperationException("Parser doesn't deal with objects of type " + c);
}