protected void assertNodeNumbers(JsonNode n, int expInt, double expDouble) {
   assertEquals(expInt, n.asInt());
   assertEquals(expInt, n.asInt(-42));
   assertEquals((long) expInt, n.asLong());
   assertEquals((long) expInt, n.asLong(19L));
   assertEquals(expDouble, n.asDouble());
   assertEquals(expDouble, n.asDouble(-19.25));
 }
 protected void assertNodeNumbersForNonNumeric(JsonNode n) {
   assertFalse(n.isNumber());
   assertEquals(0, n.asInt());
   assertEquals(-42, n.asInt(-42));
   assertEquals(0, n.asLong());
   assertEquals(12345678901L, n.asLong(12345678901L));
   assertEquals(0.0, n.asDouble());
   assertEquals(-19.25, n.asDouble(-19.25));
 }
 @Override
 public void create(Record record, JsonNode json, Class clazz, String dir) throws Exception {
   for (Field f : clazz.getFields()) {
     if (!json.has(f.getName())) return;
     JsonNode j = json.get(f.getName());
     JsonField field = f.getAnnotation(JsonField.class);
     JsonStruc struc = f.getAnnotation(JsonStruc.class);
     if (field != null) {
       SubRecordData sub = record.get(field.value()[0]);
       if (f.getType() == String.class) ((SubZString) sub).value = j.asText();
       else if (f.getType() == JsonFile.class)
         ((SubZString) sub).value =
             (j.asText().startsWith("/") ? j.asText().substring(1) : dir + "/" + j.asText())
                 .replace("/", "\\");
       else if (f.getType() == int[].class)
         for (int i = 0; i < sub.size(); i++) ((SubIntArray) sub).value[i] = j.get(i).intValue();
       else if (f.getType() == JsonFormID[].class) {
         if (field.value()[1] != null) record.get(field.value()[1]);
         ((SubFormIDList) sub).value.clear();
         for (int i = 0; i < sub.size(); i++)
           ((SubFormIDList) sub).value.add(getFormId(j.get(i), field.value(), 2));
       }
     }
     if (struc != null) {
       SubRecordData sub = record.get(struc.value()[0]);
       Field subf = sub.getClass().getField(struc.value()[1]);
       if (f.getType() == int.class) subf.setInt(sub, j.asInt());
       else if (f.getType() == float.class) subf.setFloat(sub, (float) j.asDouble());
     }
   }
 }
Example #4
0
  @SuppressWarnings({"rawtypes", "unchecked"})
  private final ContinuousMapping parseContinuous(
      String columnName,
      Class<?> type,
      VisualProperty<?> vp,
      VisualMappingFunctionFactory factory,
      JsonNode mappingNode) {

    final ContinuousMapping mapping =
        (ContinuousMapping) factory.createVisualMappingFunction(columnName, type, vp);
    for (JsonNode point : mappingNode.get("points")) {
      JsonNode val = point.get("value");
      JsonNode lesser = point.get("lesser");
      JsonNode equal = point.get("equal");
      JsonNode greater = point.get("greater");

      final BoundaryRangeValues newPoint =
          new BoundaryRangeValues(
              vp.parseSerializableString(lesser.asText()),
              vp.parseSerializableString(equal.asText()),
              vp.parseSerializableString(greater.asText()));
      mapping.addPoint(val.asDouble(), newPoint);
    }

    return mapping;
  }
Example #5
0
 /**
  * Parses an ID.
  *
  * @param node
  * @return
  */
 protected Object parseId(JsonNode node) {
   if (node == null || node.isNull()) {
     return null;
   } else if (node.isDouble()) {
     return node.asDouble();
   } else if (node.isFloatingPointNumber()) {
     return node.asDouble();
   } else if (node.isInt()) {
     return node.asInt();
   } else if (node.isIntegralNumber()) {
     return node.asInt();
   } else if (node.isLong()) {
     return node.asLong();
   } else if (node.isTextual()) {
     return node.asText();
   }
   throw new IllegalArgumentException("Unknown id type");
 }
 public Double getDouble(
     String key, ObjectNode node, boolean required, String location, ParseResult result) {
   Double value = null;
   JsonNode v = node.get(key);
   if (node == null || v == null) {
     if (required) {
       result.missing(location, key);
       result.invalid();
     }
   } else if (v.getNodeType().equals(JsonNodeType.NUMBER)) {
     value = v.asDouble();
   }
   return value;
 }
 Double retrieveSchemaVersion(String collectionName) {
   try {
     SolrJsonResponse response =
         SolrSchemaRequest.version().process(factory.getSolrClient(collectionName));
     JsonNode node = response.getNode("version");
     return node != null ? node.asDouble() : Double.NaN;
   } catch (SolrServerException e) {
     EXCEPTION_TRANSLATOR.translateExceptionIfPossible(new RuntimeException(e));
   } catch (IOException e) {
     EXCEPTION_TRANSLATOR.translateExceptionIfPossible(new RuntimeException(e));
   } catch (SolrException e) {
     EXCEPTION_TRANSLATOR.translateExceptionIfPossible(new RuntimeException(e));
   }
   return Double.NaN;
 }
 private Float parseFloat(JsonNode value) {
   if (value.isMissingNode()) return null;
   return (float) value.asDouble();
 }
Example #9
0
 @Override
 public Object toValue(JsonNode value) {
   return value.asDouble();
 }