[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Cursors/Iterators



Hi,

This is a beginner question - i am having real trouble getting some kind of 
cursor to work, in the class below every time next() is called it returns 
the first element from the iterator, not progressing to the second element 
and never reaching the end of the list.

(...surely there must be a better way of designing cursors/iterators)

PS I was looking at the way new objects are added to the database - from 
another project(a compiler) i have some classes to create classfiles on the 
fly(ie make the *Proxy classes on the run) which would remove the need for 
the dependency on sun.tools.javac and opp if anybody is interested.

- Robert

public class PRICESImpl extends OzoneObject implements PRICES {

     DxHashMap records = new DxHashMap();
     DxHashMap cursors = new DxHashMap();

     public String get(String key) {
         return (String)records.elementForKey(key);
     }

     public String getCursor() {
         String cursor = "Cursor_" + ((int)(Math.random() * 10000));
         cursors.addForKey(records.iterator(), cursor);
         return cursor;
     }

     public String next(String key) {
         DxIterator i = (DxIterator)cursors.elementForKey(key);
         if (i == null || i.next() == null) return null;
         cursors.removeForKey(key);  //for some reason this is needed
         cursors.addForKey(i, key);
         return (String)i.key();
     }

     public void set(String key, String val) {
         records.addForKey(val, key);
     }
}