Example usage for com.fasterxml.jackson.databind.node ObjectNode get

List of usage examples for com.fasterxml.jackson.databind.node ObjectNode get

Introduction

In this page you can find the example usage for com.fasterxml.jackson.databind.node ObjectNode get.

Prototype

public JsonNode get(String paramString) 

Source Link

Usage

From source file:org.glowroot.benchmark.ResultFormatter.java

public static void main(String[] args) throws IOException {
    File resultFile = new File(args[0]);

    Scores scores = new Scores();
    double baselineStartupTime = -1;
    double glowrootStartupTime = -1;

    ObjectMapper mapper = new ObjectMapper();
    String content = Files.toString(resultFile, Charsets.UTF_8);
    content = content.replaceAll("\n", " ");
    ArrayNode results = (ArrayNode) mapper.readTree(content);
    for (JsonNode result : results) {
        String benchmark = result.get("benchmark").asText();
        benchmark = benchmark.substring(0, benchmark.lastIndexOf('.'));
        ObjectNode primaryMetric = (ObjectNode) result.get("primaryMetric");
        double score = primaryMetric.get("score").asDouble();
        if (benchmark.equals(StartupBenchmark.class.getName())) {
            baselineStartupTime = score;
            continue;
        } else if (benchmark.equals(StartupWithGlowrootBenchmark.class.getName())) {
            glowrootStartupTime = score;
            continue;
        }/* w  w w .  j  a  v a 2s  .  c o  m*/
        ObjectNode scorePercentiles = (ObjectNode) primaryMetric.get("scorePercentiles");
        double score50 = scorePercentiles.get("50.0").asDouble();
        double score95 = scorePercentiles.get("95.0").asDouble();
        double score99 = scorePercentiles.get("99.0").asDouble();
        double score999 = scorePercentiles.get("99.9").asDouble();
        double score9999 = scorePercentiles.get("99.99").asDouble();
        double allocatedBytes = getAllocatedBytes(result);
        if (benchmark.equals(ServletBenchmark.class.getName())) {
            scores.baselineResponseTimeAvg = score;
            scores.baselineResponseTime50 = score50;
            scores.baselineResponseTime95 = score95;
            scores.baselineResponseTime99 = score99;
            scores.baselineResponseTime999 = score999;
            scores.baselineResponseTime9999 = score9999;
            scores.baselineAllocatedBytes = allocatedBytes;
        } else if (benchmark.equals(ServletWithGlowrootBenchmark.class.getName())) {
            scores.glowrootResponseTimeAvg = score;
            scores.glowrootResponseTime50 = score50;
            scores.glowrootResponseTime95 = score95;
            scores.glowrootResponseTime99 = score99;
            scores.glowrootResponseTime999 = score999;
            scores.glowrootResponseTime9999 = score9999;
            scores.glowrootAllocatedBytes = allocatedBytes;
        } else {
            throw new AssertionError(benchmark);
        }
    }
    System.out.println();
    printScores(scores);
    if (baselineStartupTime != -1) {
        System.out.println("STARTUP");
        System.out.format("%25s%14s%14s%n", "", "baseline", "glowroot");
        printLine("Startup time (avg)", "ms", baselineStartupTime, glowrootStartupTime);
    }
    System.out.println();
}

From source file:com.redhat.lightblue.query.ComparisonExpression.java

/**
 * Parses a relational expression or an array comparison expression from the
 * given json object/*  w w w  . j  ava  2  s. c om*/
 */
public static ComparisonExpression fromJson(ObjectNode node) {
    JsonNode x = node.get("field");
    if (x != null) {
        return RelationalExpression.fromJson(node);
    } else {
        return ArrayComparisonExpression.fromJson(node);
    }
}

From source file:com.collective.celos.RerunState.java

public static RerunState fromJSONNode(ObjectNode node) {
    String timeStr = node.get(RERUN_TIME_PROP).textValue();
    return new RerunState(new ScheduledTime(timeStr));
}

From source file:com.redhat.lightblue.query.ArrayComparisonExpression.java

/**
 * Parses an array contains or array match expression from the given object
 * node//from   w  w  w . j a  va  2  s .c om
 */
public static ArrayComparisonExpression fromJson(ObjectNode node) {
    JsonNode x = node.get("contains");
    if (x != null) {
        return ArrayContainsExpression.fromJson(node);
    } else {
        x = node.get("elemMatch");
        if (x != null) {
            return ArrayMatchExpression.fromJson(node);
        }
    }
    throw Error.get(QueryConstants.ERR_INVALID_ARRAY_COMPARISON_EXPRESSION, node.toString());
}

