Revision: 1743
          http://svn.sourceforge.net/vexi/?rev=1743&view=rev
Author:   mkpg2
Date:     2007-03-20 08:48:47 -0700 (Tue, 20 Mar 2007)

Log Message:
-----------
Development. Made iterator seperate to keysof object.

Modified Paths:
--------------
    core/trunk/org.ibex.js/src/org/ibex/js/Constants.java
    core/trunk/org.ibex.js/src/org/ibex/js/JS.jpp
    core/trunk/org.ibex.js/src/org/ibex/js/JSArray.jpp
    core/trunk/org.ibex.js/src/org/ibex/js/Parser.java
    core/trunk/org.ibex.js/src/org/ibex/js/SOAP.java
    core/trunk/org.ibex.js/src/org/ibex/js/Scheduler.java
    core/trunk/org.ibex.js/src/org/ibex/js/XMLRPC.jpp
    core/trunk/org.ibex.js/src_junit/test/js/general/keysof.js
    core/trunk/org.ibex.js/src_unused/org/ibex/js/Directory.java
    core/trunk/org.ibex.js/src_unused/org/ibex/js/JSReflection.java

Modified: core/trunk/org.ibex.js/src/org/ibex/js/Constants.java
===================================================================
--- core/trunk/org.ibex.js/src/org/ibex/js/Constants.java       2007-03-20 
13:21:05 UTC (rev 1742)
+++ core/trunk/org.ibex.js/src/org/ibex/js/Constants.java       2007-03-20 
15:48:47 UTC (rev 1743)
@@ -14,6 +14,7 @@
        static final JS SC_hasNext = JSU.S("hasNext",true);
        static final JS SC_index = JSU.S("index",true);
        static final JS SC_input = JSU.S("input",true);
+       static final JS SC_iterator = JSU.S("iterator",true);
        static final JS SC_lastModified = JSU.S("lastModified",true);
        static final JS SC_length = JSU.S("length",true);
        static final JS SC_message = JSU.S("message",true);

Modified: core/trunk/org.ibex.js/src/org/ibex/js/JS.jpp
===================================================================
--- core/trunk/org.ibex.js/src/org/ibex/js/JS.jpp       2007-03-20 13:21:05 UTC 
(rev 1742)
+++ core/trunk/org.ibex.js/src/org/ibex/js/JS.jpp       2007-03-20 15:48:47 UTC 
(rev 1743)
@@ -18,8 +18,8 @@
                private Method(){} // Private so that there can be only one.
        }
        
-    /** Returns an enumeration of the keys in this object. */
-    public JS.Enumeration keys() throws JSExn;
+    /** Returns an the keys 'obj'. */
+    public JS.Keys keys() throws JSExn;
 
     /** Return the value associated with the given key. */
     public JS get(JS key) throws JSExn;
@@ -71,7 +71,7 @@
         private static final String[] emptystr = new String[0];
 
         public JS unclone() { return this; }
