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

The following are Jave code examples for showing how to use toDouble() of the org.apache.commons.lang3.math.NumberUtils class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: sipsoup   File: NumberHandler.java   View Source Code Vote up 6 votes
@Override
public SyntaxNode parseToken(final String tokenStr) {
    return new SyntaxNode() {
        @Override
        public Object calc(Element element) {
            if (StringUtils.contains(tokenStr, ".")) {
                return NumberUtils.toDouble(tokenStr);
            } else {
                return NumberUtils.toInt(tokenStr);
            }
        }

        @Override
        public Class judeResultType() {
            return Double.class;
        }
    };
}
 
Example 2
Project: smockin   File: RuleResolverImpl.java   View Source Code Vote up 6 votes
boolean handleEquals(RestfulMockDefinitionRuleGroupCondition condition, final String inboundValue) {

        if (inboundValue == null) {
            return false;
        }

        final RuleDataTypeEnum ruleMatchDataType = condition.getDataType();
        final String ruleMatchValue = condition.getMatchValue();

        if (RuleDataTypeEnum.TEXT.equals(ruleMatchDataType)) {

            if (condition.isCaseSensitive() != null && condition.isCaseSensitive()) {
                return ruleMatchValue.equals(inboundValue);
            }

            return ruleMatchValue.equalsIgnoreCase(inboundValue);
        } else if (RuleDataTypeEnum.NUMERIC.equals(ruleMatchDataType)
                && NumberUtils.isCreatable(inboundValue)
                && NumberUtils.toDouble(inboundValue) == NumberUtils.toDouble(ruleMatchValue)) {
            return true;
        }

        return false;
    }
 
Example 3
Project: vscrawler   File: ExpressionParser.java   View Source Code Vote up 6 votes
private SyntaxNode buildByTokenHolder(TokenHolder tokenHolder) {
    if (tokenHolder.tokenType == TokenType.Expression) {
        return new ExpressionParser(new StringFunctionTokenQueue(tokenHolder.data)).parse();
    }
    if (tokenHolder.tokenType == TokenType.Function) {
        return parseFunction(new StringFunctionTokenQueue(tokenHolder.data));
    }
    if (tokenHolder.tokenType == TokenType.String) {
        return new StringSyntaxNode(tokenHolder.data);
    }
    if (tokenHolder.tokenType == TokenType.Boolean) {
        return new BooleanSyntaxNode(BooleanUtils.toBoolean(tokenHolder.data));
    }
    if (tokenHolder.tokenType == TokenType.Number) {
        if (tokenHolder.data.contains(".")) {
            return new NumberSyntaxNode(NumberUtils.toDouble(tokenHolder.data));
        } else {
            return new NumberSyntaxNode(NumberUtils.toInt(tokenHolder.data));
        }
    }
    throw new IllegalStateException("unknown token type: " + tokenHolder.tokenType);
}
 
Example 4
Project: sipsoup   File: ToDoubleFunction.java   View Source Code Vote up 5 votes
@Override
public Object call(Element element, List<SyntaxNode> params) {
    Preconditions.checkArgument(params.size() > 0, getName() + " at last has one parameter");
    Object calc = params.get(0).calc(element);
    if (calc instanceof Double) {
        return calc;
    }
    if (calc == null) {
        return null;
    }

    if (params.size() > 1) {
        Object defaultValue = params.get(1).calc(element);

        Preconditions.checkArgument(defaultValue != null && defaultValue instanceof Double,
                getName() + " parameter 2 must to be a Double now is:" + defaultValue);
        return NumberUtils.toDouble(calc.toString(), (Double) defaultValue);
    }
    return NumberUtils.toDouble(calc.toString());
}
 
Example 5
Project: givemeadriver   File: WebDriverProperties.java   View Source Code Vote up 4 votes
public double getPixelRatio() {
    return NumberUtils.toDouble(getProperty(CAPABILITY_PIXEL_RATIO));
}
 
Example 6
Project: azeroth   File: RedisNumber.java   View Source Code Vote up 4 votes
public Double getDouble() {
    String value = super.get();
    return value == null ? null : NumberUtils.toDouble(value);
}
 
Example 7
Project: util   File: NumberUtil.java   View Source Code Vote up 4 votes
/**
 * 将10进制的String安全的转化为double,当str为空或非数字字符串时,返回0
 */
public static double toDouble(String str) {
	return NumberUtils.toDouble(str, 0L);
}
 
Example 8
Project: util   File: NumberUtil.java   View Source Code Vote up 4 votes
/**
 * 将10进制的String安全的转化为double,当str为空或非数字字符串时,返回default值
 */
public static double toDouble(String str, double defaultValue) {
	return NumberUtils.toDouble(str, defaultValue);
}