get rid of JS.BT
authorbrian <brian@brianweb.net>
Wed, 7 Jul 2004 15:52:06 +0000 (15:52 +0000)
committerbrian <brian@brianweb.net>
Wed, 7 Jul 2004 15:52:06 +0000 (15:52 +0000)
darcs-hash:20040707155206-24bed-60c9d2796da762525b2b5f7a9f0518f85fcaef0e.gz

src/org/ibex/core/Box.java
src/org/ibex/js/JS.java
src/org/ibex/js/JSArray.java
src/org/ibex/js/JSScope.java

index 053357a..a587a55 100644 (file)
@@ -99,6 +99,8 @@ public final class Box extends JSScope implements Task {
     Box redirect = this;
     int flags = VISIBLE | PACKED | REPACK | RECONSTRAIN | REPLACE | FIXED | STOP_UPWARD_PROPAGATION | CLIP | MOVED;
 
     Box redirect = this;
     int flags = VISIBLE | PACKED | REPACK | RECONSTRAIN | REPLACE | FIXED | STOP_UPWARD_PROPAGATION | CLIP | MOVED;
 
+    private BalancedTree bt;
+    
     private String text = null;
     private Font font = DEFAULT_FONT; 
     private Picture texture = null;
     private String text = null;
     private Font font = DEFAULT_FONT; 
     private Picture texture = null;
@@ -938,4 +940,15 @@ public final class Box extends JSScope implements Task {
             JS.log(e);
         }
     }
             JS.log(e);
         }
     }
+    
+    // BalancedTree functions
+    private void insertNode(int p, Box b) {
+        if(bt == null) bt = new BalancedTree();
+        bt.insertNode(p,b);
+    }
+    
+    private int treeSize() { return bt == null ? 0 : bt.treeSize(); }
+    private int indexNode(Box b) { return bt == null ? -1 : bt.indexNode(b); }
+    private void deleteNode(int p) { bt.deleteNode(p); }
+    private Box getNode(int p) { return (Box)bt.getNode(p); }
 }
 }
index cd63638..2d5c9aa 100644 (file)
@@ -64,18 +64,6 @@ public abstract class JS {
         }    
     }
     
         }    
     }
     
-    public static class BT extends O {
-        private BalancedTree bt;
-        private final BalancedTree bt() { if(bt != null) return bt; return bt = new BalancedTree(); }
-        public final void insertNode(int index, Object o) { bt().insertNode(index,o); }
-        public final void clear() { bt().clear(); }
-        public final Object getNode(int i) { return bt().getNode(i); }
-        public final int treeSize() { return bt().treeSize(); }
-        public final Object deleteNode(int i) { return bt().deleteNode(i); }
-        public final void replaceNode(int index, Object o) { bt().replaceNode(index,o); }
-        public final int indexNode(Object o) { return bt().indexNode(o); }
-    }
-        
     JS _unclone() { return this; }
     
     public interface Cloneable { }
     JS _unclone() { return this; }
     
     public interface Cloneable { }
index 4777213..5afa82a 100644 (file)
@@ -5,8 +5,9 @@ import org.ibex.util.*;
 import java.util.*;
 
 /** A JavaScript JSArray */
 import java.util.*;
 
 /** A JavaScript JSArray */
