@Override public void statementRemoved(Statement st) { boolean removed = (newStatements != null) ? newStatements.remove(st) : false; if (!removed) { // trigger full rebuild statementsRemoved = true; newStatements = null; } }
/** * @deprecated since 4.0. Use {@link #remove(Resource, IRI, Value, Resource...)} instead. */ @Deprecated public default boolean remove(Resource subj, URI pred, Value obj, Resource... contexts) { return remove(subj, (IRI)pred, obj, contexts); }
/** * @deprecated since 4.0. Use {@link #remove(Resource, IRI, Value, Resource...)} instead. */ @Deprecated public default boolean remove(Resource subj, URI pred, Value obj, Resource... contexts) { return remove(subj, (IRI)pred, obj, contexts); }
public boolean remove(Resource subj, IRI pred, Value obj, Resource... contexts) { return getDelegate().remove(subj, pred, obj, contexts); }
@Override public synchronized void clear(Resource... contexts) { if (contexts != null && contexts.length == 0) { if (approved != null) { approved.remove(null, null, null); } if (approvedContexts != null) { approvedContexts.clear(); } statementCleared = true; } else { if (approved != null) { approved.remove(null, null, null, contexts); } if (approvedContexts != null) { approvedContexts.removeAll(Arrays.asList(contexts)); } if (deprecatedContexts == null) { deprecatedContexts = new HashSet<Resource>(); } deprecatedContexts.addAll(Arrays.asList(contexts)); } }
public boolean remove(Resource subj, IRI pred, Value obj, Resource... contexts) { return getDelegate().remove(subj, pred, obj, contexts); }
@Override public boolean remove(Resource s, IRI p, Value o, Resource... c) { if (s == null) { s = subj; } if (p == null) { p = pred; } if (o == null) { o = obj; } if (c != null && c.length == 0) { c = contexts; } if (!accept(s, p, o, c)) { return false; } return model.remove(s, p, o, c); }
@Override public boolean remove(Resource s, IRI p, Value o, Resource... c) { if (s == null) { s = subj; } if (p == null) { p = pred; } if (o == null) { o = obj; } if (c != null && c.length == 0) { c = contexts; } if (!accept(s, p, o, c)) { return false; } return model.remove(s, p, o, c); }
@Override public synchronized void approve(Resource subj, IRI pred, Value obj, Resource ctx) { if (deprecated != null) { deprecated.remove(subj, pred, obj, ctx); } if (approved == null) { approved = createEmptyModel(); } approved.add(subj, pred, obj, ctx); if (ctx != null) { if (approvedContexts == null) { approvedContexts = new HashSet<Resource>(); } approvedContexts.add(ctx); } }
@Override public synchronized void deprecate(Resource subj, IRI pred, Value obj, Resource ctx) { if (approved != null) { approved.remove(subj, pred, obj, ctx); } if (deprecated == null) { deprecated = createEmptyModel(); } deprecated.add(subj, pred, obj, ctx); if (approvedContexts != null && approvedContexts.contains(ctx) && !approved.contains(null, null, null, ctx)) { approvedContexts.remove(ctx); } }
m.remove(subject, property, null, contexts);
@Override public void delRelation(String subject, String predicate, String object, String graph) throws RdfProcessingFailedException { try { if (Objects.equals(subject, baseUri)) { ValueFactory vf = SimpleValueFactory.getInstance(); model.remove(vf.createIRI(subject), vf.createIRI(predicate), vf.createIRI(object)); } } catch (Exception e) { throw new RdfProcessingFailedException(e); } }
@Override public void delValue(String subject, String predicate, String value, String dataType, String graph) throws RdfProcessingFailedException { try { if (Objects.equals(subject, baseUri)) { ValueFactory vf = SimpleValueFactory.getInstance(); model.remove(vf.createIRI(subject), vf.createIRI(predicate), vf.createLiteral(value)); } } catch (Exception e) { throw new RdfProcessingFailedException(e); } }
private void updateValue(Model graph, IRI pred, Value val) { Iterator<Statement> it = graph.match(null, pred, null); Statement s = it.next(); graph.remove(s); graph.add(s.getSubject(), pred, val); }
private synchronized Set<Statement> queueBlankStatements(SubjectInContext key) { Model firstMatch = blanks.filter(key.getSubject(), null, null, key.getContext()); Model matches = firstMatch.isEmpty() ? blankReferences.filter(key.getSubject(), null, null, key.getContext()) : firstMatch; if (matches.isEmpty()) { return null; } Set<Statement> set = stmtBySubject.get(key); if (set == null) { stmtBySubject.put(key, set = new TreeSet<>(comparator)); } set.addAll(matches); if (firstMatch.isEmpty()) { // repeat blank node values queueSize += matches.size(); } else { if (repeatBlankNodes && key.getSubject() instanceof BNode && isStillReferenced(key)) { blankReferences.addAll(matches); } blanks.remove(key.getSubject(), null, null, key.getContext()); } return set; }
private synchronized Set<Statement> queueBlankStatements(SubjectInContext key) { Model firstMatch = blanks.filter(key.getSubject(), null, null, key.getContext()); Model matches = firstMatch.isEmpty() ? blankReferences.filter(key.getSubject(), null, null, key.getContext()) : firstMatch; if (matches.isEmpty()) { return null; } Set<Statement> set = stmtBySubject.get(key); if (set == null) { stmtBySubject.put(key, set = new TreeSet<Statement>(comparator)); } set.addAll(matches); if (firstMatch.isEmpty()) { // repeat blank node values queueSize += matches.size(); } else { if (repeatBlankNodes && key.getSubject() instanceof BNode && isStillReferenced(key)) { blankReferences.addAll(matches); } blanks.remove(key.getSubject(), null, null, key.getContext()); } return set; }
@Test public void testGetListURIHeadAfterInvalidGraphOperation() { this.testRdfListUtilDefaults.addList(this.testListHeadUri1, this.testValuesMultipleElements, this.testGraph); assertEquals(6, this.testGraph.size()); // Modify the graph in an invalid way to test getList final Iterator<Statement> matches = this.testGraph.filter(null, RDF.REST, RDF.NIL).iterator(); assertTrue(matches.hasNext()); final Statement matchedStatement = matches.next(); assertFalse(matches.hasNext()); assertTrue(this.testGraph.remove(matchedStatement)); assertFalse(this.testGraph.contains(matchedStatement)); try { final List<Value> results = this.testRdfListUtilDefaults.getList( this.testListHeadUri1, this.testGraph, (Resource) null); assertEquals("Returned results from an invalid list structure", 0, results.size()); fail("Did not find expected exception"); } catch (final RuntimeException rex) { assertEquals("List structure was not complete", rex.getMessage()); } }
@Test public void testGetListBNodeHeadAfterInvalidGraphOperation() { this.testRdfListUtilDefaults.addList(this.testListHeadBNode1, this.testValuesMultipleElements, this.testGraph); assertEquals(6, this.testGraph.size()); // Modify the graph in an invalid way to test getList final Iterator<Statement> matches = this.testGraph.filter(null, RDF.REST, RDF.NIL).iterator(); assertTrue(matches.hasNext()); final Statement matchedStatement = matches.next(); assertFalse(matches.hasNext()); assertTrue(this.testGraph.remove(matchedStatement)); assertFalse(this.testGraph.contains(matchedStatement)); try { final List<Value> results = this.testRdfListUtilDefaults.getList( this.testListHeadBNode1, this.testGraph, (Resource) null); assertEquals("Returned results from an invalid list structure", 0, results.size()); fail("Did not find expected exception"); } catch (final RuntimeException rex) { assertEquals("List structure was not complete", rex.getMessage()); } }
@Test public void testGetListAtNodeAfterInvalidGraphOperation() { this.testRdfListUtilDefaults.addListAtNode( this.testSubjectUri1, this.testPredicateUri1, this.testValuesMultipleElements, this.testGraph); assertEquals(7, this.testGraph.size()); // Modify the graph in an invalid way to test getList final Iterator<Statement> matches = this.testGraph.filter(null, RDF.REST, RDF.NIL).iterator(); assertTrue(matches.hasNext()); final Statement matchedStatement = matches.next(); assertFalse(matches.hasNext()); assertTrue(this.testGraph.remove(matchedStatement)); assertFalse(this.testGraph.contains(matchedStatement)); try { final List<Value> results = this.testRdfListUtilDefaults.getListAtNode( this.testSubjectUri1, this.testPredicateUri1, this.testGraph, (Resource) null); assertEquals("Returned results from an invalid list structure", 0, results.size()); fail("Did not find expected exception"); } catch (final RuntimeException rex) { assertEquals("List structure was not complete", rex.getMessage()); } }
@Test public void testGetListBNodeHeadAfterInvalidGraphOperation2() { this.testRdfListUtilDefaults.addList(this.testListHeadBNode1, this.testValuesMultipleElements, this.testGraph); assertEquals(6, this.testGraph.size()); // Modify the graph in an invalid way to test getList final Iterator<Statement> matches = this.testGraph.filter(null, RDF.REST, RDF.NIL).iterator(); assertTrue(matches.hasNext()); final Statement matchedStatement = matches.next(); assertFalse(matches.hasNext()); assertTrue(this.testGraph.remove(matchedStatement)); assertFalse(this.testGraph.contains(matchedStatement)); Statement literalRdfRest = this.vf.createStatement( matchedStatement.getSubject(), RDF.REST, this.vf.createLiteral("InvalidRdfRestLiteral")); this.testGraph.add(literalRdfRest); try { final List<Value> results = this.testRdfListUtilDefaults.getList( this.testListHeadBNode1, this.testGraph, (Resource) null); assertEquals("Returned results from an invalid list structure", 0, results.size()); fail("Did not find expected exception"); } catch (final RuntimeException rex) { assertEquals("List structure was not complete", rex.getMessage()); } }