JS no longer automatically extends BalancedTree
[org.ibex.js.git] / src / org / ibex / js / JSArray.java
index 7b90de7..dfb9714 100644 (file)
@@ -7,6 +7,8 @@ import java.util.*;
 /** 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); }
@@ -118,27 +120,27 @@ public class JSArray extends JS {
     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) {
@@ -160,7 +162,7 @@ public class JSArray extends JS {
         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;
     }
@@ -243,7 +245,7 @@ public class JSArray extends JS {
         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;
@@ -251,10 +253,10 @@ public class JSArray extends JS {
     
     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);
         }
     }