-class JSArray extends JS.BT {
+class JSArray extends JS.O {
     private static final Object NULL = new Object();
     private static final Object NULL = new Object();
+    private final BalancedTree bt = new BalancedTree();
     
     public JSArray() { }
     public JSArray(int size) { setSize(size); }
     
     public JSArray() { }
     public JSArray(int size) { setSize(size); }
@@ -122,27 +123,27 @@ class JSArray extends JS.BT {
     public final int length() { return size(); }
     public final JS elementAt(int i) { 
         if(i < 0 || i >= size()) throw new ArrayIndexOutOfBoundsException(i);
     public final int length() { return size(); }
     public final JS elementAt(int i) { 
         if(i < 0 || i >= size()) throw new ArrayIndexOutOfBoundsException(i);
-        Object o = getNode(i);
+        Object o = bt.getNode(i);
         return o == NULL ? (JS)null : (JS)o;
     }
     public final void addElement(JS o) { 
         return o == NULL ? (JS)null : (JS)o;
     }
     public final void addElement(JS o) { 
-        insertNode(size(),o==null ? NULL : o);
+        bt.insertNode(size(),o==null ? NULL : o);
     }
     public final void setElementAt(JS o, int i) {
         if(i < 0 || i >= size()) throw new ArrayIndexOutOfBoundsException(i);
     }
     public final void setElementAt(JS o, int i) {
         if(i < 0 || i >= size()) throw new ArrayIndexOutOfBoundsException(i);
-        replaceNode(i,o==null ? NULL : o);
+        bt.replaceNode(i,o==null ? NULL : o);
     }
     public final void insertElementAt(JS o, int i) {
         if(i < 0 || i > size()) throw new ArrayIndexOutOfBoundsException(i);
     }
     public final void insertElementAt(JS o, int i) {
         if(i < 0 || i > size()) throw new ArrayIndexOutOfBoundsException(i);
-        insertNode(i,o==null ? NULL : o);
+        bt.insertNode(i,o==null ? NULL : o);
     }
     public final JS removeElementAt(int i) {
         if(i < 0 || i >= size()) throw new ArrayIndexOutOfBoundsException(i);
     }
     public final JS removeElementAt(int i) {
         if(i < 0 || i >= size()) throw new ArrayIndexOutOfBoundsException(i);
-        Object o = deleteNode(i);
+        Object o = bt.deleteNode(i);
         return o == NULL ? (JS)null : (JS)o;
     }
     
         return o == NULL ? (JS)null : (JS)o;
     }
     
-    public final int size() { return treeSize(); }
+    public final int size() { return bt.treeSize(); }
     
     private JS join(String sep) throws JSExn {
         int length = size();
     
     private JS join(String sep) throws JSExn {
         int length = size();
@@ -163,7 +164,7 @@ class JSArray extends JS.BT {
         int size = size();
         if(size < 2) return this;
         Vec vec = toVec();
         int size = size();
         if(size < 2) return this;
         Vec vec = toVec();
-        clear();
+        bt.clear();
         for(int i=size-1,j=0;i>=0;i--,j++) insertElementAt((JS)vec.elementAt(i),j);
         return this;
     }
         for(int i=size-1,j=0;i>=0;i--,j++) insertElementAt((JS)vec.elementAt(i),j);
         return this;
     }
@@ -246,7 +247,7 @@ class JSArray extends JS.BT {
         Vec vec = new Vec();
         vec.setSize(count);
         for(int i=0;i<count;i++) {
         Vec vec = new Vec();
         vec.setSize(count);
         for(int i=0;i<count;i++) {
-            Object o = getNode(i);
+            Object o = bt.getNode(i);
             vec.setElementAt(o == NULL ? null : o,i);
         }
         return vec;
             vec.setElementAt(o == NULL ? null : o,i);
         }
         return vec;
@@ -254,10 +255,10 @@ class JSArray extends JS.BT {
     
     protected void setFromVec(Vec vec) {
         int count = vec.size();
     
     protected void setFromVec(Vec vec) {
         int count = vec.size();
-        clear();
+        bt.clear();
         for(int i=0;i<count;i++) {
             Object o = vec.elementAt(i);
         for(int i=0;i<count;i++) {
             Object o = vec.elementAt(i);
-            insertNode(i,o==null ? NULL : o);
+            bt.insertNode(i,o==null ? NULL : o);
         }
     }
     
         }
     }
     
index 5036220..9fbd3e2 100644 (file)
@@ -3,8 +3,7 @@ package org.ibex.js;
 
 // FIXME: should allow parentScope to be a JS, not a JSScope
 /** Implementation of a JavaScript Scope */
 
 // FIXME: should allow parentScope to be a JS, not a JSScope
 /** Implementation of a JavaScript Scope */
-// HACK: JSScope doesn't really need the BT, this is just for Box.java 
-public class JSScope extends JS.BT { 
+public class JSScope extends JS.O { 
 
     private JSScope parentScope;
 
 
     private JSScope parentScope;