public Model filter(final Value subj, final Value pred, final Value obj,
final Value... contexts) {
if (!isResourceURI(subj, pred) || !isEmptyOrResourcePresent(contexts))
return new EmptyModel(this);
return new FilteredModel(this, subj, pred, obj, contexts) {
@Override
public int size() {
if (subj == null && pred == null && obj == null) {
try {
return (int) con.size(cast(contexts));
} catch (RepositoryException e) {
throw new ModelException(e);
}
}
return super.size();
}
@Override
public Iterator<Statement> iterator() {
try {
return new StatementIterator(con.getStatements(
(Resource) subj, (URI) pred, obj, false,
cast(contexts)));
} catch (RepositoryException e) {
throw new ModelException(e);
}
}
};
}