Implement HopObject.list(start, length) as proposed by Tobi in

<http://helma.org/bugs/show_bug.cgi?id=303>. This is similar to
HopObject.list(), except the array it returns only contains the child
objects in the range specified by the start and length arguments.
This also does a prefetchChildren() on the specified range to optimize
database access.
This commit is contained in:
hns 2003-12-02 16:42:13 +00:00
parent a48bec8be4
commit 42e2552fbe

View file

@ -452,6 +452,31 @@ public class HopObject extends ScriptableObject implements Wrapper {
return Context.getCurrentContext().newArray(core.global, a.toArray());
}
/**
* Return a JS array of child objects with the given start and length.
*
* @return A JavaScript Array containing the specified child objexts
*/
public Scriptable jsFunction_list(int start, int length) {
if (start < 0 || length < 0) {
throw new EvaluatorException("Arguments must not be negative in HopObject.list(start, length)");
}
checkNode();
jsFunction_prefetchChildren(start, length);
ArrayList a = new ArrayList();
for (int i=start; i<start+length; i++) {
INode n = node.getSubnodeAt(i);
if (n != null) {
a.add(Context.toObject(n, core.global));
}
}
return Context.getCurrentContext().newArray(core.global, a.toArray());
}
/**
*
*