gzz-commits
[Top][All Lists]
Advanced

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

[Gzz-commits] gzz/lava gzz/loom/Cursor.java test/gzz/loom/Cur...


From: Benja Fallenstein
Subject: [Gzz-commits] gzz/lava gzz/loom/Cursor.java test/gzz/loom/Cur...
Date: Sun, 23 Feb 2003 18:00:55 -0500

CVSROOT:        /cvsroot/gzz
Module name:    gzz
Changes by:     Benja Fallenstein <address@hidden>      03/02/23 18:00:55

Modified files:
        lava/gzz/loom  : Cursor.java 
        lava/test/gzz/loom: Cursor.test 

Log message:
        fixes; basic browsing works now

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/lava/gzz/loom/Cursor.java.diff?tr1=1.6&tr2=1.7&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/lava/test/gzz/loom/Cursor.test.diff?tr1=1.4&tr2=1.5&r1=text&r2=text

Patches:
Index: gzz/lava/gzz/loom/Cursor.java
diff -u gzz/lava/gzz/loom/Cursor.java:1.6 gzz/lava/gzz/loom/Cursor.java:1.7
--- gzz/lava/gzz/loom/Cursor.java:1.6   Sun Feb 23 16:11:34 2003
+++ gzz/lava/gzz/loom/Cursor.java       Sun Feb 23 18:00:54 2003
@@ -63,8 +63,12 @@
      *  this returns 2.
      */
     public int getRotationIndex() {
-       if(rotation != null)
+       if(rotation == null)
+           return 0;
+       else if(getConnections(1).contains(rotation))
            return getConnections(1).headSet(rotation).size();
+       else if(getConnections(-1).contains(rotation))
+           return getConnections(-1).headSet(rotation).size();
        else
            return 0;
     }
@@ -100,33 +104,45 @@
      *  This moves the rotation of the cursor one step up or down. XXX
      */
     public void rotate(int dir) {
-       SortedSet s = getConnections(1);
-       if(dir < 0) {
-           try {
-               rotation = (RDFNode)s.headSet(rotation).last();
-           } catch(NoSuchElementException _) {
-           }
-       } else if(dir > 0) {
-           Iterator i = s.tailSet(rotation).iterator();
-           if(!i.hasNext()) return; i.next();
-           if(!i.hasNext()) return;
-           rotation = (RDFNode)i.next();
+       SortedSet 
+           neg = getConnections(-1),
+           pos = getConnections(1);
+
+       int i = getRotationIndex();
+
+       if(dir < 0) i--;
+       else i++;
+
+       if(i < 0) return;
+       if(i >= getConnections(-1).size() &&
+          i >= getConnections(1).size()) return;
+
+       List l;
+       if(pos.contains(rotation)) {
+           if(pos.size() > i)
+               l = new ArrayList(pos);
+           else
+               l = new ArrayList(neg);
+       } else {
+           if(neg.size() > i)
+               l = new ArrayList(neg);
+           else
+               l = new ArrayList(pos);
        }
+
+       rotation = (RDFNode)l.get(i);
     }
 
     /** Move left/right. XXX
      */ 
     public void move(int dir) {
-       if(dir < 0) {
-           rotation = focus;
-           focus = (Resource)getConnections(-1).first();
-       } else {
-           focus = (Resource)rotation;
-           try {
-               rotation = (RDFNode)getConnections(1).first();
-           } catch(NoSuchElementException _) {
-               rotation = null;
-           }
-       }
+       Iterator iter = getConnections(dir).iterator();
+       int n = getRotationIndex();
+       for(int i=0; i<n; i++) if(iter.hasNext()) iter.next();
+       if(!iter.hasNext())
+           // cannot move there
+           return;
+       rotation = focus;
+       focus = (Resource)iter.next();
     }
 }
Index: gzz/lava/test/gzz/loom/Cursor.test
diff -u gzz/lava/test/gzz/loom/Cursor.test:1.4 
gzz/lava/test/gzz/loom/Cursor.test:1.5
--- gzz/lava/test/gzz/loom/Cursor.test:1.4      Sun Feb 23 16:11:35 2003
+++ gzz/lava/test/gzz/loom/Cursor.test  Sun Feb 23 18:00:55 2003
@@ -35,6 +35,8 @@
 
 class Cmp(java.util.Comparator):
     def compare(self, r1, r2):
+        if (not r1) or (not r2):
+            raise java.lang.NullPointerException("r1=%r, r2=%r" % (r1, r2))
         return n.index(r1) - n.index(r2)
 c = gzz.loom.Cursor(Cmp())
 
@@ -78,6 +80,44 @@
     assert c.getRotationIndex() == 0
 
 
+def testRotateMoveLeft():
+    n[4].addProperty(p, n[5])
+    n[6].addProperty(p, n[5])
+
+    c.set(n[5], n[4])
+
+    assert c.getRotationIndex() == 1
+    c.rotate(-1)
+    assert c.getRotationIndex() == 0
+    assert c.rotation == n[2]
+    c.rotate(-1)
+    assert c.getRotationIndex() == 0
+    c.rotate(1)
+    assert c.getRotationIndex() == 1
+    c.rotate(1)
+    assert c.getRotationIndex() == 2
+    c.rotate(1)
+    assert c.getRotationIndex() == 2
+    assert c.rotation == n[6]
+
+    c.set(n[5], None)
+
+    assert c.getRotationIndex() == 0
+    c.rotate(-1)
+    assert c.getRotationIndex() == 0
+    c.rotate(1)
+    assert c.getRotationIndex() == 1
+    assert c.rotation == n[4]
+
+    c.set(n[5], None)
+    c.rotate(1)
+    assert c.getRotationIndex() == 1
+    assert c.rotation == n[4]
+
+    c.move(-1)
+    assert c.focus == n[4] and c.rotation == n[5]
+    
+
 def testRotateMove():
     c.set(n[2], n[5])
     c.rotate(1)
@@ -97,6 +137,15 @@
     c.rotate(1)
     assert c.focus == n[2] and c.rotation == n[9]
 
+    c.set(n[2], n[1])
+    assert c.getRotationIndex() == 0
+    c.rotate(1)
+    assert c.getRotationIndex() == 1
+    c.rotate(1)
+    assert c.getRotationIndex() == 2
+    c.move(1)
+    assert c.focus == n[5] and c.rotation == n[2]
+
     c.set(n[2], n[3])
     c.rotate(-1)
     assert c.focus == n[2] and c.rotation == n[3]
@@ -106,6 +155,17 @@
     c.move(-1)
     assert c.focus == n[0] and c.rotation == n[1]
     c.move(1)
-    assert c.focus == n[1] and c.rotation == n[2]
+    assert c.focus == n[1] and c.rotation == n[0]
     c.move(1)
-    assert c.focus == n[2] and c.rotation == n[3]
+    assert c.focus == n[2] and c.rotation == n[1]
+
+
+    # if we cannot move there, we remain where we are:
+
+    c.set(n[2], n[7])
+    c.move(-1)
+    assert c.focus == n[2] and c.rotation == n[7]
+
+    c.set(n[0], n[1])
+    c.move(-1)
+    assert c.focus == n[0] and c.rotation == n[1]




reply via email to

[Prev in Thread] Current Thread [Next in Thread]