}
protected Sequence nodeSetCompare(NodeSet nodes, Sequence contextSequence) throws XPathException {
if (context.getProfiler().isEnabled())
{context.getProfiler().message(this, Profiler.OPTIMIZATION_FLAGS, "OPTIMIZATION CHOICE", "nodeSetCompare");}
final NodeSet result = new ExtArrayNodeSet();
final Collator collator = getCollator(contextSequence);
if (contextSequence != null && !contextSequence.isEmpty()) {
for (final Iterator<NodeProxy> i = nodes.iterator(); i.hasNext();) {
final NodeProxy current = i.next();
ContextItem context = current.getContext();
if (context==null) {
throw new XPathException(this,"Context is missing for node set comparison");
}
do {
final AtomicValue lv = current.atomize();
final Sequence rs = getRight().eval(context.getNode().toSequence());
if (!rs.hasOne())
{throw new XPathException(this,
"Type error: sequence with less or more than one item is not allowed here");}
if (compareAtomic(collator, lv, rs.itemAt(0).atomize(), Constants.TRUNC_NONE, relation))
{result.add(current);}
} while ((context = context.getNextDirect()) != null);
}
} else {
final Sequence rs = getRight().eval(null);
if (!rs.hasOne())
{throw new XPathException(this,
"Type error: sequence with less or more than one item is not allowed here");}
final AtomicValue rv = rs.itemAt(0).atomize();
for (final Iterator<NodeProxy> i = nodes.iterator(); i.hasNext();) {
final NodeProxy current = i.next();
final AtomicValue lv = current.atomize();
if (compareAtomic(collator, lv, rv, Constants.TRUNC_NONE, Constants.EQ))
{result.add(current);}
}
}
return result;
}