下面列出了org.apache.commons.lang3.math.NumberUtils#isParsable ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private static boolean fuzzyCompare(String h2Value, String brokerValue, String connectionValue) {
// Fuzzy compare expected value and actual value
boolean error = false;
if (NumberUtils.isParsable(h2Value)) {
double expectedValue = Double.parseDouble(h2Value);
double actualValueBroker = Double.parseDouble(brokerValue);
double actualValueConnection = Double.parseDouble(connectionValue);
if (!DoubleMath.fuzzyEquals(actualValueBroker, expectedValue, 1.0) || !DoubleMath
.fuzzyEquals(actualValueConnection, expectedValue, 1.0)) {
error = true;
}
} else {
if (!h2Value.equals(brokerValue) || !h2Value.equals(connectionValue)) {
error = true;
}
}
return error;
}
public int safeParseInt(String s) {
int result = Integer.MIN_VALUE;
if (NumberUtils.isParsable(s)) {
try {
result = Integer.parseInt(s);
} catch(Exception ex) {
}
}
return result;
}
public int safeParseInt(String s) {
int result = Integer.MIN_VALUE;
if (NumberUtils.isParsable(s)) {
try {
result = Integer.parseInt(s);
} catch(Exception ex) {
}
}
return result;
}
public static int safeParseInt(String s) {
int result = Integer.MIN_VALUE;
if (NumberUtils.isParsable(s)) {
try {
result = Integer.parseInt(s);
} catch(Exception ex) {
}
}
return result;
}
private boolean label_skip_m(Item item) {
if (!StringUtils.startsWithIgnoreCase(item.getLabel(), "m")) {
return false;
} else {
return NumberUtils.isParsable(item.getValue());
}
}
private boolean label_skip_m(Item item) {
if (!StringUtils.startsWithIgnoreCase(item.getLabel(), "m")) {
return false;
} else {
return NumberUtils.isParsable(item.getValue());
}
}
private Integer getArgInteger(CommandLine cmd, String opt, Integer defaultValue) {
Integer repeat = defaultValue;
String r = cmd.getOptionValue(opt);
if (NumberUtils.isParsable(r)) {
repeat = NumberUtils.toInt(r);
}
if (repeat < REPEAT_MIN || repeat > REPEAT_MAX) {
repeat = REPEAT_MIN;
}
return repeat;
}
public Permission(final String mode) {
if(NumberUtils.isParsable(mode)) {
this.fromInteger(Integer.parseInt(mode, 8));
}
else {
this.fromSymbol(mode);
}
}
@Override
public Integer compose(String fromValue) {
if (NumberUtils.isParsable(fromValue)) {
return NumberUtils.createInteger(fromValue);
}
return null;
}
public CurseFile(String projectId, String projectName) {
if (NumberUtils.isParsable(projectId)) {
setProjectID(Integer.parseInt(projectId));
}
setProjectName(projectName);
curseForge = true;
}
protected Object parseNumber(UiControllerProperty property, Class<? extends Number> numberType) {
String stringValue = (String) property.getValue();
if (!NumberUtils.isParsable(stringValue)) {
throw new GuiDevelopmentException(String.format(
"Unable to parse '%s' as '%s'. Property value '%s' will not be injected into '%s'",
property.getValue(), numberType, property.getName(), frameOwner),
UiControllerUtils.getScreen(frameOwner).getId());
}
return org.springframework.util.NumberUtils.parseNumber(stringValue, numberType);
}
@Override
public Object readMap() {
// the maximum number used in this mixed array
int maxNumber = buf.getInt();
log.debug("Read start mixed array: {}", maxNumber);
ObjectMap<Object, Object> result = new ObjectMap<Object, Object>();
// we must store the reference before we deserialize any items in it to
// ensure that reference IDs are correct
int reference = storeReference(result);
while (hasMoreProperties()) {
String key = getString();
Object item = Deserializer.deserialize(this, Object.class);
//log.info("key: {} item: {}", key, item);
if (!NumberUtils.isParsable(key)) {
result.put(key, item);
} else {
// map keys are either integers or strings, none will be doubles
if (key.contains(".")) {
result.put(key, item);
} else {
result.put(Integer.valueOf(key), item);
}
}
}
result.remove("length");
// replace the original reference with the final result
storeReference(reference, result);
return result;
}
/**
* Gets the parameters for the given pipeline element as a map from parameter
* name to value
*
* @param classifier
* The classifier for which to get the parameters
* @return The parameter map
*/
private Map<String, String> getParametersForPipelineElement(final Object classifier) {
if (classifier instanceof OptionHandler) {
OptionHandler handler = (OptionHandler) classifier;
HashMap<String, String> parametersWithValues = new HashMap<String, String>(handler.getOptions().length);
String optionName = null;
boolean previousStringWasAValue = true;
for (String option : handler.getOptions()) {
if (option.equals("--")) {
// TODO here all classifier parameters (i.e. for meta classifiers and such) are
// skipped! Might want to include that in the future
break;
}
if (previousStringWasAValue || (!(NumberUtils.isCreatable(option) || NumberUtils.isParsable(option))
&& option.startsWith("-"))) {
// Current String is option
if (!previousStringWasAValue) {
parametersWithValues.put(optionName, "true");
}
previousStringWasAValue = false;
optionName = option.equals("") ? option : option.substring(1, option.length());
} else {
// Current String is value
previousStringWasAValue = true;
parametersWithValues.put(optionName, option);
}
}
if (!previousStringWasAValue) {
parametersWithValues.put(optionName,
Collections.list(handler.getOptions()).get(handler.getOptions().length - 1));
}
return parametersWithValues;
}
return new HashMap<String, String>(0);
}
protected Object parseNumber(String stringValue, Class<? extends Number> numberType) {
if (!NumberUtils.isParsable(stringValue)) {
throw new DevelopmentException(String.format("Unable to parse '%s' as '%s'", stringValue, numberType));
}
return org.springframework.util.NumberUtils.parseNumber(stringValue, numberType);
}
public boolean usingNumberUtils_isParsable(String strNum) {
return NumberUtils.isParsable(strNum);
}