// Match patterns need to use a more complicated test.
if (! (env instanceof Env))
throw new RuntimeException(String.valueOf(env));
Env globalEnv = (Env) env;
boolean oldMorePositions = globalEnv.setMorePositions(true);
int oldIndex = globalEnv.setPositionIndex(0);
try {
for (int i = 0; globalEnv.hasMorePositions(); i++) {
globalEnv.setPositionIndex(i);
globalEnv.setMorePositions(false);
if (_expr.isNumber()) {
double test = _expr.evalNumber(node, env);
double position = _parent.position(node, globalEnv,
_parent.copyPosition());
if (position == test)
return true;
}
else if (_expr.isBoolean()) {
if (_expr.evalBoolean(node, env))
return true;
}
else {
Object value = _expr.evalObject(node, env);
if (value instanceof Number) {
double test = ((Number) value).doubleValue();
double position = _parent.position(node, globalEnv,
_parent.copyPosition());
if (position == test)
return true;
}
else if (Expr.toBoolean(value))
return true;
}
}
return false;
} finally {
globalEnv.setPositionIndex(oldIndex);
globalEnv.setMorePositions(oldMorePositions);
}
}