类com.fasterxml.jackson.databind.node.DoubleNode源码实例Demo

下面列出了怎么用com.fasterxml.jackson.databind.node.DoubleNode的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: yosegi   文件: ObjectToJsonNode.java
/**
 * Judge Java objects and create JsonNode.
 */
public static JsonNode get( final Object obj ) throws IOException {
  if ( obj instanceof PrimitiveObject ) {
    return PrimitiveObjectToJsonNode.get( (PrimitiveObject)obj );
  } else if ( obj instanceof String ) {
    return new TextNode( (String)obj );
  } else if ( obj instanceof Boolean ) {
    return BooleanNode.valueOf( (Boolean)obj );
  } else if ( obj instanceof Short ) {
    return IntNode.valueOf( ( (Short)obj ).intValue() );
  } else if ( obj instanceof Integer ) {
    return IntNode.valueOf( (Integer)obj );
  } else if ( obj instanceof Long ) {
    return new LongNode( (Long)obj );
  } else if ( obj instanceof Float ) {
    return new DoubleNode( ( (Float)obj ).doubleValue() );
  } else if ( obj instanceof Double ) {
    return new DoubleNode( (Double)obj );
  } else if ( obj instanceof byte[] ) {
    return new BinaryNode( (byte[])obj );
  } else if ( obj == null ) {
    return NullNode.getInstance();
  } else {
    return new TextNode( obj.toString() );
  }
}
 
源代码2 项目: jslt   文件: BuiltinFunctions.java
public JsonNode call(JsonNode input, JsonNode[] arguments) {
  JsonNode array = arguments[0];
  if (array.isNull())
    return NullNode.instance;
  else if (!array.isArray())
    throw new JsltException("sum(): argument must be array, was " + array);

  double sum = 0.0;
  boolean integral = true;
  for (int ix = 0; ix < array.size(); ix++) {
    JsonNode value = array.get(ix);
    if (!value.isNumber())
      throw new JsltException("sum(): array must contain numbers, found " + value);
    integral &= value.isIntegralNumber();

    sum += value.doubleValue();
  }
  if (integral)
    return new LongNode((long) sum);
  else
    return new DoubleNode(sum);
}
 
源代码3 项目: jslt   文件: DivideOperator.java
public JsonNode perform(JsonNode v1, JsonNode v2) {
  if (v1.isNull() || v2.isNull())
    return NullNode.instance;

  // we only support the numeric operation and nothing else
  v1 = NodeUtils.number(v1, true, location);
  v2 = NodeUtils.number(v2, true, location);

  if (v1.isIntegralNumber() && v2.isIntegralNumber()) {
    long l1 = v1.longValue();
    long l2 = v2.longValue();
    if (l1 % l2 == 0)
      return new LongNode(l1 / l2);
    else
      return new DoubleNode((double) l1 / (double) l2);
  } else
    return new DoubleNode(perform(v1.doubleValue(), v2.doubleValue()));
}
 
源代码4 项目: splicer   文件: TsdbResult.java
@Override
public Points deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
	TreeNode n = jp.getCodec().readTree(jp);
	Map<String, Object> points = new HashMap<>();
	Iterator<String> namesIter = n.fieldNames();
	while(namesIter.hasNext()) {
		String field = namesIter.next();
		TreeNode child = n.get(field);

		Object o;
		if (child instanceof DoubleNode || child instanceof FloatNode) {
			o = ((NumericNode) child).doubleValue();
		} else if (child instanceof IntNode || child instanceof LongNode) {
			o = ((NumericNode) child).longValue();
		} else {
			throw new MergeException("Unsupported Type, " + child.getClass());
		}

		points.put(field, o);
	}
	return new Points(points);
}
 
源代码5 项目: flowable-engine   文件: DecisionTaskTest.java
@Test
@CmmnDeployment(resources = {
        "org/flowable/cmmn/test/runtime/DecisionTaskTest.oneDecisionTaskCase.cmmn",
        "org/flowable/cmmn/test/runtime/DecisionTaskTest.outputOrder.dmn"})
