/** * Converts the lhs and rhs JsonNodes to the numeric values * and delegates to the matches method that operates on the * numeric values alone. * * @param lhs Lhs expression * @param rhs Rhs expression * @return Boolean result of the matches method of the * corresponding comparison operator */ @Override public final boolean matches(JsonNode lhs, JsonNode rhs) { return matches(lhs.decimalValue(), rhs.decimalValue()); }
@Override public BigDecimal getDecimalValue() throws IOException, JsonParseException { return currentNumericNode().decimalValue(); }
public BigDecimal getExpectedAsNumber() { if(expected.isNumber()) { return expected.decimalValue(); } return null; }
@Override public KucoinDealOrder deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException { JsonNode root = p.readValueAsTree(); if (root.isArray()) { Long timestamp = root.get(0).asLong(); KucoinOrderType orderType = KucoinOrderType.valueOf(root.get(1).asText()); BigDecimal price = root.get(2).decimalValue(); BigDecimal amount = root.get(3).decimalValue(); BigDecimal volume = root.get(4).decimalValue(); return new KucoinDealOrder(timestamp, orderType, price, amount, volume); } else { throw new RuntimeException("KucoinDealOrder should have an array as root node!"); } } }
@Override public KucoinActiveOrder deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException { JsonNode root = p.readValueAsTree(); if (root.isArray()) { Date timestamp = new Date(root.get(0).asLong()); KucoinOrderType orderType = KucoinOrderType.valueOf(root.get(1).asText()); BigDecimal price = root.get(2).decimalValue(); BigDecimal amount = root.get(3).decimalValue(); BigDecimal dealAmount = root.get(4).decimalValue(); // amount already filled String orderOid = root.get(5).textValue(); return new KucoinActiveOrder(timestamp, orderType, price, amount, dealAmount, orderOid); } else { throw new RuntimeException("KucoinDealOrder should have an array as root node!"); } } }
private static boolean valueIsLong(final JsonNode node) { if (!node.canConvertToLong()) return false; if (NodeType.getNodeType(node) == NodeType.INTEGER) return true; return node.decimalValue().remainder(BigDecimal.ONE) .compareTo(BigDecimal.ZERO) == 0; }
protected final ObjectNode digestedNumberNode(final JsonNode schema) { final ObjectNode ret = FACTORY.objectNode(); final JsonNode node = schema.get(keyword); final boolean isLong = valueIsLong(node); ret.put("valueIsLong", isLong); if (isLong) { ret.put(keyword, node.canConvertToInt() ? FACTORY.numberNode(node.intValue()) : FACTORY.numberNode(node.longValue())); return ret; } final BigDecimal decimal = node.decimalValue(); ret.put(keyword, decimal.scale() == 0 ? FACTORY.numberNode(decimal.toBigIntegerExact()) : node); return ret; } }
return e.asLong(); } else if (e.isBigDecimal()) { return e.decimalValue(); } else if (e.isDouble()) { return e.doubleValue(); return e.floatValue(); } else if (e.isBigDecimal()) { return e.decimalValue(); } else if (e.isNull()) { return null;
return (D) jsonNode.decimalValue();
@Override protected final void validateDecimal(final ProcessingReport report, final MessageBundle bundle, final FullData data) throws ProcessingException { final JsonNode node = data.getInstance().getNode(); final BigDecimal instanceValue = node.decimalValue(); final BigDecimal decimalValue = number.decimalValue(); final BigDecimal remainder = instanceValue.remainder(decimalValue); /* * We cannot use equality! As far as BigDecimal goes, * "0" and "0.0" are NOT equal. But .compareTo() returns the correct * result. */ if (remainder.compareTo(BigDecimal.ZERO) == 0) return; report.error(newMsg(data, bundle, "err.common.divisor.nonZeroRemainder") .putArgument("value", node).putArgument("divisor", number)); } }
@Override protected void validateDecimal(final ProcessingReport report, final MessageBundle bundle, final FullData data) throws ProcessingException { final JsonNode instance = data.getInstance().getNode(); final BigDecimal instanceValue = instance.decimalValue(); final BigDecimal decimalValue = number.decimalValue(); final int cmp = instanceValue.compareTo(decimalValue); if (cmp > 0) return; if (cmp < 0) { report.error(newMsg(data, bundle, "err.common.minimum.tooSmall") .putArgument(keyword, number).putArgument("found", instance)); return; } if (!exclusive) return; report.error(newMsg(data, bundle, "err.common.minimum.notExclusive") .putArgument(keyword, number) .put("exclusiveMinimum", BooleanNode.TRUE)); } }
@Override protected void validateDecimal(final ProcessingReport report, final MessageBundle bundle, final FullData data) throws ProcessingException { final JsonNode instance = data.getInstance().getNode(); final BigDecimal instanceValue = instance.decimalValue(); final BigDecimal decimalValue = number.decimalValue(); final int cmp = instanceValue.compareTo(decimalValue); if (cmp < 0) return; if (cmp > 0) { report.error(newMsg(data, bundle, "err.common.maximum.tooLarge") .putArgument(keyword, number).putArgument("found", instance)); return; } if (!exclusive) return; report.error(newMsg(data, bundle, "err.common.maximum.notExclusive") .putArgument(keyword, number) .put("exclusiveMaximum", BooleanNode.TRUE)); } }
private static Object valueToArgument(final JsonNode value) { final NodeType type = NodeType.getNodeType(value); switch (type) { case STRING: return value.textValue(); case INTEGER: return value.bigIntegerValue(); case NUMBER: return value.decimalValue().toPlainString(); case NULL: return value; case BOOLEAN: return value.booleanValue(); case ARRAY: final List<Object> list = Lists.newArrayList(); for (final JsonNode element: value) list.add(valueToArgument(element)); return list; default: throw new UnsupportedOperationException(); } } }
return (new DoubleWritable(value.doubleValue())); case DECIMAL: return (new HiveDecimalWritable(HiveDecimal.create(value.decimalValue()))); case CHAR: return (new HiveCharWritable(new HiveChar(value.textValue(), ((CharTypeInfo) typeInfo).getLength())));
return e.asLong(); } else if (e.isBigDecimal()) { return e.decimalValue(); } else if (e.isDouble()) { return e.doubleValue(); return e.floatValue(); } else if (e.isBigDecimal()) { return e.decimalValue(); } else if (e.isNull()) { return null;
private static boolean numEquals(final JsonNode a, final JsonNode b) { /* * If both numbers are integers, delegate to JsonNode. */ if (a.isIntegralNumber() && b.isIntegralNumber()) { return a.equals(b); } /* * Otherwise, compare decimal values. */ return a.decimalValue().compareTo(b.decimalValue()) == 0; }
private static boolean numEquals(final JsonNode a, final JsonNode b) { /* * If both numbers are integers, delegate to JsonNode. */ if (a.isIntegralNumber() && b.isIntegralNumber()) { return a.equals(b); } /* * Otherwise, compare decimal values. */ return a.decimalValue().compareTo(b.decimalValue()) == 0; }
private static boolean numEquals(final JsonNode a, final JsonNode b) { /* * If both numbers are integers, delegate to JsonNode. */ if (a.isIntegralNumber() && b.isIntegralNumber()) return a.equals(b); /* * Otherwise, compare decimal values. */ return a.decimalValue().compareTo(b.decimalValue()) == 0; }
private static boolean numEquals(final JsonNode a, final JsonNode b) { /* * If both numbers are integers, delegate to JsonNode. */ if (a.isIntegralNumber() && b.isIntegralNumber()) return a.equals(b); /* * Otherwise, compare decimal values. */ return a.decimalValue().compareTo(b.decimalValue()) == 0; }
@Override public Object parseJsonNode(JsonNode input, Schema schema) { Preconditions.checkState(input.isFloat() || input.isDouble(), "'%s' is not a '%s'", input.asText(), expectedClass().getSimpleName()); return input.decimalValue().doubleValue(); } }