Commit in lcsim/src/org/lcsim/util/aida on MAIN
AidaCursor.java+40-191.2 -> 1.3


lcsim/src/org/lcsim/util/aida
AidaCursor.java 1.2 -> 1.3
diff -u -r1.2 -r1.3
--- AidaCursor.java	9 Feb 2007 22:57:31 -0000	1.2
+++ AidaCursor.java	13 Feb 2007 00:43:05 -0000	1.3
@@ -12,7 +12,7 @@
  * file's contents sequentially.
  * 
  * @author jeremym
- * @version $Id: AidaCursor.java,v 1.2 2007/02/09 22:57:31 jeremy Exp $
+ * @version $Id: AidaCursor.java,v 1.3 2007/02/13 00:43:05 jeremy Exp $
  */
 public class AidaCursor
 {    
@@ -25,14 +25,14 @@
 
     /**
      * Create a cursor from a filepath.
-     * Sets the tree variable.
      * @param filepath
      */
     public AidaCursor(String filepath)
     {    
         this.filepath=filepath;
         try {
-            setup(open(this.filepath));
+            ITree tree = open(this.filepath);
+            setup(tree);
         }
         catch ( Throwable x )
         {
@@ -42,12 +42,11 @@
 
     /**
      * Create a cursor from an ITree.
-     * Sets the tree variable.
      * @param tree
      */
     public AidaCursor(ITree tree)
     {
-        setup(this.tree);
+        setup(tree);
     }
 
     /**
@@ -62,7 +61,7 @@
     }
 
     /**
-     * Setup the cursor from an ITree.
+     * Setup this cursor from an open ITree. 
      * @param tree An AIDA ITree.
      */
     private void setup(ITree tree)
@@ -71,7 +70,7 @@
         objectNames = this.tree.listObjectNames("/",true);
         nnames=objectNames.length;
         objectTypes = this.tree.listObjectTypes("/",true);
-        seek(0);
+        reset();
     }
 
     /**
@@ -129,33 +128,44 @@
     }
 
     /**
-     * Increment the position by 1.
-     * @return The new position.
+     * Increment the position by 1, skipping directories.
+     * @return The next position that is an AIDA object or end.
      */
     public int next()
     {
-        if (currentIndex < nnames)
+        while (currentIndex < end())
         {
             currentIndex += 1;
+                       
+            if (position() == end() || !isdir())
+            {
+                break;
+            }
         }
         return position();
     }
 
     /**
-     * Decrement the position by 1.
-     * @return The next position.
+     * Decrement the position by 1, skipping directories.
+     * @return The first previous position that is an AIDA object or begin.
      */
     public int prev()
     {
-        if (currentIndex > begin())
+        while (currentIndex > begin() )
         {
             currentIndex -= 1;
+            
+            if (position() == end() || !isdir())
+            {
+                break;
+            }
         }       
         return position();
     }
 
     /**
-     * Return the begin position.  Does not set position.
+     * Return the begin position, or 0.  
+     * Does not set position.
      * @return The begin position.
      */
     public int begin()
@@ -164,7 +174,8 @@
     }
 
     /**
-     * Return the end position.  Does not set position.
+     * Return the end position, or size of names array.  
+     * Does not set position.
      * @return The end position.
      */
     public int end()
@@ -182,7 +193,7 @@
     }
 
     /**
-     * Go to position.
+     * Go to first object at position or greater.
      * @param idx The new index.
      * @return The new position.
      */
@@ -190,7 +201,7 @@
     {
         if (idx < end())
         {
-            currentIndex=idx;
+            currentIndex=idx;           
         }
         else {
             currentIndex=end();
@@ -204,7 +215,12 @@
      */
     public int reset() 
     {
-        return seek(begin());
+        seek(begin());
+        if (isdir())
+        {
+            next();
+        }
+        return position();
     }
 
     /**
@@ -213,7 +229,12 @@
      */
     public boolean isdir()
     {
-        return position() != end() && object().getClass() != IManagedObject.class;
+        boolean isdir=false;
+        if (position() != end())
+        {
+            isdir = (objectTypes[position()].compareTo("dir") == 0); 
+        }
+        return isdir;
     }
     
     /**
CVSspam 0.2.8