Search in sources :

Example 41 with TextNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.TextNode in project symja_android_library by axkr.

the class ExpressionJSONConvert method importExpressionJSONRecursive.

public static IExpr importExpressionJSONRecursive(JsonNode node) {
    if (node instanceof ArrayNode) {
        ArrayNode arrayNode = (ArrayNode) node;
        Iterator<JsonNode> iter = arrayNode.elements();
        IASTAppendable ast;
        if (iter.hasNext()) {
            JsonNode next = iter.next();
            IExpr temp = importExpressionJSONRecursive(next);
            if (temp.isPresent()) {
                ast = F.ast(temp, arrayNode.size() - 1);
                while (iter.hasNext()) {
                    next = iter.next();
                    temp = importExpressionJSONRecursive(next);
                    if (temp.isPresent()) {
                        ast.append(temp);
                    }
                }
                return ast;
            }
        }
        return F.NIL;
    } else if (node instanceof ObjectNode) {
        IASTAppendable list = F.ListAlloc();
        ObjectNode objectNode = (ObjectNode) node;
        Iterator<Entry<String, JsonNode>> iter = objectNode.fields();
        while (iter.hasNext()) {
            Entry<String, JsonNode> next = iter.next();
            IExpr temp = importExpressionJSONRecursive(next.getValue());
            if (temp.isPresent()) {
                list.append(F.Rule(F.$str(next.getKey()), temp));
            }
        }
        return list;
    } else if (node instanceof ValueNode) {
        ValueNode valueNode = (ValueNode) node;
        if (valueNode instanceof NumericNode) {
            if (valueNode instanceof DoubleNode) {
                return F.num(valueNode.doubleValue());
            } else if (valueNode instanceof FloatNode) {
                return F.num(valueNode.doubleValue());
            } else if (valueNode instanceof IntNode) {
                return F.ZZ(valueNode.intValue());
            } else if (valueNode instanceof LongNode) {
                return F.ZZ(valueNode.longValue());
            } else if (valueNode instanceof ShortNode) {
                return F.ZZ(valueNode.intValue());
            } else if (valueNode instanceof BigIntegerNode) {
                return F.ZZ(valueNode.bigIntegerValue());
            } else if (valueNode instanceof DecimalNode) {
                return F.num(new Apfloat(valueNode.decimalValue()));
            }
        }
        if (valueNode instanceof BooleanNode) {
            return valueNode.booleanValue() ? S.True : S.False;
        } else if (valueNode instanceof NullNode) {
            return S.Null;
        } else if (valueNode instanceof TextNode) {
            String symbolName = valueNode.textValue();
            if (symbolName.length() > 1 && symbolName.charAt(0) == '\'' && symbolName.charAt(symbolName.length() - 1) == '\'') {
                return F.$str(symbolName.substring(1, symbolName.length() - 1));
            }
            if (Scanner.isIdentifier(symbolName)) {
                return F.symbol(symbolName);
            }
            return F.$str(symbolName);
        }
        return F.$str(valueNode.toString());
    }
    return F.NIL;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) FloatNode(com.fasterxml.jackson.databind.node.FloatNode) DoubleNode(com.fasterxml.jackson.databind.node.DoubleNode) JsonNode(com.fasterxml.jackson.databind.JsonNode) BigIntegerNode(com.fasterxml.jackson.databind.node.BigIntegerNode) TextNode(com.fasterxml.jackson.databind.node.TextNode) NumericNode(com.fasterxml.jackson.databind.node.NumericNode) LongNode(com.fasterxml.jackson.databind.node.LongNode) BooleanNode(com.fasterxml.jackson.databind.node.BooleanNode) Apfloat(org.apfloat.Apfloat) ShortNode(com.fasterxml.jackson.databind.node.ShortNode) Entry(java.util.Map.Entry) IntNode(com.fasterxml.jackson.databind.node.IntNode) IASTAppendable(org.matheclipse.core.interfaces.IASTAppendable) Iterator(java.util.Iterator) ValueNode(com.fasterxml.jackson.databind.node.ValueNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) IExpr(org.matheclipse.core.interfaces.IExpr) DecimalNode(com.fasterxml.jackson.databind.node.DecimalNode) NullNode(com.fasterxml.jackson.databind.node.NullNode)

