store path elements or the item itself in the tree

pull/53/head
Zlatin Balevsky 2020-11-01 14:31:00 +00:00
parent 83680779f8
commit 1ee385b2ff
No known key found for this signature in database
GPG Key ID: A72832072D525E41
2 changed files with 6 additions and 3 deletions

View File

@ -37,7 +37,7 @@ class FileCollection {
name = files.first().pathElements.first() name = files.first().pathElements.first()
tree = new PathTree(name) tree = new PathTree(name)
for(FileCollectionItem item : files) { for(FileCollectionItem item : files) {
tree.add(item.pathElements) tree.add(item.pathElements, item)
} }
byte [] signablePayload = signablePayload() byte [] signablePayload = signablePayload()
@ -73,7 +73,7 @@ class FileCollection {
name = files.first().pathElements.first() name = files.first().pathElements.first()
tree = new PathTree(name) tree = new PathTree(name)
for(FileCollectionItem item : files) { for(FileCollectionItem item : files) {
tree.add(item.pathElements) tree.add(item.pathElements, item)
} }
this.hashCode = Objects.hash(timestamp, author, comment, files) this.hashCode = Objects.hash(timestamp, author, comment, files)

View File

@ -10,7 +10,7 @@ class PathTree {
keyToNode.put(this.root.key(), this.root) keyToNode.put(this.root.key(), this.root)
} }
void add(List<String> paths) { void add(List<String> paths, FileCollectionItem item) {
PathNode current = null PathNode current = null
for (String path : paths) { for (String path : paths) {
if (current == null) { if (current == null) {
@ -28,7 +28,9 @@ class PathTree {
current.children.add(child) current.children.add(child)
} }
current = keyToNode.get(childKey) current = keyToNode.get(childKey)
current.userObject = path
} }
current?.userObject = item
} }
public void traverse(Callback cb) { public void traverse(Callback cb) {
@ -51,6 +53,7 @@ class PathTree {
final PathNode parent final PathNode parent
final Set<PathNode> children = new LinkedHashSet<>() final Set<PathNode> children = new LinkedHashSet<>()
private final int hashCode private final int hashCode
Object userObject
PathNode(String path, PathNode parent) { PathNode(String path, PathNode parent) {
this.parent = parent this.parent = parent