protected Object evaluate(final Object[] iParams, final OCommandContext iContext, final String iClassName) {
final int beginIndex = (Integer) iParams[0];
final int items = iParams.length > 1 ? (Integer) iParams[1] : 1;
final ArrayDeque stack = (ArrayDeque) iContext.getVariable("stack");
if (stack == null)
throw new OCommandExecutionException("Cannot invoke " + getName() + "() against non traverse command");
final List<OIdentifiable> result = items > 1 ? new ArrayList<OIdentifiable>(items) : null;
if (beginIndex < 0) {
int i = -1;
for (Iterator it = stack.iterator(); it.hasNext();) {
final Object o = it.next();
if (o instanceof OTraverseRecordProcess) {
final ODocument record = ((OTraverseRecordProcess) o).getTarget();
if (iClassName == null || record.getSchemaClass().isSubClassOf(iClassName)) {
if (i <= beginIndex) {
if (items == 1)
return record;
else {
result.add(record);
if (result.size() >= items)
break;
}
}
i--;
}
}
}
} else {
int i = 0;
for (Iterator it = stack.descendingIterator(); it.hasNext();) {
final Object o = it.next();
if (o instanceof OTraverseRecordProcess) {
final ODocument record = ((OTraverseRecordProcess) o).getTarget();
if (iClassName == null || record.getSchemaClass().isSubClassOf(iClassName)) {