本文整理汇总了Java中org.apache.commons.lang.NumberUtils类的典型用法代码示例。如果您正苦于以下问题:Java NumberUtils类的具体用法?Java NumberUtils怎么用?Java NumberUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NumberUtils类属于org.apache.commons.lang包,在下文中一共展示了NumberUtils类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isValidData
import org.apache.commons.lang.NumberUtils; //导入依赖的package包/类
/**
* 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;
}
}
示例2: getNumbericalValueAfterPrefix
import org.apache.commons.lang.NumberUtils; //导入依赖的package包/类
/**
* 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;
}
示例3: createNumber
import org.apache.commons.lang.NumberUtils; //导入依赖的package包/类
/**
* <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;
}
}
示例4: isRightAlign
import org.apache.commons.lang.NumberUtils; //导入依赖的package包/类
/**
* 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());
}