public void withOutputOrder_ensureListOfItemIsReturnedEvenIfOnlyOneRowIsHit() {
    CaseInstance caseInstance = this.cmmnRule.getCmmnRuntimeService().createCaseInstanceBuilder()
            .caseDefinitionKey("oneDecisionTaskCase")
            .variable("testInput", "second")
            .start();
    Map<String, Object> caseVariables = caseInstance.getCaseVariables();
    Object resultObject = caseVariables.get("DecisionTable");
    assertThat(resultObject).isInstanceOf(ArrayNode.class);
    ArrayNode result = (ArrayNode) resultObject;
    assertThat(result).hasSize(1);
    assertThat(result.get(0)).isInstanceOf(ObjectNode.class);
    assertThat(result.get(0).get("testOutput")).isInstanceOf(DoubleNode.class);
    assertThat(result.get(0).get("testOutput").asDouble()).isEqualTo(2.0);
}
 
源代码6 项目: flowable-engine   文件: DecisionTaskTest.java
@Test
@CmmnDeployment(resources = {
        "org/flowable/cmmn/test/runtime/DecisionTaskTest.oneDecisionTaskCase.cmmn",
        "org/flowable/cmmn/test/runtime/DecisionTaskTest.ruleOrder.dmn"})
public void withRuleOrder_ensureListOfItemIsReturnedEvenIfOnlyOneRowIsHit() {
    CaseInstance caseInstance = this.cmmnRule.getCmmnRuntimeService().createCaseInstanceBuilder()
            .caseDefinitionKey("oneDecisionTaskCase")
            .variable("testInput", "second")
            .start();
    Map<String, Object> caseVariables = caseInstance.getCaseVariables();
    Object resultObject = caseVariables.get("DecisionTable");
    assertThat(resultObject).isInstanceOf(ArrayNode.class);
    ArrayNode result = (ArrayNode) resultObject;
    assertThat(result).hasSize(1);
    assertThat(result.get(0)).isInstanceOf(ObjectNode.class);
    assertThat(result.get(0).get("testOutput")).isInstanceOf(DoubleNode.class);
    assertThat(result.get(0).get("testOutput").asDouble()).isEqualTo(2.0);
}
 
源代码7 项目: flowable-engine   文件: DmnTaskTest.java
@Test
@Deployment(resources = {
        "org/flowable/bpmn/test/runtime/DmnTaskTest.oneDecisionTaskProcess.bpmn20.xml",
        "org/flowable/bpmn/test/runtime/DmnTaskTest.outputOrder.dmn"})
void withOutputOrder_ensureListOfItemIsReturnedEvenIfOnlyOneRowIsHit() {
    ProcessInstance processInstance = this.runtimeService.createProcessInstanceBuilder()
            .processDefinitionKey("oneDecisionTaskProcess")
            .variable("testInput", "second")
            .start();
    Map<String, Object> processVariables = processInstance.getProcessVariables();
    Object resultObject = processVariables.get("DecisionTable");
    assertThat(resultObject).isInstanceOf(ArrayNode.class);
    ArrayNode result = (ArrayNode) resultObject;
    assertThat(result).hasSize(1);
    assertThat(result.get(0)).isInstanceOf(ObjectNode.class);
    assertThat(result.get(0).get("testOutput")).isInstanceOf(DoubleNode.class);
    assertThat(result.get(0).get("testOutput").asDouble()).isEqualTo(2.0);
}
 
源代码8 项目: flowable-engine   文件: DmnTaskTest.java
@Test
@Deployment(resources = {
        "org/flowable/bpmn/test/runtime/DmnTaskTest.oneDecisionTaskProcess.bpmn20.xml",
        "org/flowable/bpmn/test/runtime/DmnTaskTest.ruleOrder.dmn"})
