From: brian Date: Wed, 7 Jul 2004 15:52:06 +0000 (+0000) Subject: get rid of JS.BT X-Git-Url: http://git.megacz.com/?p=org.ibex.core.git;a=commitdiff_plain;h=85c640ef9709fd71d0f12d8918ce125dbcc58461 get rid of JS.BT darcs-hash:20040707155206-24bed-60c9d2796da762525b2b5f7a9f0518f85fcaef0e.gz --- diff --git a/src/org/ibex/core/Box.java b/src/org/ibex/core/Box.java index 053357a..a587a55 100644 --- a/src/org/ibex/core/Box.java +++ b/src/org/ibex/core/Box.java @@ -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; + private BalancedTree bt; + 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); } } + + // 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); } } diff --git a/src/org/ibex/js/JS.java b/src/org/ibex/js/JS.java index cd63638..2d5c9aa 100644 --- a/src/org/ibex/js/JS.java +++ b/src/org/ibex/js/JS.java @@ -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 { } diff --git a/src/org/ibex/js/JSArray.java b/src/org/ibex/js/JSArray.java index 4777213..5afa82a 100644 --- a/src/org/ibex/js/JSArray.java +++ b/src/org/ibex/js/JSArray.java @@ -5,8 +5,9 @@ import org.ibex.util.*; import java.util.*; /** A JavaScript JSArray */ -class JSArray extends JS.BT { +class JSArray extends JS.O { private static final Object NULL = new Object(); + private final BalancedTree bt = new BalancedTree(); 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); - Object o = getNode(i); + Object o = bt.getNode(i); 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); - 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); - 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); - Object o = deleteNode(i); + Object o = bt.deleteNode(i); 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(); @@ -163,7 +164,7 @@ class JSArray extends JS.BT { 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; } @@ -246,7 +247,7 @@ class JSArray extends JS.BT { Vec vec = new Vec(); vec.setSize(count); for(int i=0;i