Example 42 with TextNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.TextNode in project symja_android_library by axkr.

the class JSONConvert method importJSONRecursive.

public static IExpr importJSONRecursive(JsonNode node) {
    if (node instanceof ArrayNode) {
        ArrayNode arrayNode = (ArrayNode) node;
        Iterator<JsonNode> iter = arrayNode.elements();
        IASTAppendable list = F.ListAlloc(arrayNode.size());
        while (iter.hasNext()) {
            JsonNode next = iter.next();
            IExpr temp = importJSONRecursive(next);
            if (temp.isPresent()) {
                list.append(temp);
            }
        }
        return list;
    } else if (node instanceof ObjectNode) {
        IASTAppendable list = F.ListAlloc();
        ObjectNode objectNode = (ObjectNode) node;
        Iterator<Entry<String, JsonNode>> iter = objectNode.fields();
        while (iter.hasNext()) {
            Entry<String, JsonNode> next = iter.next();
            IExpr temp = importJSONRecursive(next.getValue());
            if (temp.isPresent()) {
                list.append(F.Rule(F.$str(next.getKey()), temp));
            }
        }
        return list;
    } else if (node instanceof ValueNode) {
        ValueNode valueNode = (ValueNode) node;
        if (valueNode instanceof NumericNode) {
            if (valueNode instanceof DoubleNode) {
                return F.num(valueNode.doubleValue());
            } else if (valueNode instanceof FloatNode) {
                return F.num(valueNode.doubleValue());
            } else if (valueNode instanceof IntNode) {
                return F.ZZ(valueNode.intValue());
            } else if (valueNode instanceof LongNode) {
                return F.ZZ(valueNode.longValue());
            } else if (valueNode instanceof ShortNode) {
                return F.ZZ(valueNode.intValue());
            } else if (valueNode instanceof BigIntegerNode) {
                return F.ZZ(valueNode.bigIntegerValue());
            } else if (valueNode instanceof DecimalNode) {
                return F.num(new Apfloat(valueNode.decimalValue()));
            }
        }
        if (valueNode instanceof BooleanNode) {
            return valueNode.booleanValue() ? S.True : S.False;
        } else if (valueNode instanceof NullNode) {
            return S.Null;
        } else if (valueNode instanceof TextNode) {
            return F.$str(valueNode.textValue());
        }
        return F.$str(valueNode.toString());
    }
    return F.NIL;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) FloatNode(com.fasterxml.jackson.databind.node.FloatNode) DoubleNode(com.fasterxml.jackson.databind.node.DoubleNode) JsonNode(com.fasterxml.jackson.databind.JsonNode) BigIntegerNode(com.fasterxml.jackson.databind.node.BigIntegerNode) TextNode(com.fasterxml.jackson.databind.node.TextNode) NumericNode(com.fasterxml.jackson.databind.node.NumericNode) LongNode(com.fasterxml.jackson.databind.node.LongNode) BooleanNode(com.fasterxml.jackson.databind.node.BooleanNode) Apfloat(org.apfloat.Apfloat) ShortNode(com.fasterxml.jackson.databind.node.ShortNode) Entry(java.util.Map.Entry) IntNode(com.fasterxml.jackson.databind.node.IntNode) IASTAppendable(org.matheclipse.core.interfaces.IASTAppendable) Iterator(java.util.Iterator) ValueNode(com.fasterxml.jackson.databind.node.ValueNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) IExpr(org.matheclipse.core.interfaces.IExpr) DecimalNode(com.fasterxml.jackson.databind.node.DecimalNode) NullNode(com.fasterxml.jackson.databind.node.NullNode)

Example 43 with TextNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.TextNode in project XRTB by benmfaul.

