Hi,
Preemptively building and caching the path here is worrisome since this
will blow up memory usage quite a bit. This is the reason the path was
only build on access (i.e. getPath()) in the original design and in
TreeImpl.
Michael
On 30.1.13 17:33, [email protected] wrote:
+ /**
+ * Path of this tree
+ */
+ private final String path;
+
+ /**
+ * Underlying node state
+ */
private final NodeState state;
- public ReadOnlyTree(NodeState root) {
- this(null, "", root);
+ public ReadOnlyTree(NodeState rootState) {
+ this(null, "", rootState);
}
- public ReadOnlyTree(ReadOnlyTree parent, String name, NodeState state) {
+ public ReadOnlyTree(@Nullable ReadOnlyTree parent, @Nonnull String name,
@Nonnull NodeState state) {
this.parent = parent;
this.name = checkNotNull(name);
+ this.path = buildPath(parent, name);
this.state = checkNotNull(state);
checkArgument(!name.isEmpty() || parent == null);
}
+ private static String buildPath(ReadOnlyTree parent, String name) {
+ if (parent == null) {
+ return "/";
+ } else if (parent.isRoot()) {
+ return parent.path + name;
+ } else {
+ StringBuilder sb = new StringBuilder();
+ sb.append(parent.path).append('/').append(name);
+ return sb.toString();
+ }
+ }