Skip to content

Commit

Permalink
added public #getNodes method to handle recursive queries
Browse files Browse the repository at this point in the history
  • Loading branch information
trajar committed Apr 20, 2016
1 parent 635de7d commit 6ea285b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,15 @@ public interface HierarchicalNodeGroup {
void collapse();

/**
* @return Return iterator containing children nodes.
* @return Return iterator containing children nodes (not recursive).
*/
Iterable<Node> getNodes();

/**
* @return Return iterator containing children nodes.
*/
Iterable<Node> getNodes(boolean recursive);

/**
* Add node to this group.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class HierarchicalGraphViewImpl extends AbstractGraphView implements GraphView, HierarchicalGraphView {
Expand Down Expand Up @@ -260,7 +261,7 @@ protected Collection<Node> mapWithHidden(final Node node) {
}

if (group.isCollapsed()) {
final Collection<Node> children = group.getChildren(true);
final Collection<Node> children = group.getNodes(true);
final Set<Node> set = new HashSet<Node>(children.size() + 1);
set.add(node);
set.addAll(children);
Expand Down Expand Up @@ -428,16 +429,6 @@ public boolean hasCollapsedParent() {
}
}

public Collection<Node> getChildren(final boolean recursive) {
final Set<Node> set = new HashSet<Node>(this.nodeMap.keySet());
if (recursive) {
for (final HierarchicalNodeGroupImpl child : this.nodeMap.values()) {
set.addAll(child.getChildren(true));
}
}
return Collections.unmodifiableCollection(set);
}

@Override
public boolean isCollapsed() {
graphStore.autoReadLock();
Expand Down Expand Up @@ -481,6 +472,25 @@ public Iterable<Node> getNodes() {
return Collections.unmodifiableCollection(list);
}

@Override
public Collection<Node> getNodes(boolean recursive) {
graphStore.autoReadLock();
final Set<Node> set = new HashSet<Node>(this.nodeMap.size());
try {
if (recursive) {
for (final Map.Entry<Node, HierarchicalNodeGroupImpl> entry : this.nodeMap.entrySet()) {
set.add(entry.getKey());
if (recursive) {
set.addAll(entry.getValue().getNodes(true));
}
}
}
} finally {
graphStore.autoReadUnlock();
}
return Collections.unmodifiableCollection(set);
}

public Collection<HierarchicalNodeGroupImpl> getGroups(final boolean recursive) {
graphStore.autoReadLock();
final List<HierarchicalNodeGroupImpl> list;
Expand Down

0 comments on commit 6ea285b

Please sign in to comment.