target java 1.8
This commit is contained in:
parent
3a59c85df8
commit
91c78a8b13
9 changed files with 132 additions and 183 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -8,3 +8,5 @@ target/
|
||||||
.project
|
.project
|
||||||
.classpath
|
.classpath
|
||||||
.settings/
|
.settings/
|
||||||
|
.idea/
|
||||||
|
*.iml
|
71
pom.xml
71
pom.xml
|
@ -3,24 +3,20 @@
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>com.redhat.trie</groupId>
|
<groupId>com.redhat.trie</groupId>
|
||||||
<artifactId>PathPacker</artifactId>
|
<artifactId>PathPacker</artifactId>
|
||||||
<version>0.0.3</version>
|
<version>0.0.4</version>
|
||||||
<packaging>bundle</packaging>
|
<packaging>bundle</packaging>
|
||||||
|
|
||||||
<prerequisites>
|
|
||||||
<maven>3.0</maven>
|
|
||||||
</prerequisites>
|
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>junit</groupId>
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>junit</artifactId>
|
||||||
<version>4.11</version>
|
<version>4.13</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.bouncycastle</groupId>
|
<groupId>org.bouncycastle</groupId>
|
||||||
<artifactId>bcprov-jdk16</artifactId>
|
<artifactId>bcprov-jdk15on</artifactId>
|
||||||
<version>1.46</version>
|
<version>1.64</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.maven.surefire</groupId>
|
<groupId>org.apache.maven.surefire</groupId>
|
||||||
|
@ -28,51 +24,44 @@
|
||||||
<version>2.17</version>
|
<version>2.17</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>log4j</groupId>
|
|
||||||
<artifactId>log4j</artifactId>
|
|
||||||
<version>1.2.17</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>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-enforcer-plugin</artifactId>
|
||||||
|
<version>3.0.0-M3</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>enforce-maven</id>
|
||||||
|
<goals>
|
||||||
|
<goal>enforce</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<rules>
|
||||||
|
<requireMavenVersion>
|
||||||
|
<version>3.0</version>
|
||||||
|
</requireMavenVersion>
|
||||||
|
</rules>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
|
||||||
<plugin>
|
<plugin>
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<version>2.3.2</version>
|
<version>3.8.1</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<source>1.6</source>
|
<source>1.8</source>
|
||||||
<target>1.6</target>
|
<target>1.8</target>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-javadoc-plugin</artifactId>
|
<artifactId>maven-javadoc-plugin</artifactId>
|
||||||
|
<version>3.1.1</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<tags>
|
<tags>
|
||||||
<tag>
|
<tag>
|
||||||
|
@ -117,7 +106,7 @@
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.felix</groupId>
|
<groupId>org.apache.felix</groupId>
|
||||||
<artifactId>maven-bundle-plugin</artifactId>
|
<artifactId>maven-bundle-plugin</artifactId>
|
||||||
<version>2.4.0</version>
|
<version>4.2.1</version>
|
||||||
<extensions>true</extensions>
|
<extensions>true</extensions>
|
||||||
<configuration>
|
<configuration>
|
||||||
<instructions>
|
<instructions>
|
||||||
|
|
|
@ -146,26 +146,22 @@ public class HuffNode {
|
||||||
* get a String of the bits, that map to Object need
|
* get a String of the bits, that map to Object need
|
||||||
*/
|
*/
|
||||||
private String getBitPath(HuffNode trie, Object need) {
|
private String getBitPath(HuffNode trie, Object need) {
|
||||||
HuffNode left = trie.getLeft();
|
HuffNode leftNode = trie.getLeft();
|
||||||
HuffNode right = trie.getRight();
|
HuffNode rightNode = trie.getRight();
|
||||||
if (left != null && left.getValue() != null) {
|
if (leftNode != null && leftNode.getValue() != null && need.equals(leftNode.getValue())) {
|
||||||
if (need.equals(left.getValue())) {
|
return "0";
|
||||||
return "0";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (right != null && right.getValue() != null) {
|
if (rightNode != null && rightNode.getValue() != null && need.equals(rightNode.getValue())) {
|
||||||
if (need.equals(right.getValue())) {
|
return "1";
|
||||||
return "1";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (left != null) {
|
if (leftNode != null) {
|
||||||
String leftPath = getBitPath(left, need);
|
String leftPath = getBitPath(leftNode, need);
|
||||||
if (leftPath.length() > 0) {
|
if (leftPath.length() > 0) {
|
||||||
return "0" + leftPath;
|
return "0" + leftPath;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (right != null) {
|
if (rightNode != null) {
|
||||||
String rightPath = getBitPath(right, need);
|
String rightPath = getBitPath(rightNode, need);
|
||||||
if (rightPath.length() > 0) {
|
if (rightPath.length() > 0) {
|
||||||
return "1" + rightPath;
|
return "1" + rightPath;
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,7 +56,7 @@ public class NodePair implements Comparable {
|
||||||
* @return <tt>true</tt> if it has at least one connection and <tt>false</tt> otherwise.
|
* @return <tt>true</tt> if it has at least one connection and <tt>false</tt> otherwise.
|
||||||
*/
|
*/
|
||||||
public boolean hasNoChildren() {
|
public boolean hasNoChildren() {
|
||||||
return getConnection().getChildren().size() == 0;
|
return getConnection().getChildren().isEmpty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,12 +16,12 @@
|
||||||
package com.redhat.trie;
|
package com.redhat.trie;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.HashSet;
|
import java.util.logging.Level;
|
||||||
import java.util.Collections;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PathNode is the relationship to an item in the path tree.
|
* PathNode is the relationship to an item in the path tree.
|
||||||
|
@ -31,7 +31,7 @@ import org.apache.log4j.Logger;
|
||||||
* The Name of a given PathNode, is inferred by the NodePair that regards this PathNode as its "connection"
|
* The Name of a given PathNode, is inferred by the NodePair that regards this PathNode as its "connection"
|
||||||
*/
|
*/
|
||||||
public class PathNode {
|
public class PathNode {
|
||||||
private static org.apache.log4j.Logger log = Logger.getLogger(PathTree.class);
|
private static Logger log = Logger.getLogger(PathTree.class.getCanonicalName());
|
||||||
private long id = 0;
|
private long id = 0;
|
||||||
private List<NodePair> children = new ArrayList<NodePair>();
|
private List<NodePair> children = new ArrayList<NodePair>();
|
||||||
private List<PathNode> parents = new ArrayList<PathNode>();
|
private List<PathNode> parents = new ArrayList<PathNode>();
|
||||||
|
@ -161,14 +161,11 @@ public class PathNode {
|
||||||
* Traverse up the tree, and get the highest ancestor PathNode, for node.
|
* Traverse up the tree, and get the highest ancestor PathNode, for node.
|
||||||
*/
|
*/
|
||||||
public PathNode getStartNode(PathNode node) {
|
public PathNode getStartNode(PathNode node) {
|
||||||
if (node.getParents().size() == 0) {
|
if (node.getParents().isEmpty()) {
|
||||||
return node; // this is the end!
|
return node; // this is the end!
|
||||||
|
} else {
|
||||||
|
return node.getStartNode(node.getParents().get(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (PathNode parent : node.getParents()) {
|
|
||||||
return node.getStartNode(parent);
|
|
||||||
}
|
|
||||||
return node; // when in doubt, return yourself
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -182,13 +179,11 @@ public class PathNode {
|
||||||
* Traverse down the tree, and get the "endMarker" child, for node.
|
* Traverse down the tree, and get the "endMarker" child, for node.
|
||||||
*/
|
*/
|
||||||
public PathNode getEndNode(PathNode node) {
|
public PathNode getEndNode(PathNode node) {
|
||||||
if (node.getChildren().size() == 0) {
|
if (node.getChildren().isEmpty()) {
|
||||||
return node; // this is the end!
|
return node; // this is the end!
|
||||||
|
} else {
|
||||||
|
return node.getEndNode(node.getChildren().get(0).getConnection());
|
||||||
}
|
}
|
||||||
for (NodePair child : node.getChildren()) {
|
|
||||||
return node.getEndNode(child.getConnection());
|
|
||||||
}
|
|
||||||
return node; // when in doubt, return yourself
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -233,7 +228,7 @@ public class PathNode {
|
||||||
public boolean includes(PathNode that) {
|
public boolean includes(PathNode that) {
|
||||||
// if we are at the end of the tree we're checking against,
|
// if we are at the end of the tree we're checking against,
|
||||||
// then it includes everything up to this point.
|
// then it includes everything up to this point.
|
||||||
if (this.getChildren().size() == 0 || that.getChildren().size() == 0) {
|
if (this.getChildren().isEmpty() || that.getChildren().isEmpty()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -248,8 +243,8 @@ public class PathNode {
|
||||||
thisnp.getName().startsWith("$") ||
|
thisnp.getName().startsWith("$") ||
|
||||||
thisnp.getName().equals(thatnp.getName()) ) {
|
thisnp.getName().equals(thatnp.getName()) ) {
|
||||||
result = thisnp.getConnection().includes(thatnp.getConnection());
|
result = thisnp.getConnection().includes(thatnp.getConnection());
|
||||||
found.add(new Boolean(result).booleanValue());
|
found.add(result);
|
||||||
log.debug("includes: this: " + thisnp.getName() + " == that:" + thatnp.getName());
|
log.log(Level.FINE, () -> "includes: this: " + thisnp.getName() + " == that:" + thatnp.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -262,12 +257,11 @@ public class PathNode {
|
||||||
* pretty information
|
* pretty information
|
||||||
*/
|
*/
|
||||||
public String toString() {
|
public String toString() {
|
||||||
String parentList = "";
|
StringBuilder parentList = new StringBuilder();
|
||||||
for (PathNode parent : parents) {
|
for (PathNode parent : parents) {
|
||||||
parentList += ": " + parent.getId();
|
parentList.append(": " + parent.getId());
|
||||||
}
|
}
|
||||||
parentList += "";
|
return "ID: " + id + ", Name: " + this.getName() + ", Parents" + parentList.toString() + ", Children: " + children;
|
||||||
return "ID: " + id + ", Name: " + this.getName() + ", Parents" + parentList + ", Children: " + children;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,26 +15,23 @@
|
||||||
|
|
||||||
package com.redhat.trie;
|
package com.redhat.trie;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.StringTokenizer;
|
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.zip.Inflater;
|
import java.util.HashMap;
|
||||||
import java.util.zip.InflaterOutputStream;
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.StringTokenizer;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
import java.util.zip.Deflater;
|
import java.util.zip.Deflater;
|
||||||
import java.util.zip.DeflaterOutputStream;
|
import java.util.zip.DeflaterOutputStream;
|
||||||
import java.util.zip.DataFormatException;
|
import java.util.zip.Inflater;
|
||||||
|
import java.util.zip.InflaterOutputStream;
|
||||||
import org.apache.log4j.Logger;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PathTree
|
* PathTree
|
||||||
|
@ -42,10 +39,10 @@ import org.apache.log4j.Logger;
|
||||||
* An efficient means by which to check the content sets.
|
* An efficient means by which to check the content sets.
|
||||||
*/
|
*/
|
||||||
public class PathTree {
|
public class PathTree {
|
||||||
private static org.apache.log4j.Logger log = Logger.getLogger(PathTree.class);
|
private static Logger log = Logger.getLogger(PathTree.class.getCanonicalName());
|
||||||
private List<HuffNode> nodeDictionary;
|
private List<HuffNode> nodeDictionary;
|
||||||
private List<HuffNode> pathDictionary;
|
private List<HuffNode> pathDictionary;
|
||||||
private StringBuffer nodeBits;
|
private StringBuilder nodeBits;
|
||||||
|
|
||||||
private byte[] payload;
|
private byte[] payload;
|
||||||
|
|
||||||
|
@ -95,11 +92,7 @@ public class PathTree {
|
||||||
* Constructor using the list of content sets.
|
* Constructor using the list of content sets.
|
||||||
*/
|
*/
|
||||||
public PathTree(List<String> contentSets) throws PayloadException {
|
public PathTree(List<String> contentSets) throws PayloadException {
|
||||||
try {
|
setContentSets(contentSets);
|
||||||
setContentSets(contentSets);
|
|
||||||
} catch (PayloadException ex) {
|
|
||||||
throw ex;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -150,13 +143,13 @@ public class PathTree {
|
||||||
/**
|
/**
|
||||||
* the buffer of significant bits, with regard to how many nodes there are.
|
* the buffer of significant bits, with regard to how many nodes there are.
|
||||||
*
|
*
|
||||||
* @return StringBuffer of
|
* @return StringBuilder of
|
||||||
*/
|
*/
|
||||||
private StringBuffer getNodeBits() {
|
private StringBuilder getNodeBits() {
|
||||||
return this.nodeBits;
|
return this.nodeBits;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setNodeBits(StringBuffer nodeBits) {
|
private void setNodeBits(StringBuilder nodeBits) {
|
||||||
this.nodeBits = nodeBits;
|
this.nodeBits = nodeBits;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -211,11 +204,11 @@ public class PathTree {
|
||||||
}
|
}
|
||||||
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>();
|
||||||
this.setNodeBits(new StringBuffer());
|
this.setNodeBits(new StringBuilder());
|
||||||
|
|
||||||
ByteArrayInputStream bais = new ByteArrayInputStream(this.getPayload(),
|
ByteArrayInputStream bais = new ByteArrayInputStream(this.getPayload(),
|
||||||
(new Long(this.getDictOffset())).intValue(),
|
((int)(this.getDictOffset())),
|
||||||
(new Long(this.getPayload().length - this.getDictOffset()).intValue()));
|
((int) (this.getPayload().length - this.getDictOffset())));
|
||||||
int value = bais.read();
|
int value = bais.read();
|
||||||
// check for size bits
|
// check for size bits
|
||||||
this.setNodeCount(value);
|
this.setNodeCount(value);
|
||||||
|
@ -261,11 +254,7 @@ public class PathTree {
|
||||||
* @throws PayloadException if the newly read PathNode dictionary can not be read from the payload
|
* @throws PayloadException if the newly read PathNode dictionary can not be read from the payload
|
||||||
*/
|
*/
|
||||||
private HuffNode getPathTrie() throws PayloadException {
|
private HuffNode getPathTrie() throws PayloadException {
|
||||||
try {
|
return makeTrie(getPathDictionary());
|
||||||
return makeTrie(getPathDictionary());
|
|
||||||
} catch (PayloadException ex) {
|
|
||||||
throw ex;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -275,11 +264,7 @@ public class PathTree {
|
||||||
* @throws PayloadException if the newly read Node name dictionary can not be read from the payload
|
* @throws PayloadException if the newly read Node name dictionary can not be read from the payload
|
||||||
*/
|
*/
|
||||||
private HuffNode getNodeTrie() throws PayloadException {
|
private HuffNode getNodeTrie() throws PayloadException {
|
||||||
try {
|
return makeTrie(getNodeDictionary());
|
||||||
return makeTrie(getNodeDictionary());
|
|
||||||
} catch (PayloadException ex) {
|
|
||||||
throw ex;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -287,17 +272,12 @@ public class PathTree {
|
||||||
*/
|
*/
|
||||||
public PathNode getRootPathNode() throws PayloadException {
|
public PathNode getRootPathNode() throws PayloadException {
|
||||||
// populate the PathNodes so we can rebuild the cool url tree
|
// populate the PathNodes so we can rebuild the cool url tree
|
||||||
Set<PathNode> pathNodes;
|
Set<PathNode> pathNodes = populatePathNodes(getNodeDictionary(),
|
||||||
try {
|
|
||||||
pathNodes = populatePathNodes(getNodeDictionary(),
|
|
||||||
getPathTrie(), getNodeTrie(), getNodeBits());
|
getPathTrie(), getNodeTrie(), getNodeBits());
|
||||||
} catch (PayloadException ex) {
|
|
||||||
throw ex;
|
|
||||||
}
|
|
||||||
// find the root, he has no parents
|
// find the root, he has no parents
|
||||||
PathNode root = null;
|
PathNode root = null;
|
||||||
for (PathNode pn : pathNodes) {
|
for (PathNode pn : pathNodes) {
|
||||||
if (pn.getParents().size() == 0) {
|
if (pn.getParents().isEmpty()) {
|
||||||
root = pn;
|
root = pn;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -316,7 +296,7 @@ public class PathTree {
|
||||||
try {
|
try {
|
||||||
rootPathNode = getRootPathNode();
|
rootPathNode = getRootPathNode();
|
||||||
} catch(PayloadException pe) {
|
} catch(PayloadException pe) {
|
||||||
log.error(pe);
|
log.log(Level.SEVERE,"Payload Exception", pe);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return test(contentPath, rootPathNode);
|
return test(contentPath, rootPathNode);
|
||||||
|
@ -336,7 +316,7 @@ public class PathTree {
|
||||||
/* Request is of the form "/content/rc/rhel/7/..."
|
/* Request is of the form "/content/rc/rhel/7/..."
|
||||||
* Grab the next element.
|
* Grab the next element.
|
||||||
*/
|
*/
|
||||||
log.debug("test(" + request + ")");
|
log.log(Level.FINE, () -> "test(" + request + ")");
|
||||||
StringTokenizer tokenizer = new StringTokenizer(request, PATH_DELIMITER);
|
StringTokenizer tokenizer = new StringTokenizer(request, PATH_DELIMITER);
|
||||||
if(tokenizer.countTokens() == 0) {
|
if(tokenizer.countTokens() == 0) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -344,12 +324,11 @@ public class PathTree {
|
||||||
String currentToken = tokenizer.nextToken();
|
String currentToken = tokenizer.nextToken();
|
||||||
for(NodePair nodePair: tree.getChildren()) {
|
for(NodePair nodePair: tree.getChildren()) {
|
||||||
String nodePairName = nodePair.getName();
|
String nodePairName = nodePair.getName();
|
||||||
log.debug("Current token: [" + currentToken + "] =??= NodePair name: [" + nodePairName + "]");
|
log.log(Level.FINE, () -> "Current token: [" + currentToken + "] =??= NodePair name: [" + nodePairName + "]");
|
||||||
if(currentToken.equals(nodePairName) || nodePairName.startsWith(CONTENT_PATH_VARIABLE_PREFIX)) {
|
if(currentToken.equals(nodePairName) || nodePairName.startsWith(CONTENT_PATH_VARIABLE_PREFIX)) {
|
||||||
if(nodePair.hasNoChildren()) {
|
if(nodePair.hasNoChildren()) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
String s = PATH_DELIMITER + currentToken;
|
|
||||||
boolean retval = test(request.substring(currentToken.length()+1), nodePair.getConnection());
|
boolean retval = test(request.substring(currentToken.length()+1), nodePair.getConnection());
|
||||||
if(retval) {
|
if(retval) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -377,7 +356,7 @@ public class PathTree {
|
||||||
|
|
||||||
PathNode treeRoot = PathTree.makePathTree(contentSets, new PathNode());
|
PathNode treeRoot = PathTree.makePathTree(contentSets, new PathNode());
|
||||||
List<String> nodeStrings = orderStrings(treeRoot);
|
List<String> nodeStrings = orderStrings(treeRoot);
|
||||||
if (nodeStrings.size() == 0) {
|
if (nodeStrings.isEmpty()) {
|
||||||
this.payload = new byte[0];
|
this.payload = new byte[0];
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -429,14 +408,14 @@ public class PathTree {
|
||||||
|
|
||||||
private List<String> byteArrayToStringList(byte[] ba) {
|
private List<String> byteArrayToStringList(byte[] ba) {
|
||||||
List<String> strings = new ArrayList<String>();
|
List<String> strings = new ArrayList<String>();
|
||||||
String str = "";
|
StringBuilder str = new StringBuilder();
|
||||||
|
|
||||||
for (byte b : ba) {
|
for (byte b : ba) {
|
||||||
if (b == '\0') {
|
if (b == '\0') {
|
||||||
strings.add(str);
|
strings.add(str.toString());
|
||||||
str = "";
|
str.setLength(0);
|
||||||
} else {
|
} else {
|
||||||
str += (char) b;
|
str.append((char) b);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return strings;
|
return strings;
|
||||||
|
@ -475,9 +454,9 @@ public class PathTree {
|
||||||
* @return the Set of weighted PathNode
|
* @return the Set of weighted PathNode
|
||||||
*/
|
*/
|
||||||
private Set<PathNode> populatePathNodes(List<HuffNode> thisNodeDictionary,
|
private Set<PathNode> populatePathNodes(List<HuffNode> thisNodeDictionary,
|
||||||
HuffNode pathTrie, HuffNode nodeTrie, StringBuffer theseNodeBits) {
|
HuffNode pathTrie, HuffNode nodeTrie, StringBuilder theseNodeBits) {
|
||||||
Set<PathNode> pathNodes = new HashSet<PathNode>();
|
Set<PathNode> pathNodes = new HashSet<PathNode>();
|
||||||
StringBuffer myNodeBits = new StringBuffer(theseNodeBits.toString());
|
StringBuilder myNodeBits = new StringBuilder(theseNodeBits.toString());
|
||||||
for (HuffNode node : thisNodeDictionary) {
|
for (HuffNode node : thisNodeDictionary) {
|
||||||
pathNodes.add((PathNode) node.getValue());
|
pathNodes.add((PathNode) node.getValue());
|
||||||
boolean stillNode = true;
|
boolean stillNode = true;
|
||||||
|
@ -485,7 +464,7 @@ public class PathTree {
|
||||||
// get first child name
|
// get first child name
|
||||||
// if its HuffNode.END_NODE we are done
|
// if its HuffNode.END_NODE we are done
|
||||||
String nameValue = null;
|
String nameValue = null;
|
||||||
StringBuffer nameBits = new StringBuffer();
|
StringBuilder nameBits = new StringBuilder();
|
||||||
while (nameValue == null && stillNode) {
|
while (nameValue == null && stillNode) {
|
||||||
nameBits.append(myNodeBits.charAt(0));
|
nameBits.append(myNodeBits.charAt(0));
|
||||||
myNodeBits.deleteCharAt(0);
|
myNodeBits.deleteCharAt(0);
|
||||||
|
@ -503,7 +482,7 @@ public class PathTree {
|
||||||
}
|
}
|
||||||
|
|
||||||
PathNode nodeValue = null;
|
PathNode nodeValue = null;
|
||||||
StringBuffer pathBits = new StringBuffer();
|
StringBuilder pathBits = new StringBuilder();
|
||||||
while (nodeValue == null && stillNode) {
|
while (nodeValue == null && stillNode) {
|
||||||
pathBits.append(myNodeBits.charAt(0));
|
pathBits.append(myNodeBits.charAt(0));
|
||||||
myNodeBits.deleteCharAt(0);
|
myNodeBits.deleteCharAt(0);
|
||||||
|
@ -530,7 +509,7 @@ public class PathTree {
|
||||||
*/
|
*/
|
||||||
public List<String> toList() {
|
public List<String> toList() {
|
||||||
List<String> urls = new ArrayList<String>();
|
List<String> urls = new ArrayList<String>();
|
||||||
StringBuffer aPath = new StringBuffer();
|
StringBuilder aPath = new StringBuilder();
|
||||||
try {
|
try {
|
||||||
makeURLs(getRootPathNode(), urls, aPath);
|
makeURLs(getRootPathNode(), urls, aPath);
|
||||||
} catch (PayloadException ex) {
|
} catch (PayloadException ex) {
|
||||||
|
@ -539,12 +518,12 @@ public class PathTree {
|
||||||
return urls;
|
return urls;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void makeURLs(PathNode root, List<String> urls, StringBuffer aPath) {
|
private void makeURLs(PathNode root, List<String> urls, StringBuilder aPath) {
|
||||||
if (root.getChildren().size() == 0) {
|
if (root.getChildren().isEmpty()) {
|
||||||
urls.add(aPath.toString());
|
urls.add(aPath.toString());
|
||||||
}
|
}
|
||||||
for (NodePair child : root.getChildren()) {
|
for (NodePair child : root.getChildren()) {
|
||||||
StringBuffer childPath = new StringBuffer(aPath.substring(0));
|
StringBuilder childPath = new StringBuilder(aPath.substring(0));
|
||||||
childPath.append("/");
|
childPath.append("/");
|
||||||
childPath.append(child.getName());
|
childPath.append(child.getName());
|
||||||
makeURLs(child.getConnection(), urls, childPath);
|
makeURLs(child.getConnection(), urls, childPath);
|
||||||
|
@ -572,9 +551,8 @@ public class PathTree {
|
||||||
private HuffNode mergeNodes(HuffNode node1, HuffNode node2) {
|
private HuffNode mergeNodes(HuffNode node1, HuffNode node2) {
|
||||||
HuffNode left = node1;
|
HuffNode left = node1;
|
||||||
HuffNode right = node2;
|
HuffNode right = node2;
|
||||||
HuffNode parent = new HuffNode(getHuffNodeContext(),
|
return new HuffNode(getHuffNodeContext(),
|
||||||
null, left.getWeight() + right.getWeight(), left, right);
|
null, left.getWeight() + right.getWeight(), left, right);
|
||||||
return parent;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<HuffNode> getStringNodeList(List<String> pathStrings) {
|
private List<HuffNode> getStringNodeList(List<String> pathStrings) {
|
||||||
|
@ -603,13 +581,13 @@ public class PathTree {
|
||||||
* @return deflated byte array
|
* @return deflated byte array
|
||||||
*/
|
*/
|
||||||
private byte[] byteProcess(List<String> entries)
|
private byte[] byteProcess(List<String> entries)
|
||||||
throws IOException, UnsupportedEncodingException {
|
throws IOException {
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
DeflaterOutputStream dos = new DeflaterOutputStream(baos,
|
DeflaterOutputStream dos = new DeflaterOutputStream(baos,
|
||||||
new Deflater(Deflater.BEST_COMPRESSION));
|
new Deflater(Deflater.BEST_COMPRESSION));
|
||||||
for (String segment : entries) {
|
for (String segment : entries) {
|
||||||
dos.write(segment.getBytes("UTF-8"));
|
dos.write(segment.getBytes(StandardCharsets.UTF_8));
|
||||||
dos.write("\0".getBytes("UTF-8"));
|
dos.write("\0".getBytes(StandardCharsets.UTF_8));
|
||||||
}
|
}
|
||||||
dos.finish();
|
dos.finish();
|
||||||
dos.close();
|
dos.close();
|
||||||
|
@ -622,11 +600,11 @@ public class PathTree {
|
||||||
Map<String, Integer> segments = new HashMap<String, Integer>();
|
Map<String, Integer> segments = new HashMap<String, Integer>();
|
||||||
Set<PathNode> nodes = new HashSet<PathNode>();
|
Set<PathNode> nodes = new HashSet<PathNode>();
|
||||||
buildSegments(segments, nodes, parent);
|
buildSegments(segments, nodes, parent);
|
||||||
for (String part : segments.keySet()) {
|
for (Map.Entry<String, Integer> part : segments.entrySet()) {
|
||||||
if (!part.equals("")) {
|
if (!part.getKey().equals("")) {
|
||||||
int count = segments.get(part);
|
int count = part.getValue();
|
||||||
if (parts.size() == 0) {
|
if (parts.isEmpty()) {
|
||||||
parts.add(part);
|
parts.add(part.getKey());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
int pos = parts.size();
|
int pos = parts.size();
|
||||||
|
@ -636,7 +614,7 @@ public class PathTree {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
parts.add(pos, part);
|
parts.add(pos, part.getKey());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -654,10 +632,7 @@ public class PathTree {
|
||||||
boolean start = false;
|
boolean start = false;
|
||||||
/* TODO ??? */
|
/* TODO ??? */
|
||||||
for (byte b : toByteArray(nodeSize)) {
|
for (byte b : toByteArray(nodeSize)) {
|
||||||
if (b == 0 && !start) {
|
if (!(b == 0 && !start)) {
|
||||||
continue;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
countBaos.write(b);
|
countBaos.write(b);
|
||||||
start = true;
|
start = true;
|
||||||
}
|
}
|
||||||
|
@ -673,7 +648,7 @@ public class PathTree {
|
||||||
else {
|
else {
|
||||||
baos.write(nodeSize);
|
baos.write(nodeSize);
|
||||||
}
|
}
|
||||||
StringBuffer bits = new StringBuffer();
|
StringBuilder bits = new StringBuilder();
|
||||||
String endNodeLocationBitPath = stringParent.getBitPath(HuffNode.END_NODE);
|
String endNodeLocationBitPath = stringParent.getBitPath(HuffNode.END_NODE);
|
||||||
for (PathNode pn : pathNodes) {
|
for (PathNode pn : pathNodes) {
|
||||||
for (NodePair np : pn.getChildren()) {
|
for (NodePair np : pn.getChildren()) {
|
||||||
|
@ -726,7 +701,7 @@ public class PathTree {
|
||||||
Set<PathNode> nodes = treeRoot.getAllNodes();
|
Set<PathNode> nodes = treeRoot.getAllNodes();
|
||||||
for (PathNode pn : nodes) {
|
for (PathNode pn : nodes) {
|
||||||
int count = pn.getParents().size();
|
int count = pn.getParents().size();
|
||||||
if (nodes.size() == 0) {
|
if (nodes.isEmpty()) {
|
||||||
nodes.add(pn);
|
nodes.add(pn);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -786,7 +761,7 @@ public class PathTree {
|
||||||
for (NodePair np : parent.getChildren()) {
|
for (NodePair np : parent.getChildren()) {
|
||||||
Integer count = segments.get(np.getName());
|
Integer count = segments.get(np.getName());
|
||||||
if (count == null) {
|
if (count == null) {
|
||||||
count = new Integer(0);
|
count = 0;
|
||||||
}
|
}
|
||||||
segments.put(np.getName(), ++count);
|
segments.put(np.getName(), ++count);
|
||||||
buildSegments(segments, nodes, np.getConnection());
|
buildSegments(segments, nodes, np.getConnection());
|
||||||
|
@ -814,7 +789,6 @@ public class PathTree {
|
||||||
// "equivalent" parents are merged
|
// "equivalent" parents are merged
|
||||||
List<PathNode> parentResult = new ArrayList<PathNode>();
|
List<PathNode> parentResult = new ArrayList<PathNode>();
|
||||||
parentResult.addAll(location.getParents());
|
parentResult.addAll(location.getParents());
|
||||||
//log.debug(location);
|
|
||||||
for (PathNode parent1 : location.getParents()) {
|
for (PathNode parent1 : location.getParents()) {
|
||||||
if (!parentResult.contains(parent1)) {
|
if (!parentResult.contains(parent1)) {
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -15,8 +15,6 @@
|
||||||
|
|
||||||
package com.redhat.trie;
|
package com.redhat.trie;
|
||||||
|
|
||||||
import java.lang.Exception;
|
|
||||||
|
|
||||||
public class PayloadException extends Exception {
|
public class PayloadException extends Exception {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,35 +1,33 @@
|
||||||
package com.redhat.trie;
|
package com.redhat.trie;
|
||||||
|
|
||||||
import java.io.InputStreamReader;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import static org.junit.Assert.fail;
|
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
import static org.junit.Assert.fail;
|
||||||
import org.junit.Test;
|
|
||||||
import org.apache.log4j.Logger;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class is just to provide helpers for the other tests
|
* This class is just to provide helpers for the other tests
|
||||||
*/
|
*/
|
||||||
public class TestHelpers {
|
public class TestHelpers {
|
||||||
private static org.apache.log4j.Logger log = Logger.getLogger(TestHelpers.class);
|
private static Logger log = Logger.getLogger(TestHelpers.class.getCanonicalName());
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* junit requires at least one runnable test
|
* junit requires at least one runnable test
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testDeadVicker() {
|
public void testDeadVicker() {
|
||||||
assertNotNull(new String("What's its diocese?"));
|
assertNotNull("What's its diocese?");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helpers
|
// Helpers
|
||||||
|
@ -98,7 +96,7 @@ public class TestHelpers {
|
||||||
br = new BufferedReader(new InputStreamReader(in));
|
br = new BufferedReader(new InputStreamReader(in));
|
||||||
} catch(NullPointerException npe) {
|
} catch(NullPointerException npe) {
|
||||||
// can happen in the case of an empty content set list
|
// can happen in the case of an empty content set list
|
||||||
log.warn(">>>>>>> Empty content set <<<<<");
|
log.fine(">>>>>>> Empty content set <<<<<");
|
||||||
return contentList;
|
return contentList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,19 +1,17 @@
|
||||||
package com.redhat.trie;
|
package com.redhat.trie;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.junit.runners.Parameterized;
|
||||||
|
import org.junit.runners.Parameterized.Parameters;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import static org.junit.Assert.assertEquals;
|
||||||
import org.apache.log4j.Level;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.junit.runners.Parameterized;
|
|
||||||
import org.junit.runners.Parameterized.Parameters;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests of whether a URL should be granted access based on a given content set
|
* Tests of whether a URL should be granted access based on a given content set
|
||||||
|
|
Loading…
Reference in a new issue