From de9f279ed454e67e395a439b1b82aa5dab936b4d Mon Sep 17 00:00:00 2001 From: Vincent Batts Date: Fri, 9 Nov 2012 16:26:43 -0500 Subject: [PATCH] fixing the PathNode.includes() --- src/main/java/com/redhat/trie/PathNode.java | 19 +++++++++---------- .../java/com/redhat/trie/TestPathNode.java | 8 +++++--- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/redhat/trie/PathNode.java b/src/main/java/com/redhat/trie/PathNode.java index c11b1ba..e57c663 100644 --- a/src/main/java/com/redhat/trie/PathNode.java +++ b/src/main/java/com/redhat/trie/PathNode.java @@ -218,8 +218,6 @@ public class PathNode { /** * check whether current PathNode, includes the paths in PathNode that, like a mask. * - * FIXME This is not working correctly yet - * * @param that PathNode to check for * @return boolean of truth! */ @@ -234,20 +232,21 @@ public class PathNode { List found = new ArrayList(); boolean result; - for (NodePair thisnp : this.getChildren()) { - for (NodePair thatnp : that.getChildren()) { - // keep checking, even if we hist a variablized value - if (thisnp.getName().startsWith("$") || thisnp.getName().equals(thatnp.getName())) { + for (NodePair thatnp : that.getChildren()) { + for (NodePair thisnp : this.getChildren()) { + // keep checking, even if we hit a variablized value + if ( thatnp.getName().startsWith("$") || + thisnp.getName().startsWith("$") || + thisnp.getName().equals(thatnp.getName()) ) { result = thisnp.getConnection().includes(thatnp.getConnection()); found.add(new Boolean(result).booleanValue()); - log.debug("includes: " + thisnp + " == " + thatnp); - break; + log.debug("includes: this: " + thisnp.getName() + " == that:" + thatnp.getName()); } - found.add(Boolean.FALSE); } } - return (!found.contains(Boolean.FALSE)); + // return true, if we've found all of thats children + return (found.size() == that.getChildren().size()); } /** diff --git a/src/test/java/com/redhat/trie/TestPathNode.java b/src/test/java/com/redhat/trie/TestPathNode.java index 694c4ac..6edbe53 100644 --- a/src/test/java/com/redhat/trie/TestPathNode.java +++ b/src/test/java/com/redhat/trie/TestPathNode.java @@ -62,12 +62,15 @@ public class TestPathNode { List contents1 = TestHelpers.loadContents(this, "contents_small.list"); try { + // this will be the authority pt0.setContentSets(contents0); pn0 = pt0.getRootPathNode(); // setup the larger PathNode + // small tree, that is a subset of the contents in the authority pt1.setContentSets(contents1); pn1 = pt1.getRootPathNode(); // setup the small PathNode + // of that small tree, add an entry that is _not_ in the authority contents1.add(new String("/this/is/not/in/the/list")); pt2.setContentSets(contents1); pn2 = pt2.getRootPathNode(); // setup the small PathNode @@ -79,9 +82,8 @@ public class TestPathNode { assertNotNull(pn1); assertNotNull(pn2); - // FIXME - Finish the test first - //assertTrue(pn0.includes(pn1)); - //assertFalse(pn0.includes(pn2)); + assertTrue(pn0.includes(pn1)); + assertFalse(pn0.includes(pn2)); } }