if (subj != null && memSubj == null) {
// non-existent subject
return new EmptyIteration<MemStatement, X>();
}
MemURI memPred = valueFactory.getMemURI(pred);
if (pred != null && memPred == null) {
// non-existent predicate
return new EmptyIteration<MemStatement, X>();
}
MemValue memObj = valueFactory.getMemValue(obj);
if (obj != null && memObj == null) {
// non-existent object
return new EmptyIteration<MemStatement, X>();
}
MemResource[] memContexts;
MemStatementList smallestList;
if (contexts.length == 0) {
memContexts = new MemResource[0];
smallestList = statements;
}
else if (contexts.length == 1 && contexts[0] != null) {
MemResource memContext = valueFactory.getMemResource(contexts[0]);
if (memContext == null) {
// non-existent context
return new EmptyIteration<MemStatement, X>();
}
memContexts = new MemResource[] { memContext };
smallestList = memContext.getContextStatementList();
}
else {
Set<MemResource> contextSet = new LinkedHashSet<MemResource>(2 * contexts.length);
for (Resource context : contexts) {
MemResource memContext = valueFactory.getMemResource(context);
if (context == null || memContext != null) {
contextSet.add(memContext);
}
}
if (contextSet.isEmpty()) {
// no known contexts specified
return new EmptyIteration<MemStatement, X>();
}
memContexts = contextSet.toArray(new MemResource[contextSet.size()]);
smallestList = statements;
}
if (memSubj != null) {
MemStatementList l = memSubj.getSubjectStatementList();
if (l.size() < smallestList.size()) {
smallestList = l;
}
}
if (memPred != null) {
MemStatementList l = memPred.getPredicateStatementList();
if (l.size() < smallestList.size()) {
smallestList = l;
}
}