[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[ff-cvs] fenfire/org/fenfire/util/lava Traversals.java
From: |
Tuukka Hastrup |
Subject: |
[ff-cvs] fenfire/org/fenfire/util/lava Traversals.java |
Date: |
Fri, 15 Aug 2003 19:04:03 -0400 |
CVSROOT: /cvsroot/fenfire
Module name: fenfire
Branch:
Changes by: Tuukka Hastrup <address@hidden> 03/08/15 19:04:03
Modified files:
org/fenfire/util/lava: Traversals.java
Log message:
added concat Iterator for non-directed properties
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/fenfire/fenfire/org/fenfire/util/lava/Traversals.java.diff?tr1=1.1&tr2=1.2&r1=text&r2=text
Patches:
Index: fenfire/org/fenfire/util/lava/Traversals.java
diff -u fenfire/org/fenfire/util/lava/Traversals.java:1.1
fenfire/org/fenfire/util/lava/Traversals.java:1.2
--- fenfire/org/fenfire/util/lava/Traversals.java:1.1 Fri Aug 15 17:49:50 2003
+++ fenfire/org/fenfire/util/lava/Traversals.java Fri Aug 15 19:04:03 2003
@@ -14,6 +14,38 @@
static class CollisionException extends Exception {
}
+ /** Returns an iterator of nodes directly connected to a given node
+ * along a given non-directional property.
+ */
+ static Iterator findConnected_Iter(ConstGraph g, Object node,
+ Object property) {
+ return concat(g.findN_X11_Iter(property, node), // subjects
+ g.findN_11X_Iter(node, property)); // objects
+ }
+
+ /** Returns an iterator that iterates given iterators one after the other.
+ */
+ static Iterator concat(final Iterator first, final Iterator second) {
+ return new Iterator() {
+ Iterator active = first;
+ public boolean hasNext() {
+ if(active.hasNext())
+ return true;
+ if(active != second)
+ return second.hasNext();
+ return false;
+ }
+ public Object next() {
+ if(!active.hasNext() && active != second)
+ active = second;
+ return active.next();
+ }
+ public void remove() {
+ active.remove();
+ }
+ };
+ }
+
/** Tests whether a given nondirected property connects the two
nodes given. The method is to run BFS from both nodes simultaneously
and see whether they collide. */
@@ -53,13 +85,13 @@
while(active.hasNext()) {
Object node = active.next();
- iterateConns(g.findN_11X_Iter(node, property), visited, activated,
obstacles);
- iterateConns(g.findN_X11_Iter(property, node), visited, activated,
obstacles);
+ iterateConns(findConnected_Iter(g, node, property), visited,
activated, obstacles);
}
return activated;
}
- /** Iterates connections from some node to visit new nodes. */
+ /** Iterates connections from some node to visit new nodes.
+ XXX Is this really reusable as it is ?-) */
static void iterateConns(Iterator conns, Set visited, Set activated,
Set obstacles) throws CollisionException {
while(conns.hasNext()) {
@@ -72,4 +104,5 @@
}
}
}
+
}
- [ff-cvs] fenfire/org/fenfire/util/lava Traversals.java,
Tuukka Hastrup <=