public boolean effectiveBooleanValue(XPathContext context) throws XPathException {
// If the first operand is a singleton boolean,
// compare it with the effective boolean value of the other operand
SequenceIterator iter0 = null;
if (maybeBoolean0) {
iter0 = operand0.iterate(context);
Item i01 = iter0.next();
Item i02 = (i01 == null ? null : iter0.next());
if (i01 instanceof BooleanValue && i02 == null) {
boolean b = operand1.effectiveBooleanValue(context);
return compare((BooleanValue)i01, singletonOperator, BooleanValue.get(b), comparer, context);
}
if (i01 == null && !maybeBoolean1) {
return false;
}
}
// If the second operand is a singleton boolean,
// compare it with the effective boolean value of the other operand
SequenceIterator iter1 = null;
if (maybeBoolean1) {
iter1 = operand1.iterate(context);
Item i11 = iter1.next();
Item i12 = (i11 == null ? null : iter1.next());
if (i11 instanceof BooleanValue && i12 == null) {
boolean b = operand0.effectiveBooleanValue(context);
return compare(BooleanValue.get(b), singletonOperator, (BooleanValue)i11, comparer, context);
}
if (i11 == null && !maybeBoolean0) {
return false;
}
}
// Atomize both operands where necessary
if (iter0 == null) {
iter0 = operand0.iterate(context);
} else {
iter0 = iter0.getAnother();
}
if (iter1 == null) {
iter1 = operand1.iterate(context);
} else {
iter1 = iter1.getAnother();
}
if (atomize0) {
iter0 = Atomizer.getAtomizingIterator(iter0);
}
if (atomize1) {
iter1 = Atomizer.getAtomizingIterator(iter1);
}
// If the operator is one of <, >, <=, >=, then convert both operands to sequences of xs:double
// using the number() function
if (operator == Token.LT || operator == Token.LE || operator == Token.GT || operator == Token.GE) {
ItemMappingFunction map = new ItemMappingFunction() {
public Item mapItem(Item item) throws XPathException {
return NumberFn.convert((AtomicValue)item);
}
};
iter0 = new ItemMappingIterator(iter0, map, true);
iter1 = new ItemMappingIterator(iter1, map, true);
}
// Compare all pairs of atomic values in the two atomized sequences
List seq1 = null;
while (true) {
AtomicValue item0 = (AtomicValue)iter0.next();
if (item0 == null) {
return false;
}
if (iter1 != null) {
while (true) {
AtomicValue item1 = (AtomicValue)iter1.next();
if (item1 == null) {
iter1 = null;
if (seq1 == null) {
// second operand is empty
return false;