@Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; ProcessingTree<?> that = (ProcessingTree<?>) o; return path.equals(that.path); }
ProcessingTree<BE> getChild(RelativePath childPath) { Iterator<Path.Segment> segments = childPath.getPath().iterator(); Set<ProcessingTree<BE>> children = this.children; ProcessingTree<BE> current = null; while (segments.hasNext()) { Path.Segment seg = segments.next(); current = null; for (ProcessingTree<BE> c : children) { //children are bound to each have a different ending segment, otherwise their CP would be the same //which is illegal in inventory. We can therefore just compare the current segment with the last //segment of the child path and if they match, move on to that child. if (seg.equals(c.cp.getSegment())) { current = c; children = c.children; break; } } //no child found matching this segment... if (current == null) { break; } } return segments.hasNext() ? null : current; }
private ProcessingTree<BE> extendTreeTo(CanonicalPath entityPath) { Set<ProcessingTree<BE>> children = this.children; CanonicalPath.Extender cp = CanonicalPath.empty(); ProcessingTree<BE> found = null; for (Path.Segment seg : entityPath.getPath()) { cp.extend(seg); found = null; for (ProcessingTree<BE> child : children) { if (seg.equals(child.path)) { found = child; break; } } if (found == null) { found = new ProcessingTree<>(seg, cp.get()); children.add(found); } children = found.children; } if (found == null) { throw new IllegalStateException("Could not figure out the processing tree element for entity on path " + entityPath); } return found; }