public static NodeId create(byte[] b) { return create(b, 0) ; } public static NodeId create(ByteBuffer b) { return create(b, 0) ; }
public static NodeId create(long value) { // All creation of NodeIds must go through this. if ( value == NodeDoesNotExist.value ) return NodeDoesNotExist ; if ( value == NodeIdAny.value ) return NodeIdAny ; return new NodeId(value) ; }
@Override public boolean test(Tuple<NodeId> item) { // Check on pattern and item (both in natural order) for ( int i = 0 ; i < tupleLength ; i++ ) { NodeId n = pattern.get(i) ; // The pattern must be null/Any or match the tuple being tested. if ( ! NodeId.isAny(n) ) if ( ! item.get(i).equals(n) ) return false ; } return true ; } } ;
public final boolean isConcrete() { return !isAny(this) && !isDoesNotExist(this) ; }
private void test(String x, Node correct) { Node n = NodeFactoryExtra.parseNode(x) ; NodeId nodeId = NodeId.inline(n) ; boolean b = NodeId.hasInlineDatatype(n) ; if ( nodeId != null ) assertTrue("Converted NodeId but datatype test was false", b) ; if ( correct == null ) { assertNull("Expected no encoding: got: "+nodeId, nodeId) ; return ; } assertNotNull("Expected inlining: "+n, nodeId) ; Node n2 = NodeId.extract(nodeId) ; assertNotNull("Expected recovery", n2) ; String s = "("+correct.getLiteralLexicalForm()+","+n2.getLiteralLexicalForm()+")" ; assertTrue("Not same value: "+s, correct.sameValueAs(n2)) ; // Term equality. assertEquals("Not same term", correct, n2) ; } }
@Override public boolean containsNode(Node node) { NodeId x = getNodeIdForNode(node) ; return NodeId.isDoesNotExist(x) ; }
return new NodeId(dn.pack()) ; else return null ; return new NodeId(v) ; else return null ; if ( v == -1 ) return null; v = setType(v, DATETIME); return new NodeId(v); if ( v == -1 ) return null; v = setType(v, DATE); return new NodeId(v); boolean b = (Boolean)lit.getValue(); v = setType(v, BOOLEAN); if ( b ) v = v | 0x01; return new NodeId(v);
private static boolean reject(BindingNodeId output , Var var, NodeId value) { if ( ! output.containsKey(var) ) return false ; if ( output.get(var).equals(value) ) return false ; return true ; }
if ( NodeId.isAny(X) ) { X = null; if ( leading ) { leadingIdx = i; Bytes.setLong(X.getId(), minRec.getKey(), i * SizeOfNodeId); Bytes.setLong(X.getId(), maxRec.getKey(), i * SizeOfNodeId); Bytes.setLong(X.getId() + 1, maxRec.getKey(), leadingIdx * SizeOfNodeId); iter = index.iterator(minRec, maxRec);
@Override public final NodeId getAllocateNodeId(Node node) { NodeId nid = NodeId.inline(node) ; if ( nid != null ) return nid ; return super.getAllocateNodeId(node) ; }
@Override public final Node getNodeForNodeId(NodeId id) { Node n = NodeId.extract(id) ; if ( n != null ) return n ; return super.getNodeForNodeId(id) ; }
/** Encode a node as an inline literal. Return null if it can't be done */ public static NodeId inline(Node node) { if ( node == null ) { Log.warn(NodeId.class, "Null node: " + node); return null; } if ( !enableInlineLiterals ) return null; if ( !node.isLiteral() ) return null; if ( NodeUtils.isSimpleString(node) || NodeUtils.isLangString(node) ) return null; try { return inline$(node) ; } catch (Throwable th) { Log.warn(NodeId.class, "Failed to process "+node) ; return null ; } }
private void test(String x, Node correct) { Node n = NodeFactoryExtra.parseNode(x) ; NodeId nodeId = NodeId.inline(n) ; boolean b = NodeId.hasInlineDatatype(n) ; if ( nodeId != null ) assertTrue("Converted NodeId but datatype test was false", b) ; if ( correct == null ) { assertNull("Expected no encoding: got: "+nodeId, nodeId) ; return ; } assertNotNull("Expected inlining: "+n, nodeId) ; Node n2 = NodeId.extract(nodeId) ; assertNotNull("Expected recovery", n2) ; String s = "("+correct.getLiteralLexicalForm()+","+n2.getLiteralLexicalForm()+")" ; assertTrue("Not same value: "+s, correct.sameValueAs(n2)) ; // Term equality. assertEquals("Not same term", correct, n2) ; } }
@Override public boolean containsNode(Node node) { NodeId x = getNodeIdForNode(node) ; return NodeId.isDoesNotExist(x) ; }
private Node _retrieveNodeByNodeId(NodeId id) { if ( NodeId.isDoesNotExist(id) ) return null ; if ( NodeId.isAny(id) ) return null ; Node n = readNodeFromTable(id) ; return n ; }
public static void dumpNodeTable(NodeTable nodeTable, Set<NodeTable> dumpedNodeTables) { if ( dumpedNodeTables.contains(nodeTable) ) return ; Iterator<Pair<NodeId, Node>> iter = nodeTable.all() ; for ( ; iter.hasNext() ; ) { Pair<NodeId, Node> pair = iter.next() ; NodeId nid = pair.car() ; Node n = pair.cdr(); String x = NodeFmtLib.displayStr(n) ; System.out.printf("%016X %s\n", nid.getId(), x) ; } dumpedNodeTables.add(nodeTable) ; }