void withRuleOrder_ensureListOfItemIsReturnedEvenIfOnlyOneRowIsHit() {
    ProcessInstance processInstance = this.runtimeService.createProcessInstanceBuilder()
            .processDefinitionKey("oneDecisionTaskProcess")
            .variable("testInput", "second")
            .start();
    Map<String, Object> processVariables = processInstance.getProcessVariables();
    Object resultObject = processVariables.get("DecisionTable");
    assertThat(resultObject).isInstanceOf(ArrayNode.class);
    ArrayNode result = (ArrayNode) resultObject;
    assertThat(result).hasSize(1);
    assertThat(result.get(0)).isInstanceOf(ObjectNode.class);
    assertThat(result.get(0).get("testOutput")).isInstanceOf(DoubleNode.class);
    assertThat(result.get(0).get("testOutput").asDouble()).isEqualTo(2.0);
}
 
源代码9 项目: onos   文件: DistributedNetworkConfigStore.java
@Activate
public void activate() {
    KryoNamespace.Builder kryoBuilder = new KryoNamespace.Builder()
            .register(KryoNamespaces.API)
            .register(ConfigKey.class, ObjectNode.class, ArrayNode.class,
                      JsonNodeFactory.class, LinkedHashMap.class,
                      TextNode.class, BooleanNode.class,
                      LongNode.class, DoubleNode.class, ShortNode.class, IntNode.class,
                      NullNode.class);

    configs = storageService.<ConfigKey, JsonNode>consistentMapBuilder()
            .withSerializer(Serializer.using(kryoBuilder.build()))
            .withName("onos-network-configs")
            .withRelaxedReadConsistency()
            .build();
    configs.addListener(listener);
    log.info("Started");
}
 
源代码10 项目: log-synth   文件: RandomWalkSampler.java
@Override
public JsonNode sample() {
    double step;
    if (stepDistribution == null) {
        step = rand.nextGaussian() * sd.sample().asDouble() + mean.sample().asDouble();
    } else {
        step = stepDistribution.sample().asDouble();
    }
    double newState = state.addAndGet(step);

    if (verbose) {
        ObjectNode r = new ObjectNode(JsonNodeFactory.withExactBigDecimals(false));
        r.set("value", new DoubleNode(newState));
        r.set("step", new DoubleNode(step));
        return r;
    } else {
        return new DoubleNode(newState);
    }
}
 
源代码11 项目: log-synth   文件: RandomWalkSampler.java
@SuppressWarnings("UnusedDeclaration")
public void setPrecision(final JsonNode value) throws IOException {
    if (value.isObject()) {
        sd = new FieldSampler() {
            FieldSampler base = FieldSampler.newSampler(value.toString());

            @Override
            public JsonNode sample() {
                return new DoubleNode(Math.sqrt(1 / base.sample().asDouble()));
            }
        };
    } else {
        this.sd = constant(Math.sqrt(1 / value.asDouble()));
    }
    init();
}
 
源代码12 项目: log-synth   文件: RandomWalkSampler.java
@SuppressWarnings("UnusedDeclaration")
public void setVariance(final JsonNode value) throws IOException {
    if (value.isObject()) {
        sd = new FieldSampler() {
            FieldSampler base = FieldSampler.newSampler(value.toString());

            @Override
            public JsonNode sample() {
                return new DoubleNode(Math.sqrt(base.sample().asDouble()));
            }
        };
    } else {
        this.sd = constant(Math.sqrt(value.asDouble()));
    }
    init();
}
 
源代码13 项目: log-synth   文件: RandomWalkSampler.java
@SuppressWarnings("UnusedDeclaration")
public void setSD(final JsonNode value) throws IOException {
    if (value.isObject()) {
        sd = new FieldSampler() {
            FieldSampler base = FieldSampler.newSampler(value.toString());

            @Override
            public JsonNode sample() {
                return new DoubleNode(base.sample().asDouble());
            }
        };
    } else {
        sd = constant(value.asDouble());
    }
    init();
}
 