-        public JS.Enumeration keys() throws JSExn {
+        public Keys keys() throws JSExn {
             throw new JSExn("object has no key set, class ["+ 
getClass().getName() +"]"); }
         public JS get(JS key) throws JSExn { return null; }
         public void put(JS key, JS val) throws JSExn {
@@ -112,7 +112,7 @@
         // Non-Trap methods forward to the clonee        
         public JS unclone() { return clonee.unclone(); }
         public boolean equals(Object o) { return (!(o instanceof JS))?false: 
clonee.equals(((JS)o).unclone()); }
-        public Enumeration keys() throws JSExn { return clonee.keys(); }
+        public Keys keys() throws JSExn { return clonee.keys(); }
         public JS get(JS k) throws JSExn { return clonee.get(k); }
         public void put(JS k, JS v) throws JSExn { clonee.put(k, v); }
         public JS call(JS t, JS m, JS[] a) throws JSExn { return 
clonee.call(t, m, a); }
@@ -192,26 +192,26 @@
         public JS call(JS method, JS[] args) throws JSExn {
             throw new JSExn(method==null ? "cannot call a " + 
getClass().getName() : "method not found: " + JSU.str(method)); }
 
-        public Enumeration keys() throws JSExn {
-               return new Enumeration(null) {
-                    private int cur = 0;
-                    private Object[] keydump; 
-                    public JS _remove(JS key) throws JSExn{
-                       JS r = Obj.this.get(key);
-                       Obj.super.remove(key);
-                       return r;
-                    }
-                    private Object[] _keys(){if(keydump==null){keydump = 
JS.Obj.this.dumpkeys();}return keydump;}
-                    public boolean _hasNext() { return cur < _keys().length; }
-                    public JS _next() throws JSExn {
-                       Object[] keys = _keys();
-                       if (cur >= keys.length) throw new 
NoSuchElementException();
-                        return (JS)keys[cur++];
-                    }
-                    public JS _size() throws JSExn {
-                       return JSU.N(JS.Obj.this.size());
-                    }
-                };
+        public Keys keys() throws JSExn {
+               return new Keys(){
+                               public Enumeration iterator() throws JSExn {
+                               return new Enumeration(null) {
+                           private int cur = 0;
+                           private Object[] keys = JS.Obj.this.dumpkeys(); 
+                           public boolean _hasNext() { return cur < 
keys.length; }
+                           public JS _next() throws JSExn {
+                               if (cur >= keys.length) throw new 
NoSuchElementException();
+                               return (JS)keys[cur++];
+                           }
+                       };
+                               }
+                               protected JS remove(JS key) throws JSExn {
+                                       JS r = Obj.this.get(key);
+                       Obj.super.remove(key);
+                       return r;
+                               }
+                               protected JS size() throws JSExn {return 
JSU.N(JS.Obj.this.size());}
+               };
         }
 
         public JS get(JS key) throws JSExn { return (JS)super.get(key, 0); }
@@ -326,6 +326,32 @@
         public Trap write();
     }
 
+    public static abstract class Keys extends Immutable {
+       protected JS contains(JS key) throws JSExn{ throw new JSExn("Cannot 
call contains on [" + getClass().getName() +"]");}
+       public Enumeration iterator() throws JSExn{throw new JSExn("Cannot call 
iterator on [" + getClass().getName() +"]");}
+       protected JS remove(JS key) throws JSExn{ throw new JSExn("Cannot call 
key on [" + getClass().getName() +"]");}
+       protected JS size() throws JSExn{ throw new JSExn("Cannot call size on 
[" + getClass().getName() +"]");}
+       
+        public JS get(JS key) throws JSExn {
+            //#switch(JSU.str(key))
+            case "contains": return METHOD; 
+            case "iterator": return METHOD; 
+            case "remove": return METHOD;
+            case "size": return size();
+            //#end
+            return super.get(key);
+        }
+        
+        public JS call(JS method, JS[] args) throws JSExn {
+            //#switch(JSU.str(method))
+               case "contains": return contains(args[0]); 
+               case "iterator": return iterator(); 
+               case "remove": return remove(args[0]);
+               //#end
+               return super.call(method, args);
+        }
+    }
+    
     public static abstract class Enumeration extends Immutable {
         public static final Enumeration EMPTY = new Empty(null);
 
@@ -336,8 +362,7 @@
 
         protected abstract boolean _hasNext();
         protected abstract JS _next() throws JSExn;
-        protected JS _remove(JS key) throws JSExn {return null;}
-        protected JS _size() throws JSExn{return null;}
+
         
         public final boolean hasNext() { return _hasNext() || (parent != null 
? parent.hasNext() : false); }
         public final JS next() throws JSExn {
@@ -350,20 +375,10 @@
             //#switch(JSU.str(key))
             case "hasNext": return JSU.B(hasNext());
             case "next": return next();
-            case "remove": return METHOD;
-            case "size": return METHOD;
             //#end
             return super.get(key);
         }
         
-        public JS call(JS method, JS[] args) throws JSExn {
-            //#switch(JSU.str(method))
-               case "remove": return _remove(args[0]);
-               case "size": return _size();
-               //#end
-               return super.call(method, args);
-        }
-        
         public static final class Empty extends Enumeration {
             public Empty(Enumeration parent) { super(parent); }
             protected boolean _hasNext() { return false; }

Modified: core/trunk/org.ibex.js/src/org/ibex/js/JSArray.jpp
===================================================================
--- core/trunk/org.ibex.js/src/org/ibex/js/JSArray.jpp  2007-03-20 13:21:05 UTC 
(rev 1742)
+++ core/trunk/org.ibex.js/src/org/ibex/js/JSArray.jpp  2007-03-20 15:48:47 UTC 
(rev 1743)
@@ -16,12 +16,26 @@
     public JSArray(JS arg) { super(1); add(arg); }
 
     public JS unclone() { return this; }
-    public JS.Enumeration keys() throws JSExn {
-        return new Enumeration(null) {
-            private int n = 0;
-            public boolean _hasNext() { return n < size(); }
-            public JS _next() { return JSU.N(n++); }
+    public Keys keys() throws JSExn {
+        return new Keys(){
+                       protected JS contains(JS key) throws JSExn {
+                               return JSU.B(JSU.isInt(key) && 
(JSU.toInt(key)<JSArray.this.size()));
+                       }
+                       public Enumeration iterator() throws JSExn {
+                               return new Enumeration(null) {
+                           private int n = 0;
+                           public boolean _hasNext() { return n < 
JSArray.this.size(); }
+                           public JS _next() { return JSU.N(n++); }
+                       };
+                       }
+                       protected JS remove(JS key) throws JSExn {
+                               throw new JSExn("attempted to remove from 
array");
+                       }
+                       protected JS size() throws JSExn {
+                               return JSU.N(JSArray.this.size());
+                       }
         };
+       
     }
     public JS get(JS key) throws JSExn {
         if (key == null || !JSU.isInt(key)) {

Modified: core/trunk/org.ibex.js/src/org/ibex/js/Parser.java
===================================================================
--- core/trunk/org.ibex.js/src/org/ibex/js/Parser.java  2007-03-20 13:21:05 UTC 
(rev 1742)
+++ core/trunk/org.ibex.js/src/org/ibex/js/Parser.java  2007-03-20 15:48:47 UTC 
(rev 1743)
@@ -994,7 +994,9 @@
                 consume(RP);
                 
                 b.add(parserLine, PUSHKEYS);
-                
+                b.add(parserLine, LITERAL, SC_iterator);
+                b.add(parserLine, GET_PRESERVE);
+                b.add(parserLine, CALLMETHOD, NC_0);                
                 int size = b.size;
                 b.add(parserLine, LOOP);
                 b.add(parserLine, POP);

Modified: core/trunk/org.ibex.js/src/org/ibex/js/SOAP.java
===================================================================
--- core/trunk/org.ibex.js/src/org/ibex/js/SOAP.java    2007-03-20 13:21:05 UTC 
(rev 1742)
+++ core/trunk/org.ibex.js/src/org/ibex/js/SOAP.java    2007-03-20 15:48:47 UTC 
(rev 1743)
@@ -235,7 +235,7 @@
         } else if (o instanceof JS) {
             JS j = (JS)o;
             sb.append("                <" + name + ">");
-            JS.Enumeration e = j.keys();
+            JS.Enumeration e = j.keys().iterator();
             while(e.hasNext()) {
                 Object key = e.next();
                 appendObject((String)key, j.get((JS)key), sb);
@@ -261,7 +261,7 @@
         content.append(nameSpace != null ? " xmlns=\"" + nameSpace + "\"" : 
"");
         content.append(">\r\n");
         if (args.size() > 0) {
-            JS.Enumeration e = ((JS)args.get(0)).keys();
+            JS.Enumeration e = ((JS)args.get(0)).keys().iterator();
             while(e.hasNext()) {
                 JS key = (JS)e.next();
                 appendObject(((JSString)key).coerceToString(), 
((JS)args.get(0)).get(key), content);

Modified: core/trunk/org.ibex.js/src/org/ibex/js/Scheduler.java
===================================================================
--- core/trunk/org.ibex.js/src/org/ibex/js/Scheduler.java       2007-03-20 
13:21:05 UTC (rev 1742)
+++ core/trunk/org.ibex.js/src/org/ibex/js/Scheduler.java       2007-03-20 
15:48:47 UTC (rev 1743)
@@ -23,7 +23,9 @@
        /*static public class Stop extends Exception{
                public Stop(String message){super(message);}}*/
        public static void add(Callable t) {/*Log.info(Scheduler.class, 
"scheduling " + t);*/
-               Scheduler.runnable.append(t);}
+               if(JSU.debugHandler!=null && (t instanceof 
Thread))JSU.debugHandler.threadScheduled((Thread)t);
+               Scheduler.runnable.append(t);
+       }
        public static Object init(Scheduler s) { 
                singleton = s;
                return singleton.run();

Modified: core/trunk/org.ibex.js/src/org/ibex/js/XMLRPC.jpp
===================================================================
--- core/trunk/org.ibex.js/src/org/ibex/js/XMLRPC.jpp   2007-03-20 13:21:05 UTC 
(rev 1742)
+++ core/trunk/org.ibex.js/src/org/ibex/js/XMLRPC.jpp   2007-03-20 15:48:47 UTC 
(rev 1743)
@@ -303,7 +303,7 @@
             tracker.put(o, JSU.T);
             JS j = (JS)o;
             sb.append("                <value><struct>\n");
-            Enumeration e = j.keys();
+            Enumeration e = j.keys().iterator();
             while (e.hasNext()) {
                 Object key = e.next();
                 sb.append("                <member><name>" + key + 
"</name>\n");

Modified: core/trunk/org.ibex.js/src_junit/test/js/general/keysof.js
===================================================================
--- core/trunk/org.ibex.js/src_junit/test/js/general/keysof.js  2007-03-20 
13:21:05 UTC (rev 1742)
+++ core/trunk/org.ibex.js/src_junit/test/js/general/keysof.js  2007-03-20 
15:48:47 UTC (rev 1743)
@@ -1,7 +1,7 @@
 //////
 var x = {a:"1",b:"2",c:"3"};
 var keys = keysof(x);
-assert(keys.size()==3);
+assert(keys.size==3);
 keys.remove("a");
-assert(keys.size()==2);
+assert(keys.size==2);
 assert(x.a==null);

Modified: core/trunk/org.ibex.js/src_unused/org/ibex/js/Directory.java
===================================================================
--- core/trunk/org.ibex.js/src_unused/org/ibex/js/Directory.java        
2007-03-20 13:21:05 UTC (rev 1742)
+++ core/trunk/org.ibex.js/src_unused/org/ibex/js/Directory.java        
2007-03-20 15:48:47 UTC (rev 1743)
@@ -93,7 +93,7 @@
                 out.close();
             } else {
                 Directory d2 = new Directory(f2);
-                JS.Enumeration e = val.keys();
+                JS.Enumeration e = val.keys().iterator();
                 while(e.hasNext()) {
                     JS k = e.next();
                     JS v = val.get(k);
@@ -125,12 +125,13 @@
         }
     }
 
-    public JS.Enumeration keys() {
+    public Keys keys() throws JSExn {
         final String[] elements = f.list();
-        return new JS.Enumeration(null) {
+        throw new JSExn("Needs re-implementing");
+        /*return new JS.Enumeration(null) {
                 int i = 0;
                 public boolean _hasNext() { return i < elements.length; }
                 public JS _next() { return 
JSU.S(Encode.fromFilename(elements[i++])); }
-            };
+            };*/
     }
 }

Modified: core/trunk/org.ibex.js/src_unused/org/ibex/js/JSReflection.java
===================================================================
--- core/trunk/org.ibex.js/src_unused/org/ibex/js/JSReflection.java     
2007-03-20 13:21:05 UTC (rev 1742)
+++ core/trunk/org.ibex.js/src_unused/org/ibex/js/JSReflection.java     
2007-03-20 15:48:47 UTC (rev 1743)
@@ -23,7 +23,7 @@
         private final Object o;
         public Wrapper(Object o) { this.o = o; }
         public Object unwrap() { return o; }
-        public Enumeration keys() throws JSExn { throw new 
JSExn("JSReflection.keys() not supported yet"); }
+        public Keys keys() throws JSExn { throw new JSExn("JSReflection.keys() 
not supported yet"); }
         public JS get(JS key) throws JSExn {
             String k = JSU.toString(key);
             Class c = o.getClass();
@@ -71,17 +71,18 @@
         final Object[] arr;
         public Array(Object[] arr) { this.arr = arr; }
         // FEATURE: Add a JSCounterEnumeration
-        public Enumeration keys() throws JSExn {
-            return new Enumeration(null) {
+        public Keys keys() throws JSExn {
+               throw new JSExn("Needs re-implementing!");
+               /*return new Enumeration(null) {
                 private int n = 0;
                 public boolean _hasNext() { return n < arr.length; }
                 public JS _next() { return JSU.N(n++); }
-            };
+            };*/
         }
         public JS get(JS key) throws JSExn { return wrap(arr[JSU.toInt(key)]); 
}
     }
 
-    public Enumeration keys() throws JSExn { throw new 
JSExn("JSReflection.keys() not supported yet"); }
+    public Keys keys() throws JSExn { throw new JSExn("JSReflection.keys() not 
supported yet"); }
 
     public JS get(JS key) throws JSExn {
         String k = JSU.toString(key);


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Vexi-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/vexi-svn

Reply via email to