Moar progress!
* adding logging, at least for a minute * working through the PathTree.validate(path) logic * BUG: in the populate tree path, calling a stringbuffer charAt(0) * moar unit testing to iron things out.
This commit is contained in:
parent
d12655d4db
commit
49c606be4d
9 changed files with 155 additions and 13 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -3,3 +3,5 @@
|
|||
Session.vim
|
||||
build/
|
||||
dist/
|
||||
out/
|
||||
target/
|
||||
|
|
BIN
lib/log4j-1.2.15.jar
Normal file
BIN
lib/log4j-1.2.15.jar
Normal file
Binary file not shown.
30
pom.xml
30
pom.xml
|
@ -17,6 +17,36 @@
|
|||
<artifactId>bcprov-jdk16</artifactId>
|
||||
<version>1.44</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>log4j</groupId>
|
||||
<artifactId>log4j</artifactId>
|
||||
<version>1.2.15</version>
|
||||
<scope>compile</scope>
|
||||
<!--
|
||||
log4j's metadata pulls in broken and useless deps:
|
||||
http://stackoverflow.com/questions/2310633/maven-dependency-log4j-error
|
||||
-->
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>com.sun.jdmk</groupId>
|
||||
<artifactId>jmxtools</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>com.sun.jmx</groupId>
|
||||
<artifactId>jmxri</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>javax.jms</groupId>
|
||||
<artifactId>jms</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>javax.mail</groupId>
|
||||
<artifactId>mail</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
|
2
run.sh
2
run.sh
|
@ -1,7 +1,7 @@
|
|||
#!/bin/sh
|
||||
|
||||
java \
|
||||
-cp ./lib/bcprov-jdk16-1.46.jar:$(ls -rt ./target/*jar | tail -1) \
|
||||
-cp $(find lib/ -type f -printf "./%h/%f:")$(ls -rt ./target/*jar | tail -1) \
|
||||
com.hashbangbash.trie.App \
|
||||
./src/test/resources/test-certv3.pem
|
||||
|
||||
|
|
|
@ -42,11 +42,11 @@ public class PathNode {
|
|||
return this.ctx;
|
||||
}
|
||||
|
||||
void addChild(NodePair cp) {
|
||||
public void addChild(NodePair cp) {
|
||||
this.children.add(cp);
|
||||
}
|
||||
|
||||
void addParent(PathNode cp) {
|
||||
public void addParent(PathNode cp) {
|
||||
if (!parents.contains(cp)) {
|
||||
this.parents.add(cp);
|
||||
}
|
||||
|
@ -57,15 +57,15 @@ public class PathNode {
|
|||
return this.children;
|
||||
}
|
||||
|
||||
List<PathNode> getParents() {
|
||||
public List<PathNode> getParents() {
|
||||
return this.parents;
|
||||
}
|
||||
|
||||
void setParents(List<PathNode> parents) {
|
||||
public void setParents(List<PathNode> parents) {
|
||||
this.parents = parents;
|
||||
}
|
||||
|
||||
void addParents(List<PathNode> parents) {
|
||||
public void addParents(List<PathNode> parents) {
|
||||
for (PathNode pn : parents) {
|
||||
addParent(pn);
|
||||
}
|
||||
|
|
|
@ -34,6 +34,8 @@ import java.util.zip.Deflater;
|
|||
import java.util.zip.DeflaterOutputStream;
|
||||
import java.util.zip.DataFormatException;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
/**
|
||||
* PathTree
|
||||
*
|
||||
|
@ -42,6 +44,7 @@ import java.util.zip.DataFormatException;
|
|||
* TODO - this is a prototype stub
|
||||
*/
|
||||
public class PathTree {
|
||||
private static org.apache.log4j.Logger log = Logger.getLogger(PathTree.class);
|
||||
private List<HuffNode> nodeDictionary;
|
||||
private List<HuffNode> pathDictionary;
|
||||
private StringBuffer nodeBits; // TODO make a smart getter for this
|
||||
|
@ -303,6 +306,40 @@ public class PathTree {
|
|||
* TODO - this is a stub
|
||||
*/
|
||||
public boolean validate(String contentPath) {
|
||||
StringTokenizer st = new StringTokenizer(contentPath, "/");
|
||||
PathNode root;
|
||||
PathNode pn;
|
||||
String curTok;
|
||||
|
||||
try {
|
||||
root = this.getRootPathNode();
|
||||
} catch (PayloadException ex) {
|
||||
log.error(ex);
|
||||
return false;
|
||||
}
|
||||
|
||||
pn = root;
|
||||
while (st.hasMoreTokens()) {
|
||||
curTok = st.nextToken();
|
||||
|
||||
for (NodePair np : pn.getChildren()) {
|
||||
if (curTok.equals(np.getName()) || np.getName().startsWith("$")) {
|
||||
//System.out.println("[" + curTok + "] == [" + np.getName() + "]");
|
||||
if (np.getConnection().getChildren().size() == 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
pn = np.getConnection();
|
||||
break;
|
||||
}
|
||||
}
|
||||
// XXX do hot stuff
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean matches(PathNode pn, StringTokenizer st) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -321,7 +358,7 @@ public class PathTree {
|
|||
this.pathNodeContext = new NodeContext();
|
||||
this.huffNodeContext = new NodeContext();
|
||||
|
||||
PathNode treeRoot = makePathTree(contentSets, new PathNode());
|
||||
PathNode treeRoot = PathTree.makePathTree(contentSets, new PathNode());
|
||||
List<String> nodeStrings = orderStrings(treeRoot);
|
||||
if (nodeStrings.size() == 0) {
|
||||
this.payload = new byte[0];
|
||||
|
@ -358,13 +395,14 @@ public class PathTree {
|
|||
* @param parent a PathNode, will be the root node, to be populated
|
||||
* @return is the same object as the parent param
|
||||
*/
|
||||
public PathNode makePathTree(List<String> contents, PathNode parent) {
|
||||
public static PathNode makePathTree(List<String> contents, PathNode parent) {
|
||||
PathNode endMarker = new PathNode(new NodeContext());
|
||||
for (String path : contents) {
|
||||
StringTokenizer st = new StringTokenizer(path, "/");
|
||||
this.makePathForURL(st, parent, endMarker);
|
||||
PathTree.makePathForURL(st, parent, endMarker);
|
||||
}
|
||||
this.condenseSubTreeNodes(endMarker);
|
||||
//log.debug("would run condenseSubTreeNodes()");
|
||||
//this.condenseSubTreeNodes(endMarker);
|
||||
return parent;
|
||||
}
|
||||
|
||||
|
@ -754,7 +792,7 @@ public class PathTree {
|
|||
* given a tokenized URL path, build out the PathNode parent,
|
||||
* and append endMarker to terminal nodes.
|
||||
*/
|
||||
private void makePathForURL(StringTokenizer st, PathNode parent, PathNode endMarker) {
|
||||
private static void makePathForURL(StringTokenizer st, PathNode parent, PathNode endMarker) {
|
||||
if (st.hasMoreTokens()) {
|
||||
String childVal = st.nextToken();
|
||||
if (childVal.equals("")) {
|
||||
|
@ -765,7 +803,7 @@ public class PathTree {
|
|||
for (NodePair child : parent.getChildren()) {
|
||||
if (child.getName().equals(childVal) &&
|
||||
!child.getConnection().equals(endMarker)) {
|
||||
this.makePathForURL(st, child.getConnection(), endMarker);
|
||||
PathTree.makePathForURL(st, child.getConnection(), endMarker);
|
||||
isNew = false;
|
||||
}
|
||||
}
|
||||
|
@ -775,7 +813,7 @@ public class PathTree {
|
|||
next = new PathNode(parent.getContext());
|
||||
parent.addChild(new NodePair(childVal, next));
|
||||
next.addParent(parent);
|
||||
this.makePathForURL(st, next, endMarker);
|
||||
PathTree.makePathForURL(st, next, endMarker);
|
||||
} else {
|
||||
parent.addChild(new NodePair(childVal, endMarker));
|
||||
if (!endMarker.getParents().contains(parent)) {
|
||||
|
|
17
src/main/resources/log4j.properties
Normal file
17
src/main/resources/log4j.properties
Normal file
|
@ -0,0 +1,17 @@
|
|||
# Define the root logger with appender file
|
||||
#log = /usr/home/log4j
|
||||
log4j.rootLogger = DEBUG, stderr
|
||||
|
||||
log4j.appender.stderr= org.apache.log4j.ConsoleAppender
|
||||
#log4j.appender.stderr.Threshold=DEBUG
|
||||
log4j.appender.stderr.target=System.err
|
||||
log4j.appender.stderr.layout=org.apache.log4j.PatternLayout
|
||||
log4j.appender.stderr.layout.ConversionPattern=%d{ISO8601} %5p [%t] %c -- %m%n
|
||||
|
||||
# Define the file appender
|
||||
#log4j.appender.FILE=org.apache.log4j.FileAppender
|
||||
#log4j.appender.FILE.File=${log}/log.out
|
||||
|
||||
# Define the layout for file appender
|
||||
#log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
|
||||
#log4j.appender.FILE.layout.conversionPattern=%m%n
|
|
@ -1,6 +1,7 @@
|
|||
package com.redhat.trie;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import org.junit.Test;
|
||||
|
@ -19,5 +20,34 @@ public class TestPathNode {
|
|||
assertNotNull(pn);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEquivalent() {
|
||||
NodeContext ctx0 = new NodeContext();
|
||||
NodeContext ctx1 = new NodeContext();
|
||||
PathNode endMarker = new PathNode();
|
||||
PathNode pn0 = new PathNode(ctx0);
|
||||
PathNode pn1 = new PathNode(ctx1);
|
||||
|
||||
assertTrue(pn0.isEquivalentTo(pn1));
|
||||
|
||||
|
||||
NodePair np0a = new NodePair("foo",endMarker);
|
||||
pn0.addChild(np0a);
|
||||
NodePair np1a = new NodePair("foo",endMarker);
|
||||
pn1.addChild(np1a);
|
||||
|
||||
assertTrue(pn0.isEquivalentTo(pn1));
|
||||
|
||||
|
||||
PathNode pn2 = new PathNode(pn0.getContext());
|
||||
PathNode pn3 = new PathNode(pn1.getContext());
|
||||
NodePair np0b = new NodePair("bar",endMarker);
|
||||
pn0.addChild(np0b);
|
||||
NodePair np1b = new NodePair("baz",endMarker);
|
||||
pn1.addChild(np1b);
|
||||
|
||||
// XXX finish this test !!
|
||||
//assertTrue(pn0.isEquivalentTo(pn1));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -51,6 +51,31 @@ public class TestPathTree {
|
|||
assertNotNull(pt);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRootNode() {
|
||||
PathTree pt = new PathTree();
|
||||
List<String> contents = loadContents("contents.list");
|
||||
try {
|
||||
pt.setContentSets(contents);
|
||||
} catch (PayloadException ex) {
|
||||
fail(ex.toString());
|
||||
}
|
||||
|
||||
// generate the root PathNode
|
||||
try {
|
||||
assertNotNull(pt.getRootPathNode());
|
||||
} catch (PayloadException ex) {
|
||||
fail(ex.toString());
|
||||
}
|
||||
|
||||
// do it again, to make sure it was not a mistake
|
||||
try {
|
||||
assertNotNull(pt.getRootPathNode());
|
||||
} catch (PayloadException ex) {
|
||||
fail(ex.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testThereAndBackAgainPayload() {
|
||||
byte[] bytes;
|
||||
|
|
Loading…
Reference in a new issue