コード例 #1
0
 @Override
 public boolean containsRoot(int layer) {
   for (ISimpleNode node : getNodesByLayer(layer)) {
     if (node.isRootNode()) {
       return true;
     }
   }
   return false;
 }
コード例 #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()]);
 }
コード例 #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()]);
 }
コード例 #4
0
 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);
   }
 }
コード例 #5
0
 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;
 }
コード例 #6
0
 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;
 }
コード例 #7
0
 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;
 }
コード例 #8
0
 @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()]);
 }
コード例 #9
0
 @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()]);
 }
コード例 #10
0
 @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);
   }
 }
コード例 #11
0
 @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()]);
 }
コード例 #12
0
 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();
 }
コード例 #13
0
 @Override
 public boolean isRootNode() {
   return content.isRootNode();
 }
コード例 #14
0
 private int getChildDistance(IRegularNode node, ISimpleNode child) {
   return child.getLayer() - node.getLayer();
 }
コード例 #15
0
 private DummyNode createDummyEdge(ISimpleNode child) {
   DummyNode dummyNode = new DummyNode(child, child.getLayer() - 1);
   child.addParent(dummyNode);
   return dummyNode;
 }