the class BidRequest method setup.

/**
 * Sets up the database of values of the JSON, from the mapped keys in the
 * campaigns. THis traverses the JSON once, and stores the required values
 * needed by campaigns once.
 *
 * @throws Exception
 *             on JSON processing errors.
 */
protected void setup() throws Exception {
    id = rootNode.path("id").textValue();
    if (id == null) {
        throw new Exception("Required field 'id' is missing or wrong type");
    }
    IntNode in = null;
    Object test = null;
    // a fast way to keep up
    StringBuilder item = new StringBuilder("id");
    // Im looking for
    try {
        for (int i = 0; i < keys.size(); i++) {
            String key = keys.get(i);
            List list = mapp.get(key);
            if (list.size() != 0)
                compileList(key, list);
        }
        // ////////////////////////////////////////////////////////////////////
        if ((test = getNode("site.id")) != null)
            siteId = ((TextNode) test).textValue();
        else {
            test = getNode("app.id");
            if (test != null) {
                siteId = ((TextNode) test).textValue();
            }
        }
        if ((test = getNode("site.domain")) != null)
            siteDomain = ((TextNode) test).textValue();
        else {
            test = getNode("app.domain");
            if (test != null) {
                siteDomain = ((TextNode) test).textValue();
            }
        }
        // ///////////////
        if (siteDomain != null && blackList != null) {
            if (blackList.contains(siteDomain)) {
                blackListed = true;
                return;
            }
        }
        if ((test = getNode("site.name")) != null)
            siteName = ((TextNode) test).textValue();
        else {
            test = getNode("app.name");
            if (test != null) {
                siteName = ((TextNode) test).textValue();
            }
        }
        // //////////////// Fill in pageurl info ////////////////
        if ((test = getNode("site.content.url")) != null) {
            pageurl = ((TextNode) test).textValue();
        } else if ((test = getNode("site.page")) != null) {
            pageurl = ((TextNode) test).textValue();
        } else {
            test = getNode("app.content.url");
            if (test != null) {
                pageurl = ((TextNode) test).textValue();
            }
        }
        if ((test = database.get("device.geo.lat")) != null && test instanceof MissingNode == false) {
            try {
                lat = getDoubleFrom(test);
                test = database.get("device.geo.lon");
                if (test != null)
                    lon = getDoubleFrom(test);
            } catch (Exception error) {
            }
        }
        // ////////////////////////////////////////////////////////////////
        // 
        // Handle the impressions
        // 
        ArrayNode imps = (ArrayNode) rootNode.get("imp");
        impressions = new ArrayList();
        for (int i = 0; i < imps.size(); i++) {
            JsonNode obj = imps.get(i);
            Impression imp = new Impression(rootNode, obj);
            impressions.add(imp);
        }
        handleRtb4FreeExtensions();
    } catch (Exception error) {
        // This is an error in the protocol
        error.printStackTrace();
        if (Configuration.isInitialized() == false)
            return;
        // error.printStackTrace();
        // String str = rootNode.toString();
        // System.out.println(str);
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        error.printStackTrace(pw);
        String str = sw.toString();
        String[] lines = str.split("\n");
        StringBuilder sb = new StringBuilder();
        sb.append("Abmormal processing of bid ");
        sb.append(id);
        sb.append(", ");
        if (lines.length > 0)
            sb.append(lines[0]);
        if (lines.length > 1)
            sb.append(lines[1]);
        logger.debug("BidRequest:setup():error: {}", sb.toString());
    }
}
Also used : ArrayList(java.util.ArrayList) TextNode(com.fasterxml.jackson.databind.node.TextNode) MissingNode(com.fasterxml.jackson.databind.node.MissingNode) JsonNode(com.fasterxml.jackson.databind.JsonNode) IntNode(com.fasterxml.jackson.databind.node.IntNode) StringWriter(java.io.StringWriter) ArrayList(java.util.ArrayList) List(java.util.List) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) PrintWriter(java.io.PrintWriter)

