Search in sources :

Example 1 with PatternIterator

use of org.eclipse.rdf4j.model.util.PatternIterator in project rdf4j by eclipse.

the class LinkedHashModel method matchPattern.

private ModelIterator matchPattern(Resource subj, IRI pred, Value obj, Resource... contexts) {
    Set<ModelStatement> set = choose(subj, pred, obj, contexts);
    Iterator<ModelStatement> it = set.iterator();
    Iterator<ModelStatement> iter;
    iter = new PatternIterator(it, subj, pred, obj, contexts);
    return new ModelIterator(iter, set);
}
Also used : PatternIterator(org.eclipse.rdf4j.model.util.PatternIterator)

Example 2 with PatternIterator

use of org.eclipse.rdf4j.model.util.PatternIterator in project rdf4j by eclipse.

the class LinkedHashModel method removeTermIteration.

@Override
public void removeTermIteration(Iterator iterator, Resource subj, IRI pred, Value obj, Resource... contexts) {
    Set<ModelStatement> owner = ((ModelIterator) iterator).getOwner();
    Set<ModelStatement> chosen = choose(subj, pred, obj, contexts);
    Iterator<ModelStatement> iter = chosen.iterator();
    iter = new PatternIterator(iter, subj, pred, obj, contexts);
    while (iter.hasNext()) {
        ModelStatement last = iter.next();
        if (statements == owner) {
            statements = new LinkedHashSet<ModelStatement>(statements);
            statements.remove(last);
        } else if (statements != chosen) {
            statements.remove(last);
        }
        if (last.subj.subjects == owner) {
            last.subj.subjects = new LinkedHashSet<ModelStatement>(last.subj.subjects);
            last.subj.subjects.remove(last);
        } else if (last.subj.subjects != chosen) {
            last.subj.subjects.remove(last);
        }
        if (last.pred.predicates == owner) {
            last.pred.predicates = new LinkedHashSet<ModelStatement>(statements);
            last.pred.predicates.remove(last);
        } else if (last.pred.predicates != chosen) {
            last.pred.predicates.remove(last);
        }
        if (last.obj.objects == owner) {
            last.obj.objects = new LinkedHashSet<ModelStatement>(statements);
            last.obj.objects.remove(last);
        } else if (last.obj.objects != chosen) {
            last.obj.objects.remove(last);
        }
        if (last.ctx.contexts == owner) {
            last.ctx.contexts = new LinkedHashSet<ModelStatement>(statements);
            last.ctx.contexts.remove(last);
        } else if (last.ctx.contexts != chosen) {
            last.ctx.contexts.remove(last);
        }
        if (owner != chosen) {
            // remove from chosen
            iter.remove();
        }
    }
}
Also used : PatternIterator(org.eclipse.rdf4j.model.util.PatternIterator)

Aggregations

PatternIterator (org.eclipse.rdf4j.model.util.PatternIterator)2