Java 类org.apache.commons.lang.NumberUtils 实例源码

项目:carbondata    文件:DataTypeUtil.java   
/**
 * Below method will be used to basically to know whether the input data is valid string of
 * giving data type. If there is any non parseable string is present return false.
 */
public static boolean isValidData(String data, DataType actualDataType) {
  if (null == data) {
    return false;
  }
  try {
    switch (actualDataType) {
      case SHORT:
      case INT:
      case LONG:
      case DOUBLE:
      case DECIMAL:
        return NumberUtils.isNumber(data);
      case TIMESTAMP:
        if (data.isEmpty()) {
          return false;
        }
        SimpleDateFormat parser = new SimpleDateFormat(CarbonProperties.getInstance()
            .getProperty(CarbonCommonConstants.CARBON_TIMESTAMP_FORMAT,
                CarbonCommonConstants.CARBON_TIMESTAMP_DEFAULT_FORMAT));
        try {
          parser.parse(data);
          return true;
        } catch (ParseException e) {
          return false;
        }
      default:
        return true;
    }
  } catch (NumberFormatException ex) {
    return false;
  }
}
项目:kc-rice    文件:PagingBannerUtils.java   
/**
 * find the number string in a method to call parameter with the following format parameterPrefix.1 or
 * parameterPrefix.1.bleh
 * 
 * @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;
}
项目:rice    文件:PagingBannerUtils.java   
/**
 * find the number string in a method to call parameter with the following format parameterPrefix.1 or
 * parameterPrefix.1.bleh
 * 
 * @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;
}
项目:bootchart    文件:TypeHandler.java   
/**
 * <p>Create a number from a String.</p>
 *
 * @param str the value
 * @return the number represented by <code>str</code>, if <code>str</code>
 * is not a number, null is returned.
 */
public static Number createNumber(String str) {
    // Needs to be able to create
    try {
        // do searching for decimal point etc, but atm just make an Integer
        return NumberUtils.createNumber(str);
    } catch (NumberFormatException nfe) {
        System.err.println(nfe.getMessage());
        return null;
    }
}
项目:kuali_rice    文件:PagingBannerUtils.java   
/**
 * find the number string in a method to call parameter with the following format parameterPrefix.1 or
 * parameterPrefix.1.bleh
 * 
 * @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;
}
项目:SOAPgaea    文件:ReportColumn.java   
/**
 * Check if the value can be right aligned. Does not trim the values before checking if numeric since it assumes
 * the spaces mean that the value is already padded.
 *
 * @param value to check
 * @return true if the value is a right alignable
 */
protected static boolean isRightAlign(final String value) {
    return value == null || RIGHT_ALIGN_STRINGS.contains(value) || NumberUtils.isNumber(value.trim());
}