@Test public void replaceWith() { Graph initialGraph = new SimpleGraph(); BlankNode bNode1 = new BlankNode(); BlankNode bNode2 = new BlankNode(); BlankNode newBnode = new BlankNode(); IRI property1 = new IRI("http: IRI property2 = new IRI("http: IRI newIRI = new IRI("http: Literal literal1 = new PlainLiteralImpl("literal"); Literal literal2 = new PlainLiteralImpl("bla bla"); Triple triple1 = new TripleImpl(bNode1, property1, literal1); Triple triple2 = new TripleImpl(bNode1, property2, property1); Triple triple3 = new TripleImpl(bNode2, property2, bNode1); Triple triple4 = new TripleImpl(property1, property1, bNode2); Triple triple5 = new TripleImpl(property1, property1, literal2); initialGraph.add(triple1); initialGraph.add(triple2); initialGraph.add(triple3); initialGraph.add(triple4); initialGraph.add(triple5); GraphNode node = new GraphNode(property1, new SimpleGraph(initialGraph.iterator())); node.replaceWith(newIRI, true); Assert.assertEquals(5, node.getGraph().size()); Triple expectedTriple1 = new TripleImpl(bNode1, newIRI, literal1); Triple expectedTriple2 = new TripleImpl(bNode1, property2, newIRI); Triple expectedTriple3 = new TripleImpl(newIRI, newIRI, bNode2); Triple expectedTriple4 = new TripleImpl(newIRI, newIRI, literal2); Assert.assertTrue(node.getGraph().contains(expectedTriple1)); Assert.assertTrue(node.getGraph().contains(expectedTriple2)); Assert.assertTrue(node.getGraph().contains(expectedTriple3)); Assert.assertTrue(node.getGraph().contains(expectedTriple4)); Assert.assertFalse(node.getGraph().contains(triple1)); Assert.assertFalse(node.getGraph().contains(triple2)); Assert.assertFalse(node.getGraph().contains(triple4)); Assert.assertFalse(node.getGraph().contains(triple5)); node = new GraphNode(property1, new SimpleGraph(initialGraph.iterator())); node.replaceWith(newBnode); Triple expectedTriple5 = new TripleImpl(bNode1, property2, newBnode); Triple expectedTriple6 = new TripleImpl(newBnode, property1, bNode2); Triple expectedTriple7 = new TripleImpl(newBnode, property1, literal2); Assert.assertTrue(node.getGraph().contains(triple1)); Assert.assertTrue(node.getGraph().contains(expectedTriple5)); Assert.assertTrue(node.getGraph().contains(expectedTriple6)); Assert.assertTrue(node.getGraph().contains(expectedTriple7)); node = new GraphNode(literal1, new SimpleGraph(initialGraph.iterator())); node.replaceWith(newBnode); Triple expectedTriple8 = new TripleImpl(bNode1, property1, newBnode); Assert.assertTrue(node.getGraph().contains(expectedTriple8)); node = new GraphNode(property1, new SimpleGraph(initialGraph.iterator())); node.replaceWith(newIRI); Triple expectedTriple9 = new TripleImpl(bNode1, property2, newIRI); Triple expectedTriple10 = new TripleImpl(newIRI, property1, bNode2); Triple expectedTriple11 = new TripleImpl(newIRI, property1, literal2); Assert.assertTrue(node.getGraph().contains(triple1)); Assert.assertTrue(node.getGraph().contains(expectedTriple9)); Assert.assertTrue(node.getGraph().contains(expectedTriple10)); Assert.assertTrue(node.getGraph().contains(expectedTriple11)); }
public GraphNode replaceWith(BlankNodeOrIRI replacement) { return replaceWith(replacement, false); }
GraphNode { public GraphNode replaceWith(BlankNodeOrIRI replacement) { return replaceWith(replacement, false); } }
GraphNode { public GraphNode replaceWith(BlankNodeOrIRI replacement) { return replaceWith(replacement, false); } GraphNode(RDFTerm resource, Graph graph); }
GraphNode { public GraphNode replaceWith(BlankNodeOrIRI replacement) { return replaceWith(replacement, false); } GraphNode(RDFTerm resource, Graph graph); Graph getGraph(); RDFTerm getNode(); void deleteNodeContext(); ImmutableGraph getNodeContext(); Iterator<Literal> getLiterals(IRI property); int countObjects(IRI property); Iterator<RDFTerm> getObjects(IRI property); boolean hasProperty(IRI property, RDFTerm object); int countSubjects(IRI property); Iterator<BlankNodeOrIRI> getSubjects(IRI property); Iterator<IRI> getIRIObjects(IRI property); Iterator<IRI> getProperties(); Iterator<IRI> getInverseProperties(); void addProperty(IRI predicate, RDFTerm object); void addPropertyValue(IRI property, Object value); void addInverseProperty(IRI predicate, RDFTerm subject); List<RDFTerm> asList(); void deleteProperties(IRI predicate); void deleteProperty(IRI predicate, RDFTerm object); @Override String toString(); GraphNode replaceWith(BlankNodeOrIRI replacement); GraphNode replaceWith(BlankNodeOrIRI replacement, boolean checkPredicates); Iterator<GraphNode> getObjectNodes(IRI property); Iterator<GraphNode> getSubjectNodes(IRI property); @Override boolean equals(Object obj); @Override int hashCode(); Lock readLock(); Lock writeLock(); }
GraphNode { public GraphNode replaceWith(BlankNodeOrIRI replacement) { return replaceWith(replacement, false); } GraphNode(RDFTerm resource, Graph graph); Graph getGraph(); RDFTerm getNode(); void deleteNodeContext(); ImmutableGraph getNodeContext(); Iterator<Literal> getLiterals(IRI property); int countObjects(IRI property); Iterator<RDFTerm> getObjects(IRI property); boolean hasProperty(IRI property, RDFTerm object); int countSubjects(IRI property); Iterator<BlankNodeOrIRI> getSubjects(IRI property); Iterator<IRI> getIRIObjects(IRI property); Iterator<IRI> getProperties(); Iterator<IRI> getInverseProperties(); void addProperty(IRI predicate, RDFTerm object); void addPropertyValue(IRI property, Object value); void addInverseProperty(IRI predicate, RDFTerm subject); List<RDFTerm> asList(); void deleteProperties(IRI predicate); void deleteProperty(IRI predicate, RDFTerm object); @Override String toString(); GraphNode replaceWith(BlankNodeOrIRI replacement); GraphNode replaceWith(BlankNodeOrIRI replacement, boolean checkPredicates); Iterator<GraphNode> getObjectNodes(IRI property); Iterator<GraphNode> getSubjectNodes(IRI property); @Override boolean equals(Object obj); @Override int hashCode(); Lock readLock(); Lock writeLock();  }