@Override
 public boolean containsRoot(int layer) {
   for (ISimpleNode node : getNodesByLayer(layer)) {
     if (node.isRootNode()) {
       return true;
     }
   }
   return false;
 }
Beispiel #2
0
 @Override
 public IVisualizableNode[] getParents() {
   Set<IVisualizableNode> parents = new LinkedHashSet<IVisualizableNode>();
   for (ISimpleNode node : contentNodes) {
     for (ISimpleNode parent : node.getParents()) {
       parents.add(getContentNodeMap().get(parent));
     }
   }
   return parents.toArray(new IVisualizableNode[parents.size()]);
 }
Beispiel #3
0
 @Override
 public IVisualizableNode[] getChildren() {
   Set<IVisualizableNode> children = new LinkedHashSet<IVisualizableNode>();
   for (ISimpleNode node : contentNodes) {
     for (ISimpleNode child : node.getChildren()) {
       children.add(getContentNodeMap().get(child));
     }
   }
   return children.toArray(new IVisualizableNode[children.size()]);
 }
 private ProperHierarchicalGraph(ISimpleNode[] nodes, int deepestLayer, IGraphType type) {
   this.allNodes = nodes;
   this.deepestLayer = deepestLayer;
   this.type = type;
   for (int index = 1; index - 1 < deepestLayer; index++) {
     nodesByLayer.put(index, new ArrayList<ISimpleNode>());
   }
   for (ISimpleNode node : nodes) {
     nodesByLayer.get(node.getLayer()).add(node);
   }
 }
 private boolean isInvertedTree() {
   if (getNodesByLayer(deepestLayer).length != 1) {
     return false;
   }
   for (int layerIndex = 1; layerIndex <= deepestLayer - 1; layerIndex++) {
     for (ISimpleNode node : getNodesByLayer(layerIndex)) {
       if (node.getChildren().length != 1) {
         return false;
       }
     }
   }
   return true;
 }
 private boolean isTree() {
   if (getNodesByLayer(1).length != 1) {
     return false;
   }
   for (int layerIndex = 2; layerIndex <= deepestLayer; layerIndex++) {
     for (ISimpleNode node : getNodesByLayer(layerIndex)) {
       if (node.getParents().length != 1) {
         return false;
       }
     }
   }
   return true;
 }
 private List<ISimpleNode> insertDummyNodes(IRegularNode node, ISimpleNode child) {
   List<ISimpleNode> dummyNodes = new ArrayList<>();
   node.removeChild(child);
   child.removeParent(node);
   int nodeLayer = node.getLayer();
   ISimpleNode currentChild = child;
   while (currentChild.getLayer() - 1 > nodeLayer) {
     currentChild = createDummyEdge(currentChild);
     dummyNodes.add(currentChild);
   }
   node.addChild(currentChild);
   currentChild.addParent(node);
   return dummyNodes;
 }
 @Override
 public IVisualizableNode[] getParents() {
   List<IVisualizableNode> parentList = new ArrayList<IVisualizableNode>();
   for (ISimpleNode parent : content.getParents()) {
     parentList.add(getContentNodeMap().get(parent));
   }
   return parentList.toArray(new IVisualizableNode[parentList.size()]);
 }
 @Override
 public IVisualizableNode[] getChildren() {
   List<IVisualizableNode> childrenList = new ArrayList<IVisualizableNode>();
   for (ISimpleNode child : content.getChildren()) {
     childrenList.add(getContentNodeMap().get(child));
   }
   return childrenList.toArray(new IVisualizableNode[childrenList.size()]);
 }
 @Override
 public void setNewLayerOrder(int layer, ISimpleNode[] orderedNodes) {
   List<ISimpleNode> layerNodes = nodesByLayer.get(layer);
   boolean equalSize = layerNodes.size() == orderedNodes.length;
   List<ISimpleNode> orderedNodeList = Arrays.asList(orderedNodes);
   boolean newNodes = !layerNodes.containsAll(orderedNodeList);
   if (!equalSize || newNodes) {
     throw new IllegalArgumentException(
         "Layer content must not be changed " + Arrays.deepToString(orderedNodes)); // $NON-NLS-1$
   }
   nodesByLayer.put(layer, orderedNodeList);
   if (layer == 1) {
     return;
   }
   for (ISimpleNode node : nodesByLayer.get(layer - 1)) {
     node.reorderChildren(orderedNodes);
   }
 }
 @Override
 public ISimpleNode[] removeLongEdges(IRegularNode[] acyclicGraph) {
   List<ISimpleNode> hierarchicalGraph = new ArrayList<>();
   Collections.addAll(hierarchicalGraph, acyclicGraph);
   for (IRegularNode node : acyclicGraph) {
     if (node.getLowerToChildren()) {
       int minimumChildLayer = Integer.MAX_VALUE;
       for (ISimpleNode child : node.getChildren()) {
         minimumChildLayer = Math.min(child.getLayer(), minimumChildLayer);
       }
       if (minimumChildLayer > node.getLayer()) {
         node.setLayer(minimumChildLayer - 1);
       }
     }
     for (ISimpleNode child : node.getChildren()) {
       if (isLongEdge(node, child)) {
         List<ISimpleNode> insertedNodes = insertDummyNodes(node, child);
         hierarchicalGraph.addAll(insertedNodes);
       }
     }
   }
   return hierarchicalGraph.toArray(new ISimpleNode[hierarchicalGraph.size()]);
 }
 public ProperHierarchicalGraph(ISimpleNode[] hierarchicalGraph, int deepestLayer) {
   this.allNodes = hierarchicalGraph;
   this.deepestLayer = deepestLayer;
   for (int index = 1; index <= deepestLayer; index++) {
     nodesByLayer.put(index, new ArrayList<ISimpleNode>());
   }
   for (ISimpleNode node : hierarchicalGraph) {
     for (ISimpleNode child : node.getChildren()) {
       String message = node + " and " + child + " are more than one layer apart.";
       Preconditions.checkArgument(child.getLayer() - node.getLayer() == 1, message);
     }
     nodesByLayer.get(node.getLayer()).add(node);
   }
   this.type = identifyGraphType();
 }
 @Override
 public boolean isRootNode() {
   return content.isRootNode();
 }
 private int getChildDistance(IRegularNode node, ISimpleNode child) {
   return child.getLayer() - node.getLayer();
 }
 private DummyNode createDummyEdge(ISimpleNode child) {
   DummyNode dummyNode = new DummyNode(child, child.getLayer() - 1);
   child.addParent(dummyNode);
   return dummyNode;
 }