Example 44 with TextNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.TextNode in project XRTB by benmfaul.

the class Node method traverse.

/**
 * Traverse an ArrayNode and convert to ArrayList
 *
 * @param n.
 *            A Jackson ArrayNode.
 * @return List. The list that corresponds to the Jackson ArrayNode.
 */
List traverse(ArrayNode n) {
    List list = new ArrayList();
    for (int i = 0; i < n.size(); i++) {
        Object obj = n.get(i);
        if (obj instanceof IntNode) {
            IntNode d = (IntNode) obj;
            list.add(d.numberValue());
        } else if (obj instanceof DoubleNode) {
            DoubleNode d = (DoubleNode) obj;
            list.add(d.numberValue());
        } else if (obj instanceof ArrayNode) {
            ArrayNode nodes = (ArrayNode) obj;
            for (int k = 0; i < nodes.size(); i++) {
                list.add(nodes.get(k));
            }
        } else if (obj instanceof TextNode) {
            TextNode t = (TextNode) obj;
            list.add(t.textValue());
        } else {
            list.add(obj);
        }
    }
    return list;
}
Also used : IntNode(com.fasterxml.jackson.databind.node.IntNode) ArrayList(java.util.ArrayList) DoubleNode(com.fasterxml.jackson.databind.node.DoubleNode) ArrayList(java.util.ArrayList) List(java.util.List) TextNode(com.fasterxml.jackson.databind.node.TextNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Example 45 with TextNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.TextNode in project XRTB by benmfaul.

the class ANode method traverse.

/**
 * Traverse an ArrayNode and convert to ArrayList
 *
 * @param n. A Jackson ArrayNode.
 * @return List. The list that corresponds to the Jackson ArrayNode.
 */
List traverse(ArrayNode n) {
    List list = new ArrayList();
    for (int i = 0; i < n.size(); i++) {
        Object obj = n.get(i);
        if (obj instanceof IntNode) {
            IntNode d = (IntNode) obj;
            list.add(d.numberValue());
        } else if (obj instanceof DoubleNode) {
            DoubleNode d = (DoubleNode) obj;
            list.add(d.numberValue());
        } else {
            TextNode t = (TextNode) obj;
            list.add(t.textValue());
        }
    }
    return list;
}
Also used : IntNode(com.fasterxml.jackson.databind.node.IntNode) ArrayList(java.util.ArrayList) DoubleNode(com.fasterxml.jackson.databind.node.DoubleNode) ArrayList(java.util.ArrayList) List(java.util.List) TextNode(com.fasterxml.jackson.databind.node.TextNode)

Aggregations

TextNode (com.fasterxml.jackson.databind.node.TextNode)96 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)35 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)29 JsonNode (com.fasterxml.jackson.databind.JsonNode)28 Test (org.junit.Test)16 Test (org.junit.jupiter.api.Test)15 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)14 IntNode (com.fasterxml.jackson.databind.node.IntNode)14 MockScheduler (org.apache.kafka.common.utils.MockScheduler)14 MockTime (org.apache.kafka.common.utils.MockTime)14 ExpectedTaskBuilder (org.apache.kafka.trogdor.common.ExpectedTasks.ExpectedTaskBuilder)14 ExpectedTasks (org.apache.kafka.trogdor.common.ExpectedTasks)13 WorkerRunning (org.apache.kafka.trogdor.rest.WorkerRunning)12 NoOpTaskSpec (org.apache.kafka.trogdor.task.NoOpTaskSpec)11 ArrayList (java.util.ArrayList)9 Scheduler (org.apache.kafka.common.utils.Scheduler)9 MiniTrogdorCluster (org.apache.kafka.trogdor.common.MiniTrogdorCluster)9 CreateTaskRequest (org.apache.kafka.trogdor.rest.CreateTaskRequest)9 TaskRunning (org.apache.kafka.trogdor.rest.TaskRunning)9 DoubleNode (com.fasterxml.jackson.databind.node.DoubleNode)8