/** A JavaScript JSArray */
public class JSArray extends JS {
private static final Object NULL = new Object();
+
+ private BalancedTree arr = new BalancedTree();
public JSArray() { }
public JSArray(int size) { setSize(size); }
public final int length() { return size(); }
public final Object elementAt(int i) {
if(i < 0 || i >= size()) throw new ArrayIndexOutOfBoundsException(i);
- Object o = getNode(i);
+ Object o = arr.getNode(i);
return o == NULL ? null : o;
}
public final void addElement(Object o) {
- insertNode(size(),o==null ? NULL : o);
+ arr.insertNode(size(),o==null ? NULL : o);
}
public final void setElementAt(Object o, int i) {
if(i < 0 || i >= size()) throw new ArrayIndexOutOfBoundsException(i);
- replaceNode(i,o==null ? NULL : o);
+ arr.replaceNode(i,o==null ? NULL : o);
}
public final void insertElementAt(Object o, int i) {
if(i < 0 || i > size()) throw new ArrayIndexOutOfBoundsException(i);
- insertNode(i,o==null ? NULL : o);
+ arr.insertNode(i,o==null ? NULL : o);
}
public final Object removeElementAt(int i) {
if(i < 0 || i >= size()) throw new ArrayIndexOutOfBoundsException(i);
- Object o = deleteNode(i);
+ Object o = arr.deleteNode(i);
return o == NULL ? null : o;
}
- public final int size() { return treeSize(); }
+ public final int size() { return arr.treeSize(); }
public String typeName() { return "array"; }
private Object join(String sep) {
int size = size();
if(size < 2) return this;
Vec vec = toVec();
- clear();
+ arr.clear();
for(int i=size-1,j=0;i>=0;i--,j++) insertElementAt(vec.elementAt(i),j);
return this;
}
Vec vec = new Vec();
vec.setSize(count);
for(int i=0;i<count;i++) {
- Object o = getNode(i);
+ Object o = arr.getNode(i);
vec.setElementAt(o == NULL ? null : o,i);
}
return vec;
protected void setFromVec(Vec vec) {
int count = vec.size();
- clear();
+ arr.clear();
for(int i=0;i<count;i++) {
Object o = vec.elementAt(i);
- insertNode(i,o==null ? NULL : o);
+ arr.insertNode(i,o==null ? NULL : o);
}
}