源代码14 项目: yosegi   文件: JsonNodeToPrimitiveObject.java
/**
 * Converts JsonNode to PrimitiveObject.
 */
public static PrimitiveObject get( final JsonNode jsonNode ) throws IOException {
  if ( jsonNode instanceof TextNode ) {
    return new StringObj( ( (TextNode)jsonNode ).textValue() );
  } else if ( jsonNode instanceof BooleanNode ) {
    return new BooleanObj( ( (BooleanNode)jsonNode ).booleanValue() );
  } else if ( jsonNode instanceof IntNode ) {
    return new IntegerObj( ( (IntNode)jsonNode ).intValue() );
  } else if ( jsonNode instanceof LongNode ) {
    return new LongObj( ( (LongNode)jsonNode ).longValue() );
  } else if ( jsonNode instanceof DoubleNode ) {
    return new DoubleObj( ( (DoubleNode)jsonNode ).doubleValue() );
  } else if ( jsonNode instanceof BigIntegerNode ) {
    return new StringObj( ( (BigIntegerNode)jsonNode ).bigIntegerValue().toString() );
  } else if ( jsonNode instanceof DecimalNode ) {
    return new StringObj( ( (DecimalNode)jsonNode ).decimalValue().toString() );
  } else if ( jsonNode instanceof BinaryNode ) {
    return new BytesObj( ( (BinaryNode)jsonNode ).binaryValue() );
  } else if ( jsonNode instanceof POJONode ) {
    return new BytesObj( ( (POJONode)jsonNode ).binaryValue() );
  } else if ( jsonNode instanceof NullNode ) {
    return NullObj.getInstance();
  } else if ( jsonNode instanceof MissingNode ) {
    return NullObj.getInstance();
  } else {
    return new StringObj( jsonNode.toString() );
  }
}
 
源代码15 项目: yosegi   文件: PrimitiveObjectToJsonNode.java
/**
 * Convert PrimitiveObject to JsonNode.
 */
public static JsonNode get( final PrimitiveObject obj ) throws IOException {
  if ( obj == null ) {
    return NullNode.getInstance();
  }
  switch ( obj.getPrimitiveType() ) {
    case BOOLEAN:
      return BooleanNode.valueOf( obj.getBoolean() );
    case BYTE:
      return IntNode.valueOf( obj.getInt() );
    case SHORT:
      return IntNode.valueOf( obj.getInt() );
    case INTEGER:
      return IntNode.valueOf( obj.getInt() );
    case LONG:
      return new LongNode( obj.getLong() );
    case FLOAT:
      return new DoubleNode( obj.getDouble() );
    case DOUBLE:
      return new DoubleNode( obj.getDouble() );
    case STRING:
      return new TextNode( obj.getString() );
    case BYTES:
      return new BinaryNode( obj.getBytes() );
    default:
      return NullNode.getInstance();
  }
}
 
源代码16 项目: jslt   文件: NumericOperator.java
public JsonNode perform(JsonNode v1, JsonNode v2) {
  if (v1.isNull() || v2.isNull())
    return NullNode.instance;

  v1 = NodeUtils.number(v1, true, location);
  v2 = NodeUtils.number(v2, true, location);

  if (v1.isIntegralNumber() && v2.isIntegralNumber())
    return new LongNode(perform(v1.longValue(), v2.longValue()));
  else
    return new DoubleNode(perform(v1.doubleValue(), v2.doubleValue()));
}
 
源代码17 项目: graphql-spqr   文件: JacksonScalars.java
@Override
public Number serialize(Object dataFetcherResult) {
    if (dataFetcherResult instanceof DoubleNode) {
        return ((DoubleNode) dataFetcherResult).numberValue();
    } else {
        throw serializationException(dataFetcherResult, DoubleNode.class);
    }
}
 
