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:
parent
a48bec8be4
commit
42e2552fbe
1 changed files with 25 additions and 0 deletions
|
@ -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());
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
|
|
Loading…
Add table
Reference in a new issue