@Override public int compare(final JsonNode o1, final JsonNode o2) { return o1.bigIntegerValue().compareTo(o2.bigIntegerValue()); } };
@Override public BigInteger getBigIntegerValue() throws IOException, JsonParseException { return currentNumericNode().bigIntegerValue(); }
public DivisorsKeywordValidator(final JsonNode digest) { super("divisors"); final ImmutableList.Builder<BigInteger> list = ImmutableList.builder(); for (final JsonNode element: digest) list.add(element.bigIntegerValue()); divisors = list.build(); }
@Override public void validate(final Processor<FullData, FullData> processor, final ProcessingReport report, final MessageBundle bundle, final FullData data) throws ProcessingException { final BigInteger value = data.getInstance().getNode().bigIntegerValue(); /* * We use a plain list to store failed divisors: remember that the * digested form was built with divisors in order, we therefore * only need insertion order, and a plain ArrayList guarantees that. */ final List<BigInteger> failed = Lists.newArrayList(); for (final BigInteger divisor: divisors) if (!value.mod(divisor).equals(BigInteger.ZERO)) failed.add(divisor); if (failed.isEmpty()) return; /* * There are missed divisors: report. */ report.error(newMsg(data, bundle, "missingDivisors") .put("divisors", divisors).put("failed", failed)); }
return (D) jsonNode.bigIntegerValue();
@Override public void validate(final ProcessingReport report, final MessageBundle bundle, final FullData data) throws ProcessingException { final JsonNode instance = data.getInstance().getNode(); BigInteger epoch = instance.bigIntegerValue(); if (epoch.signum() == -1) { report.warn(newMsg(data, bundle, "warn.format.epoch.negative") .putArgument("value", instance)); return; } epoch = epoch.divide(ONE_THOUSAND); if (epoch.bitLength() > EPOCH_BITLENGTH) report.warn(newMsg(data, bundle, "warn.format.epoch.overflow") .putArgument("value", instance)); } }
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: case NULL: case OBJECT: case ARRAY: 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(); } } }
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(); } } }
.put("expected", NodeType.INTEGER) .put("found", type)); else if (element.bigIntegerValue().compareTo(BigInteger.ONE) < 0) report.error(newMsg(tree, bundle, "integerIsNegative") .put("value", element));
public DivisorsKeywordValidator(final JsonNode schema) { super("divisors", NodeType.INTEGER); /* * Use Google's ImmutableSet */ final ImmutableSet.Builder<BigInteger> set = ImmutableSet.builder(); for (final JsonNode element: schema.get(keyword)) set.add(element.bigIntegerValue()); divisors = set.build(); }
@Override public BigInteger getBigIntegerValue() throws IOException, JsonParseException { return currentNumericNode().bigIntegerValue(); }
@Override public BigInteger getBigIntegerValue() throws IOException, JsonParseException { return currentNumericNode().bigIntegerValue(); }
@Override public BigInteger getBigIntegerValue() throws IOException, JsonParseException { return currentNumericNode().bigIntegerValue(); }
@Override public BigInteger getBigIntegerValue() throws IOException, JsonParseException { return currentNumericNode().bigIntegerValue(); }
@Override public BigInteger getBigIntegerValue() throws IOException, JsonParseException { return currentNumericNode().bigIntegerValue(); }
@Override public BigInteger getBigIntegerValue() throws IOException, JsonParseException { return currentNumericNode().bigIntegerValue(); }
protected ChannelStatistics setChannelStatistics(JsonNode node) { ChannelStatistics stats = new ChannelStatistics(); if (node == null) { return stats; } stats.setCommentCount(node.get("commentCount").bigIntegerValue()); stats.setHiddenSubscriberCount(node.get("hiddenSubscriberCount").asBoolean()); stats.setSubscriberCount(node.get("subscriberCount").bigIntegerValue()); stats.setVideoCount(node.get("videoCount").bigIntegerValue()); stats.setViewCount(node.get("viewCount").bigIntegerValue()); return stats; }
@Override public Object fromJson(JsonNode node) { if (node == null || node instanceof NullNode) { return null; } else if (node instanceof TextNode) { return new BigInteger(node.asText()); } if (node.isValueNode()) { return node.bigIntegerValue(); } else { throw Error.get(NAME, MetadataConstants.ERR_INCOMPATIBLE_VALUE, node.toString()); } }
@Override public Object fromJson(JsonNode node) { if (node.isValueNode()) { return node.bigIntegerValue(); } else { throw Error.get(NAME, MetadataConstants.ERR_INCOMPATIBLE_VALUE, node.toString()); } }
@Override public Object parseJsonNode(JsonNode input, Schema schema) { Preconditions.checkState(input.isInt(), "'%s' is not a '%s'", input.textValue(), expectedClass().getSimpleName()); return input.bigIntegerValue().byteValue(); } }