Search in sources :

Example 1 with LabelToNodeMap

use of org.apache.jena.sparql.util.LabelToNodeMap in project jena by apache.

the class E_BNode method evalSpecial.

// Not really a special form but we need access to 
// the binding to use a key.
@Override
public NodeValue evalSpecial(Binding binding, FunctionEnv env) {
    Expr expr = null;
    if (args.size() == 1)
        expr = getArg(1);
    if (expr == null)
        return NodeValue.makeNode(NodeFactory.createBlankNode());
    NodeValue x = expr.eval(binding, env);
    if (!x.isString())
        throw new ExprEvalException("Not a string: " + x);
    Integer key = System.identityHashCode(binding);
    // IdentityHashMap
    // Normally bindings have structural equality (e.g. DISTINCT)
    // we want identify as OpAssign/OpExtend mutates a binding to add new pairs.
    @SuppressWarnings("unchecked") IdentityHashMap<Binding, LabelToNodeMap> mapping = (IdentityHashMap<Binding, LabelToNodeMap>) env.getContext().get(keyMap);
    if (mapping == null) {
        mapping = new IdentityHashMap<>();
        env.getContext().set(keyMap, mapping);
    }
    LabelToNodeMap mapper = mapping.get(binding);
    if (mapper == null) {
        mapper = LabelToNodeMap.createBNodeMap();
        mapping.put(binding, mapper);
    }
    Node bnode = mapper.asNode(x.getString());
    return NodeValue.makeNode(bnode);
}
Also used : Binding(org.apache.jena.sparql.engine.binding.Binding) IdentityHashMap(java.util.IdentityHashMap) LabelToNodeMap(org.apache.jena.sparql.util.LabelToNodeMap) Node(org.apache.jena.graph.Node)

Aggregations

IdentityHashMap (java.util.IdentityHashMap)1 Node (org.apache.jena.graph.Node)1 Binding (org.apache.jena.sparql.engine.binding.Binding)1 LabelToNodeMap (org.apache.jena.sparql.util.LabelToNodeMap)1