Java Code Examples for org.apache.commons.lang3.math.NumberUtils#isParsable()

The following examples show how to use org.apache.commons.lang3.math.NumberUtils#isParsable() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ClusterIntegrationTestUtils.java    From incubator-pinot with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 2
Source File: StringUtils.java    From easter_eggs_for_java_9 with Apache License 2.0 5 votes vote down vote up
public int safeParseInt(String s) {
    int result = Integer.MIN_VALUE;

    if (NumberUtils.isParsable(s)) {
        try {
            result = Integer.parseInt(s);
        } catch(Exception ex) {
        } 
    }

    return result;
}
 
Example 3
Source File: StringUtils.java    From easter_eggs_for_java_9 with Apache License 2.0 5 votes vote down vote up
public int safeParseInt(String s) {
    int result = Integer.MIN_VALUE;

    if (NumberUtils.isParsable(s)) {
        try {
            result = Integer.parseInt(s);
        } catch(Exception ex) {
        } 
    }

    return result;
}
 
Example 4
Source File: UserServiceImpl.java    From easter_eggs_for_java_9 with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 5
Source File: LanguageProcessingHelper.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
private boolean label_skip_m(Item item) {
	if (!StringUtils.startsWithIgnoreCase(item.getLabel(), "m")) {
		return false;
	} else {
		return NumberUtils.isParsable(item.getValue());
	}
}
 
Example 6
Source File: LanguageProcessingHelper.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
private boolean label_skip_m(Item item) {
	if (!StringUtils.startsWithIgnoreCase(item.getLabel(), "m")) {
		return false;
	} else {
		return NumberUtils.isParsable(item.getValue());
	}
}
 
Example 7
Source File: ActionControl.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
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;
}
 
Example 8
Source File: Permission.java    From cyberduck with GNU General Public License v3.0 5 votes vote down vote up
public Permission(final String mode) {
    if(NumberUtils.isParsable(mode)) {
        this.fromInteger(Integer.parseInt(mode, 8));
    }
    else {
        this.fromSymbol(mode);
    }
}
 
Example 9
Source File: ConfigValueParser.java    From Plan with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public Integer compose(String fromValue) {
    if (NumberUtils.isParsable(fromValue)) {
        return NumberUtils.createInteger(fromValue);
    }
    return null;
}
 
Example 10
Source File: CurseFile.java    From ModPackDownloader with MIT License 5 votes vote down vote up
public CurseFile(String projectId, String projectName) {
	if (NumberUtils.isParsable(projectId)) {
		setProjectID(Integer.parseInt(projectId));
	}
	setProjectName(projectName);
	curseForge = true;
}
 
Example 11
Source File: UiControllerPropertyInjector.java    From cuba with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 12
Source File: Input.java    From red5-io with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example 13
Source File: MLPipelineComponentInstanceFactory.java    From AILibs with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * 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);
}
 
Example 14
Source File: ActionCustomPropertyLoader.java    From cuba with Apache License 2.0 4 votes vote down vote up
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);
}
 
Example 15
Source File: IsNumeric.java    From tutorials with MIT License 4 votes vote down vote up
public boolean usingNumberUtils_isParsable(String strNum) {
    return NumberUtils.isParsable(strNum);
}