public static Iterator<Relation> getAllAggregationRelations(ContextNode contextNode) { return new SelectingIterator<Relation> (contextNode.getAllRelations()) { @Override public boolean select(Relation relation) { return relation.getXDIAddress().equals(XDIDictionaryConstants.XDI_ADD_HAS); } }; } }
public static Iterator<Relation> getAllReplacementRelations(ContextNode contextNode) { return new SelectingIterator<Relation> (contextNode.getAllRelations()) { @Override public boolean select(Relation relation) { return relation.getXDIAddress().equals(XDIDictionaryConstants.XDI_ADD_REP); } }; }
public static Iterator<Relation> getAllReferenceAndReplacementRelations(ContextNode contextNode) { return new SelectingIterator<Relation> (contextNode.getAllRelations()) { @Override public boolean select(Relation relation) { return relation.getXDIAddress().equals(XDIDictionaryConstants.XDI_ADD_REF) || relation.getXDIAddress().equals(XDIDictionaryConstants.XDI_ADD_REP); } }; } }
@Override public Iterator<Relation> descend(ContextNode contextNode) { return contextNode.getAllRelations(); } };
public static Iterator<Relation> getAllIdentityRelations(ContextNode contextNode) { return new SelectingIterator<Relation> (contextNode.getAllRelations()) { @Override public boolean select(Relation relation) { return relation.getXDIAddress().equals(XDIDictionaryConstants.XDI_ADD_IS); } }; }
public static Iterator<Relation> getAllReferenceRelations(ContextNode contextNode) { return new SelectingIterator<Relation> (contextNode.getAllRelations()) { @Override public boolean select(Relation relation) { return relation.getXDIAddress().equals(XDIDictionaryConstants.XDI_ADD_REF); } }; }
@Override /* * TODO: This is inefficient for a large number of context nodes in the graph. */ public ReadOnlyIterator<Relation> getIncomingRelations() { return new SelectingIterator<Relation> (this.getGraph().getRootContextNode(true).getAllRelations()) { @Override public boolean select(Relation relation) { return relation.follow().equals(AbstractContextNode.this); } }; }
@Override public synchronized void delContextNodes() { // delete all relations and incoming relations for (ContextNode contextNode : this.getContextNodes()) { for (Relation relation : contextNode.getAllRelations()) relation.delete(); for (Relation relation : contextNode.getAllIncomingRelations()) relation.delete(); } // delete context nodes this.contextNodes.clear(); }
@Override public synchronized void delContextNodes() { // delete all relations and incoming relations for (ContextNode contextNode : this.getContextNodes()) { for (Relation relation : contextNode.getAllRelations()) relation.delete(); for (Relation relation : contextNode.getAllIncomingRelations()) relation.delete(); } // delete context nodes String contextNodesKey = this.getContextNodesKey(); this.keyValueStore.delete(contextNodesKey); }
list.add(new MappingRelationStatementIterator(orderedGraph.getRootContextNode(true).getAllRelations())); list.add(new MappingLiteralNodeStatementIterator(orderedGraph.getRootContextNode(true).getAllLiteralNodes()));
list.add(new MappingRelationStatementIterator(orderedGraph.getRootContextNode(true).getAllRelations())); list.add(new MappingLiteralNodeStatementIterator(orderedGraph.getRootContextNode(true).getAllLiteralNodes()));
list.add(new MappingRelationStatementIterator(orderedGraph.getRootContextNode(true).getAllRelations())); list.add(new MappingLiteralNodeStatementIterator(orderedGraph.getRootContextNode(true).getAllLiteralNodes()));
list.add(new MappingRelationStatementIterator(orderedGraph.getRootContextNode(true).getAllRelations())); list.add(new MappingLiteralNodeStatementIterator(orderedGraph.getRootContextNode(true).getAllLiteralNodes()));
private void writeInternal(Graph graph, JsonObject jsonObject) throws IOException { // write ordered? Graph orderedGraph = null; IterableIterator<Statement> statements; if (this.isWriteOrdered()) { MemoryGraphFactory memoryGraphFactory = new MemoryGraphFactory(); memoryGraphFactory.setSortmode(MemoryGraphFactory.SORTMODE_ALPHA); orderedGraph = memoryGraphFactory.openGraph(); CopyUtil.copyGraph(graph, orderedGraph, null); List<Iterator<? extends Statement>> list = new ArrayList<Iterator<? extends Statement>> (); list.add(new MappingContextNodeStatementIterator(orderedGraph.getRootContextNode(true).getAllContextNodes())); list.add(new MappingRelationStatementIterator(orderedGraph.getRootContextNode(true).getAllRelations())); list.add(new MappingLiteralNodeStatementIterator(orderedGraph.getRootContextNode(true).getAllLiteralNodes())); statements = new CompositeIterator<Statement> (list.iterator()); } else { statements = graph.getRootContextNode(true).getAllStatements(); } // ignore implied statements if (! this.isWriteImplied()) statements = new SelectingNotImpliedStatementIterator(statements); // write the statements for (Statement statement : statements) { XDIStatement XDIstatement = statement.getXDIStatement(); // put the statement into the JSON object this.putStatementIntoJsonObject(XDIstatement, jsonObject); } // done if (orderedGraph != null) orderedGraph.close(); }
private static boolean includeContextNode(ContextNode contextNode) { if (! contextNode.getStatement().isImplied()) return true; if (XdiInnerRoot.fromContextNode(contextNode) != null) return false; for (Relation relation : contextNode.getAllRelations()) { XdiInnerRoot xdiInnerRoot = XdiInnerRoot.fromRelation(relation); if (xdiInnerRoot != null && xdiInnerRoot.getSubjectContextNode() == relation.getContextNode() && xdiInnerRoot.getPredicateRelation() == relation) { if (! allStatementsImplied(xdiInnerRoot.getContextNode())) return true; } } if (! allStatementsImplied(contextNode)) return true; //if (contextNode.getAllLiterals().hasNext()) return true; //if (contextNode.getAllRelations().hasNext()) return true; /* if (contextNode.isEmpty() && contextNode.containsIncomingRelations()) return false; if (XdiInnerRoot.isValid(contextNode)) return false;*/ return false; /* if (contextNode.containsLiteralNode()) return true; if (contextNode.containsRelations()) return true; if (contextNode.containsIncomingRelations()) return false; for (ContextNode childContextNode : contextNode.getContextNodes()) { if (includeContextNode(childContextNode)) return true; } if (contextNode.containsContextNodes()) return false; return false;*/ }
try { markus.getRelations().next(); fail(); } catch (NoSuchElementException ex) { } try { markus.getIncomingRelations().next(); fail(); } catch (NoSuchElementException ex) { } assertFalse(markus.getAllRelations().hasNext()); try { markus.getAllRelations().next(); fail(); } catch (NoSuchElementException ex) { } assertEquals(markus.getRelationCount(XDIAddress.create("+not")), 0); assertEquals(markus.getRelationCount(), 0);
assertEquals(root.getRelationCount(), 0); assertFalse(root.getAllContextNodes().hasNext()); assertFalse(root.getAllRelations().hasNext()); assertFalse(root.getAllLiteralNodes().hasNext()); assertEquals(root.getRelationCount(), 1); assertTrue(root.getAllContextNodes().hasNext()); assertTrue(root.getAllRelations().hasNext()); assertTrue(root.getAllLiteralNodes().hasNext()); assertEquals(root.getRelationCount(), 1); assertTrue(root.getAllContextNodes().hasNext()); assertTrue(root.getAllRelations().hasNext()); assertTrue(root.getAllLiteralNodes().hasNext()); assertEquals(root.getRelationCount(), 0); assertFalse(root.getAllContextNodes().hasNext()); assertFalse(root.getAllRelations().hasNext()); assertFalse(root.getAllLiteralNodes().hasNext());