源代码18 项目: graphql-spqr   文件: JacksonScalars.java
@Override
public DoubleNode parseValue(Object input) {
    if (input instanceof Number || input instanceof String) {
        return DoubleNode.valueOf(new BigDecimal(input.toString()).doubleValue());
    }
    if (input instanceof DoubleNode) {
        return (DoubleNode) input;
    }
    throw valueParsingException(input, Number.class, String.class, DoubleNode.class);
}
 
源代码19 项目: graphql-spqr   文件: JacksonScalars.java
@Override
public DoubleNode parseLiteral(Object input) {
    if (input instanceof IntValue) {
        return DoubleNode.valueOf(((IntValue) input).getValue().doubleValue());
    } if (input instanceof FloatValue) {
        return DoubleNode.valueOf(((FloatValue) input).getValue().doubleValue());
    } else {
        throw new CoercingParseLiteralException(errorMessage(input, IntValue.class, FloatValue.class));
    }
}
 
源代码20 项目: graphql-spqr   文件: JacksonScalars.java
private static Map<Type, GraphQLScalarType> getScalarMapping() {
    Map<Type, GraphQLScalarType> scalarMapping = new HashMap<>();
    scalarMapping.put(TextNode.class, JsonTextNode);
    scalarMapping.put(BooleanNode.class, JsonBooleanNode);
    scalarMapping.put(BinaryNode.class, JsonBinaryNode);
    scalarMapping.put(BigIntegerNode.class, JsonBigIntegerNode);
    scalarMapping.put(IntNode.class, JsonIntegerNode);
    scalarMapping.put(ShortNode.class, JsonShortNode);
    scalarMapping.put(DecimalNode.class, JsonDecimalNode);
    scalarMapping.put(FloatNode.class, JsonFloatNode);
    scalarMapping.put(DoubleNode.class, JsonDoubleNode);
    scalarMapping.put(NumericNode.class, JsonDecimalNode);
    return Collections.unmodifiableMap(scalarMapping);
}
 
源代码21 项目: graphql-spqr   文件: JsonTypeMappingTest.java
public JacksonContainer(ObjectNode obj, JsonNode any, BinaryNode binary, TextNode text, IntNode integer,
                        DoubleNode dbl, BigIntegerNode bigInt, ArrayNode array) {
    this.obj = obj;
    this.any = any;
    this.text = text;
    this.binary = binary;
    this.integer = integer;
    this.dbl = dbl;
    this.bigInt = bigInt;
    this.array = array;
}
 
源代码22 项目: rest-schemagen   文件: NumberJsonPropertyMapper.java
private JsonNode createNode(Object value) {
    if (value instanceof Float) {
        return new FloatNode((Float) value);
    } else if (value instanceof Double) {
        return new DoubleNode((Double) value);
    }
    return null;
}
 
private Example createExample(JsonNode node) {
    if (node instanceof ObjectNode) {
        ObjectExample obj = new ObjectExample();
        ObjectNode on = (ObjectNode) node;
        for (Iterator<Entry<String, JsonNode>> x = on.fields(); x.hasNext(); ) {
            Entry<String, JsonNode> i = x.next();
            String key = i.getKey();
            JsonNode value = i.getValue();
            obj.put(key, createExample(value));
        }
        return obj;
    } else if (node instanceof ArrayNode) {
        ArrayExample arr = new ArrayExample();
        ArrayNode an = (ArrayNode) node;
        for (JsonNode childNode : an) {
            arr.add(createExample(childNode));
        }
        return arr;
    } else if (node instanceof DoubleNode) {
        return new DoubleExample(node.doubleValue());
    } else if (node instanceof IntNode || node instanceof ShortNode) {
        return new IntegerExample(node.intValue());
    } else if (node instanceof FloatNode) {
        return new FloatExample(node.floatValue());
    } else if (node instanceof BigIntegerNode) {
        return new BigIntegerExample(node.bigIntegerValue());
    } else if (node instanceof DecimalNode) {
        return new DecimalExample(node.decimalValue());
    } else if (node instanceof LongNode) {
        return new LongExample(node.longValue());
    } else if (node instanceof BooleanNode) {
        return new BooleanExample(node.booleanValue());
    } else {
        return new StringExample(node.asText());
    }
}
 
