From 95200474960ea0c93cf66441a9be121de4d2e750 Mon Sep 17 00:00:00 2001 From: Vincent Batts Date: Thu, 4 Oct 2012 10:31:46 -0400 Subject: [PATCH] commit 595f08259cfd44f1a6faf1a169735f6f452904ce Refs: candlepin-0.7.10-1-1-g595f082 Author: James Bowes AuthorDate: Wed Sep 19 17:22:36 2012 -0300 Commit: James Bowes CommitDate: Wed Sep 19 17:22:36 2012 -0300 certv3: sort path names alphabetically By sorting the child paths of a node alphabetically, clients can do a binary search for the node they want, rather than having to iterate over all children. --- src/main/java/com/redhat/trie/NodePair.java | 6 +++++- src/main/java/com/redhat/trie/PathNode.java | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/redhat/trie/NodePair.java b/src/main/java/com/redhat/trie/NodePair.java index 5585158..6abb38c 100644 --- a/src/main/java/com/redhat/trie/NodePair.java +++ b/src/main/java/com/redhat/trie/NodePair.java @@ -15,7 +15,7 @@ package com.redhat.trie; -public class NodePair { +public class NodePair implements Comparable { private String name; private PathNode connection; @@ -39,5 +39,9 @@ public class NodePair { public String toString() { return "Name: " + name + ", Connection: " + connection.getId(); } + + public int compareTo(Object other) { + return this.name.compareTo(((NodePair) other).name); + } } diff --git a/src/main/java/com/redhat/trie/PathNode.java b/src/main/java/com/redhat/trie/PathNode.java index cdc3b87..03a71c1 100644 --- a/src/main/java/com/redhat/trie/PathNode.java +++ b/src/main/java/com/redhat/trie/PathNode.java @@ -17,6 +17,7 @@ package com.redhat.trie; import java.util.ArrayList; import java.util.List; +import java.util.Collections; public class PathNode { private long id = 0; @@ -48,6 +49,7 @@ public class PathNode { } public List getChildren() { + Collections.sort(this.children); return this.children; }