From source file:com.redhat.lightblue.query.RelationalExpression.java

/**
 * Parses a relational expression using the given object node
 *//*from  w  ww . j  av a2 s  . com*/
public static RelationalExpression fromJson(ObjectNode node) {
    JsonNode x = node.get("regex");
    if (x != null) {
        return RegexMatchExpression.fromJson(node);
    } else {
        x = node.get("op");
        if (x != null) {
            String op = x.asText();
            if (BinaryComparisonOperator.fromString(op) != null) {
                return BinaryRelationalExpression.fromJson(node);
            } else if (NaryRelationalOperator.fromString(op) != null) {
                return NaryRelationalExpression.fromJson(node);
            }
        }
    }
    throw Error.get(QueryConstants.ERR_INVALID_COMPARISON_EXPRESSION, node.toString());
}

From source file:org.apache.streams.jackson.CleanAdditionalPropertiesProcessor.java

public static void cleanAdditionalProperties(ObjectNode node) {
    if (node.get("additionalProperties") != null) {
        ObjectNode additionalProperties = (ObjectNode) node.get("additionalProperties");
        cleanAdditionalProperties(additionalProperties);
        Iterator<Map.Entry<String, JsonNode>> jsonNodeIterator = additionalProperties.fields();
        while (jsonNodeIterator.hasNext()) {
            Map.Entry<String, JsonNode> entry = jsonNodeIterator.next();
            node.put(entry.getKey(), entry.getValue());
        }/*from w w  w. ja va  2s .  co m*/
    }
}

From source file:com.redhat.lightblue.query.ArrayMatchExpression.java

/**
 * Parses an array match expression from the given json object
 *///from  ww w  .  j ava2s  . c o  m
public static ArrayMatchExpression fromJson(ObjectNode node) {
    JsonNode x = node.get("array");
    if (x != null) {
        Path field = new Path(x.asText());
        x = node.get("elemMatch");
        if (x != null) {
            return new ArrayMatchExpression(field, QueryExpression.fromJson(x));
        }
    }
    throw Error.get(QueryConstants.ERR_INVALID_ARRAY_COMPARISON_EXPRESSION, node.toString());
}

From source file:io.fabric8.collector.elasticsearch.JsonNodes.java

/**
 * Creates nested objects if they don't exist on the given paths.
 *
 * @returns the last object or null if it could not be created
 *//*from   ww  w.j a  va  2s  .c o  m*/
public static ObjectNode setObjects(JsonNode node, String... paths) {
    JsonNodeFactory nodeFactory = JsonNodeFactory.instance;
    JsonNode iter = node;
    for (String path : paths) {
        if (!iter.isObject()) {
            return null;
        }
        ObjectNode object = (ObjectNode) iter;
        iter = object.get(path);
        if (iter == null || !iter.isObject()) {
            iter = nodeFactory.objectNode();
            object.set(path, iter);
        }
    }
    return (ObjectNode) iter;
}

From source file:com.redhat.lightblue.query.NaryRelationalExpression.java

/**
 * Parses an n-ary relational expression from the given json object
 *//*from  ww w.j a v a 2 s  . c  om*/
public static NaryRelationalExpression fromJson(ObjectNode node) {
    if (node.size() == 3) {
        if (node.get("rfield") != null) {
            return NaryFieldRelationalExpression.fromJson(node);
        } else if (node.get("values") != null) {
            return NaryValueRelationalExpression.fromJson(node);
        }
    }
    throw Error.get(QueryConstants.ERR_INVALID_COMPARISON_EXPRESSION, node.toString());
}

From source file:com.redhat.lightblue.query.BinaryRelationalExpression.java

/**
 * Parses a field comparison or value comparison expression from the given
 * json object//  w  ww . ja  va  2 s  .c  o m
 */
public static BinaryRelationalExpression fromJson(ObjectNode node) {
    if (node.size() == 3) {
        JsonNode x = node.get("op");
        if (x != null) {
            BinaryComparisonOperator op = BinaryComparisonOperator.fromString(x.asText());
            if (op != null) {
                x = node.get("field");
                if (x != null) {
                    Path field = new Path(x.asText());
                    x = node.get("rfield");
                    if (x != null) {
                        return new FieldComparisonExpression(field, op, new Path(x.asText()));
                    } else {
                        x = node.get("rvalue");
                        if (x != null) {
                            return new ValueComparisonExpression(field, op, Value.fromJson(x));
                        }
                    }
                }
            }
        }
    }
    throw Error.get(QueryConstants.ERR_INVALID_COMPARISON_EXPRESSION, node.toString());
}