源代码24 项目: james-project   文件: Serializer.java
@Override
public Optional<Float> deserialize(JsonNode json) {
    if (json instanceof FloatNode) {
        return Optional.of(json.floatValue());
    } else if (json instanceof DoubleNode) {
        return Optional.of(json.floatValue());
    } else {
        return Optional.empty();
    }
}
 
源代码25 项目: james-project   文件: Serializer.java
@Override
public Optional<Double> deserialize(JsonNode json) {
    if (json instanceof DoubleNode || json instanceof FloatNode) {
        return Optional.of(json.asDouble());
    } else {
        return Optional.empty();
    }
}
 
源代码26 项目: bce-sdk-java   文件: Datapoint.java
/**
 * Add datapoint of double type value.
 *
 * @param time datapoint's timestamp
 * @param value datapoint's value
 * @return Datapoint
 */
public Datapoint addDoubleValue(long time, double value) {
    initialValues();
    checkType(TsdbConstants.TYPE_DOUBLE);

    values.add(Lists.<JsonNode> newArrayList(new LongNode(time), new DoubleNode(value)));
    return this;
}
 
源代码27 项目: gitlab4j-api   文件: ApplicationSettings.java
private Object jsonNodeToValue(JsonNode node) {

        Object value = node;
        if (node instanceof NullNode) {
            value = null;
        } else if (node instanceof TextNode) {
            value = node.asText();
        } else if (node instanceof BooleanNode) {
            value = node.asBoolean();
        } else if (node instanceof IntNode) {
            value = node.asInt();
        } else if (node instanceof FloatNode) {
            value = (float)((FloatNode)node).asDouble();
        } else if (node instanceof DoubleNode) {
            value = (float)((DoubleNode)node).asDouble();
        } else if (node instanceof ArrayNode) {

            int numItems = node.size();
            String[] values = new String[numItems];
            for (int i = 0; i < numItems; i++) {
                values[i] = node.path(i).asText();
            }

            value = values;
        }

        return (value);
    }
 
源代码28 项目: onos   文件: UiExtensionManager.java
@Activate
public void activate() {
    Serializer serializer = Serializer.using(KryoNamespaces.API,
                 ObjectNode.class, ArrayNode.class,
                 JsonNodeFactory.class, LinkedHashMap.class,
                 TextNode.class, BooleanNode.class,
                 LongNode.class, DoubleNode.class, ShortNode.class,
                 IntNode.class, NullNode.class, UiSessionToken.class);

    prefsConsistentMap = storageService.<String, ObjectNode>consistentMapBuilder()
            .withName(ONOS_USER_PREFERENCES)
            .withSerializer(serializer)
            .withRelaxedReadConsistency()
            .build();
    prefsConsistentMap.addListener(prefsListener);
    prefs = prefsConsistentMap.asJavaMap();

    tokensConsistentMap = storageService.<UiSessionToken, String>consistentMapBuilder()
            .withName(ONOS_SESSION_TOKENS)
            .withSerializer(serializer)
            .withRelaxedReadConsistency()
            .build();
    tokens = tokensConsistentMap.asJavaMap();

    register(core);

    log.info("Started");
}
 
源代码29 项目: log-synth   文件: FieldSampler.java
protected static FieldSampler constant(final double v) {
    return new FieldSampler() {
        private DoubleNode sd = new DoubleNode(v);

        @Override
        public JsonNode sample() {
            return sd;
        }
    };
}
 
源代码30 项目: log-synth   文件: NormalSampler.java
@Override
public JsonNode sample() {
    double x;
    do {
        x = rand.nextDouble();
    } while (x < min || x > max);
    return new DoubleNode(x);
}
 
 类方法
 同包方法