working on the PathNode includes() logic, and moar documentation and
unit testing
This commit is contained in:
parent
f06d01718a
commit
4dbdeb4916
7 changed files with 241 additions and 60 deletions
45
pom.xml
45
pom.xml
|
@ -29,6 +29,51 @@
|
||||||
<target>1.6</target>
|
<target>1.6</target>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-javadoc-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<tags>
|
||||||
|
<tag>
|
||||||
|
<name>methodundertest</name>
|
||||||
|
<placement>m</placement>
|
||||||
|
<head>Method Under Test:</head>
|
||||||
|
</tag>
|
||||||
|
<tag>
|
||||||
|
<name>servicesused</name>
|
||||||
|
<placement>m</placement>
|
||||||
|
<head>Services Used:</head>
|
||||||
|
</tag>
|
||||||
|
<tag>
|
||||||
|
<name>testdescription</name>
|
||||||
|
<placement>m</placement>
|
||||||
|
<head>Description of Test:</head>
|
||||||
|
</tag>
|
||||||
|
<tag>
|
||||||
|
<name>datadependencies</name>
|
||||||
|
<placement>m</placement>
|
||||||
|
<head>Data Dependencies:</head>
|
||||||
|
</tag>
|
||||||
|
<tag>
|
||||||
|
<name>inputs</name>
|
||||||
|
<placement>m</placement>
|
||||||
|
<head>Inputs:</head>
|
||||||
|
</tag>
|
||||||
|
<tag>
|
||||||
|
<name>externalconsumers</name>
|
||||||
|
<placement>m</placement>
|
||||||
|
<head>External Consumers:</head>
|
||||||
|
</tag>
|
||||||
|
<tag>
|
||||||
|
<name>expectedresults</name>
|
||||||
|
<placement>m</placement>
|
||||||
|
<head>Expected Results:</head>
|
||||||
|
</tag>
|
||||||
|
</tags>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-jar-plugin</artifactId>
|
<artifactId>maven-jar-plugin</artifactId>
|
||||||
|
|
|
@ -36,6 +36,9 @@ public class NodePair implements Comparable {
|
||||||
this.connection = connection;
|
this.connection = connection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* pretty information
|
||||||
|
*/
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "Name: " + name + ", Connection: " + connection.getId();
|
return "Name: " + name + ", Connection: " + connection.getId();
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,7 +74,7 @@ public class PathNode {
|
||||||
/*
|
/*
|
||||||
* same number of children with the same names for child nodes
|
* same number of children with the same names for child nodes
|
||||||
*/
|
*/
|
||||||
boolean isEquivalentTo(PathNode that) {
|
public boolean isEquivalentTo(PathNode that) {
|
||||||
if (this.getChildren().size() != that.getChildren().size()) {
|
if (this.getChildren().size() != that.getChildren().size()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -95,6 +95,47 @@ public class PathNode {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* check whether current PathNode, includes the paths in PathNode that, like a mask.
|
||||||
|
*
|
||||||
|
* TODO - this is a stub
|
||||||
|
*
|
||||||
|
* @param that PathNode to check for
|
||||||
|
* @return boolean of truth!
|
||||||
|
*/
|
||||||
|
public boolean includes(PathNode that) {
|
||||||
|
// if we are at the end of the tree we're checking against,
|
||||||
|
// then it includes everything up to this point.
|
||||||
|
if (this.getChildren().size() == 0 || that.getChildren().size() == 0) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// why can java allow a list of primitives ...
|
||||||
|
List<Boolean> found = new ArrayList<Boolean>();
|
||||||
|
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())) {
|
||||||
|
result = thisnp.getConnection().includes(thatnp.getConnection());
|
||||||
|
found.add(new Boolean(result).booleanValue());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
found.add(Boolean.FALSE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (found.contains(Boolean.FALSE)) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* pretty information
|
||||||
|
*/
|
||||||
public String toString() {
|
public String toString() {
|
||||||
String parentList = "";
|
String parentList = "";
|
||||||
for (PathNode parent : parents) {
|
for (PathNode parent : parents) {
|
||||||
|
|
|
@ -112,8 +112,8 @@ public class PathTree {
|
||||||
*/
|
*/
|
||||||
public void setPayload(byte[] payload) {
|
public void setPayload(byte[] payload) {
|
||||||
this.modified = true;
|
this.modified = true;
|
||||||
setNodeBits(null);
|
this.setNodeBits(null);
|
||||||
setNodeCount(0);
|
this.setNodeCount(0);
|
||||||
|
|
||||||
this.pathNodeContext = new NodeContext();
|
this.pathNodeContext = new NodeContext();
|
||||||
this.huffNodeContext = new NodeContext();
|
this.huffNodeContext = new NodeContext();
|
||||||
|
@ -190,10 +190,10 @@ public class PathTree {
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
throw new PayloadException();
|
throw new PayloadException();
|
||||||
}
|
}
|
||||||
setDictOffset(inf.getBytesRead());
|
this.setDictOffset(inf.getBytesRead());
|
||||||
|
|
||||||
int weight = 1;
|
int weight = 1;
|
||||||
for (String name : byteArrayToStringList(baos.toByteArray())) {
|
for (String name : this.byteArrayToStringList(baos.toByteArray())) {
|
||||||
this.pathDictionary.add(new HuffNode(getHuffNodeContext(), name, weight++));
|
this.pathDictionary.add(new HuffNode(getHuffNodeContext(), name, weight++));
|
||||||
}
|
}
|
||||||
this.pathDictionary.add(new HuffNode(HuffNode.END_NODE, weight));
|
this.pathDictionary.add(new HuffNode(HuffNode.END_NODE, weight));
|
||||||
|
@ -210,17 +210,18 @@ public class PathTree {
|
||||||
*/
|
*/
|
||||||
private List<HuffNode> getNodeDictionary() throws PayloadException {
|
private List<HuffNode> getNodeDictionary() throws PayloadException {
|
||||||
if (this.pathDictionary == null) {
|
if (this.pathDictionary == null) {
|
||||||
getPathDictionary(); // this has to run before the nodeDictionary bits are ready
|
this.getPathDictionary(); // this has to run before the nodeDictionary bits are ready
|
||||||
}
|
}
|
||||||
if (this.modified || this.pathDictionary == null || this.nodeDictionary == null) {
|
if (this.modified || this.pathDictionary == null || this.nodeDictionary == null) {
|
||||||
this.nodeDictionary = new ArrayList<HuffNode>();
|
this.nodeDictionary = new ArrayList<HuffNode>();
|
||||||
setNodeBits(new StringBuffer());
|
this.setNodeBits(new StringBuffer());
|
||||||
|
|
||||||
ByteArrayInputStream bais = new ByteArrayInputStream(getPayload(),
|
ByteArrayInputStream bais = new ByteArrayInputStream(this.getPayload(),
|
||||||
(new Long(getDictOffset())).intValue(), (new Long(getPayload().length - getDictOffset()).intValue()));
|
(new Long(this.getDictOffset())).intValue(),
|
||||||
|
(new Long(this.getPayload().length - this.getDictOffset()).intValue()));
|
||||||
int value = bais.read();
|
int value = bais.read();
|
||||||
// check for size bits
|
// check for size bits
|
||||||
setNodeCount(value);
|
this.setNodeCount(value);
|
||||||
if (value > 127) {
|
if (value > 127) {
|
||||||
byte[] count = new byte[value - 128];
|
byte[] count = new byte[value - 128];
|
||||||
try {
|
try {
|
||||||
|
@ -232,7 +233,7 @@ public class PathTree {
|
||||||
for (int k = 0; k < value - 128; k++) {
|
for (int k = 0; k < value - 128; k++) {
|
||||||
total = (total << 8) | (count[k] & 0xFF);
|
total = (total << 8) | (count[k] & 0xFF);
|
||||||
}
|
}
|
||||||
setNodeCount(total);
|
this.setNodeCount(total);
|
||||||
}
|
}
|
||||||
value = bais.read();
|
value = bais.read();
|
||||||
while (value != -1) {
|
while (value != -1) {
|
||||||
|
@ -240,11 +241,11 @@ public class PathTree {
|
||||||
for (int pad = 0; pad < 8 - someBits.length(); pad++) {
|
for (int pad = 0; pad < 8 - someBits.length(); pad++) {
|
||||||
this.nodeBits.append("0");
|
this.nodeBits.append("0");
|
||||||
}
|
}
|
||||||
this.nodeBits.append(someBits);
|
this.getNodeBits().append(someBits);
|
||||||
value = bais.read();
|
value = bais.read();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int j = 0; j < getNodeCount(); j++) {
|
for (int j = 0; j < this.getNodeCount(); j++) {
|
||||||
this.nodeDictionary.add(new HuffNode(new PathNode(getPathNodeContext()), j));
|
this.nodeDictionary.add(new HuffNode(new PathNode(getPathNodeContext()), j));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -319,7 +320,7 @@ public class PathTree {
|
||||||
public void setContentSets(List<String> contentSets) throws PayloadException {
|
public void setContentSets(List<String> contentSets) throws PayloadException {
|
||||||
this.modified = true;
|
this.modified = true;
|
||||||
this.nodeBits = null;
|
this.nodeBits = null;
|
||||||
setNodeCount(0);
|
this.setNodeCount(0);
|
||||||
|
|
||||||
this.pathNodeContext = new NodeContext();
|
this.pathNodeContext = new NodeContext();
|
||||||
this.huffNodeContext = new NodeContext();
|
this.huffNodeContext = new NodeContext();
|
||||||
|
@ -365,9 +366,9 @@ public class PathTree {
|
||||||
PathNode endMarker = new PathNode(new NodeContext());
|
PathNode endMarker = new PathNode(new NodeContext());
|
||||||
for (String path : contents) {
|
for (String path : contents) {
|
||||||
StringTokenizer st = new StringTokenizer(path, "/");
|
StringTokenizer st = new StringTokenizer(path, "/");
|
||||||
makePathForURL(st, parent, endMarker);
|
this.makePathForURL(st, parent, endMarker);
|
||||||
}
|
}
|
||||||
condenseSubTreeNodes(endMarker);
|
this.condenseSubTreeNodes(endMarker);
|
||||||
return parent;
|
return parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -768,7 +769,7 @@ public class PathTree {
|
||||||
for (NodePair child : parent.getChildren()) {
|
for (NodePair child : parent.getChildren()) {
|
||||||
if (child.getName().equals(childVal) &&
|
if (child.getName().equals(childVal) &&
|
||||||
!child.getConnection().equals(endMarker)) {
|
!child.getConnection().equals(endMarker)) {
|
||||||
makePathForURL(st, child.getConnection(), endMarker);
|
this.makePathForURL(st, child.getConnection(), endMarker);
|
||||||
isNew = false;
|
isNew = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -778,7 +779,7 @@ public class PathTree {
|
||||||
next = new PathNode(parent.getContext());
|
next = new PathNode(parent.getContext());
|
||||||
parent.addChild(new NodePair(childVal, next));
|
parent.addChild(new NodePair(childVal, next));
|
||||||
next.addParent(parent);
|
next.addParent(parent);
|
||||||
makePathForURL(st, next, endMarker);
|
this.makePathForURL(st, next, endMarker);
|
||||||
} else {
|
} else {
|
||||||
parent.addChild(new NodePair(childVal, endMarker));
|
parent.addChild(new NodePair(childVal, endMarker));
|
||||||
if (!endMarker.getParents().contains(parent)) {
|
if (!endMarker.getParents().contains(parent)) {
|
||||||
|
|
18
src/test/java/com/redhat/trie/TestNodePair.java
Normal file
18
src/test/java/com/redhat/trie/TestNodePair.java
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
package com.redhat.trie;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class TestNodePair {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testNew0() {
|
||||||
|
NodePair np = new NodePair("foo", new PathNode());
|
||||||
|
assertNotNull(np);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
23
src/test/java/com/redhat/trie/TestPathNode.java
Normal file
23
src/test/java/com/redhat/trie/TestPathNode.java
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
package com.redhat.trie;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class TestPathNode {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testNew0() {
|
||||||
|
PathNode pn = new PathNode();
|
||||||
|
assertNotNull(pn);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testNew1() {
|
||||||
|
PathNode pn = new PathNode(new NodeContext());
|
||||||
|
assertNotNull(pn);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
50
src/test/java/com/redhat/trie/TestPathTree.java
Normal file
50
src/test/java/com/redhat/trie/TestPathTree.java
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
package com.redhat.trie;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class TestPathTree {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testNew0() {
|
||||||
|
PathTree pt = new PathTree();
|
||||||
|
assertNotNull(pt);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testNew1() {
|
||||||
|
PathTree pt = new PathTree();
|
||||||
|
assertNotNull(pt);
|
||||||
|
}
|
||||||
|
|
||||||
|
private InputStream resStream(String filename) {
|
||||||
|
return getClass().getClassLoader().getResourceAsStream(filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<String> loadContents(String filename) throws IOException {
|
||||||
|
String content;
|
||||||
|
List<String> contentList = new ArrayList<String>();
|
||||||
|
InputStream in = resStream(filename);
|
||||||
|
BufferedReader br = new BufferedReader(new InputStreamReader(in));
|
||||||
|
|
||||||
|
try {
|
||||||
|
while ((content = br.readLine()) != null) {
|
||||||
|
contentList.add(content);
|
||||||
|
}
|
||||||
|
} catch (IOException ex) {
|
||||||
|
throw ex;
|
||||||
|
}
|
||||||
|
return contentList;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue