소스 검색

add comments to graph package

Eren Yilmaz 6 년 전
부모
커밋
e775e40bbe
5개의 변경된 파일105개의 추가작업 그리고 44개의 파일을 삭제
  1. 17 36
      src/graph/LayeredEdge.java
  2. 0 6
      src/graph/LayeredGraphEdge.java
  3. 60 2
      src/graph/LayeredNode.java
  4. 20 0
      src/graph/io/Reader.java
  5. 8 0
      src/graph/io/Writer.java

+ 17 - 36
src/graph/LayeredEdge.java

@@ -58,7 +58,7 @@ public class LayeredEdge implements LayeredGraphEdge {
 
     @Override
     public boolean isConflicted( LayoutType layout )
-    {
+    {   // see javadoc for better understanding of what this does
         if( layout == LayoutType.LEFTMOST_UPPER )
             return conflicted[ 0 ];
         if( layout == LayoutType.RIGHTMOST_UPPER )
@@ -72,36 +72,9 @@ public class LayeredEdge implements LayeredGraphEdge {
         return false;
     }
     
-    @Override
-    public ArrayList<LayeredGraphEdge> calcEdgeCrossings()
-    {
-        ArrayList<LayeredGraphEdge> list = new ArrayList<>();
-        ArrayList<LayeredGraphNode> l = graph.getContainedLayers().get( sources.get( 0 ).getLayer() );
-        ArrayList<LayeredGraphNode> l2 = graph.getContainedLayers().get( targets.get( 0 ).getLayer() );
-        int startIndex = l.indexOf( sources.get( 0 ) );
-        int endIndex = l2.indexOf( targets.get( 0 ) );
-        for( int i = 0; i < l.size(); i++ )
-        {
-            if( i == startIndex )
-                continue;
-            for( LayeredGraphEdge e : l.get( i ).getOutgoingEdges() )
-            {
-                int i2 = l2.indexOf( e.getTargets().get( 0 ) );
-                if( i2 == endIndex )
-                    continue;
-                if( i < startIndex && i2 > endIndex || i > startIndex && i2 < endIndex )
-                {
-                    if( !list.contains( e ) )
-                        list.add( e );
-                }
-            }
-        }
-        return list;
-    };
-    
     @Override
     public void setConflicted( boolean conflicted, LayoutType layout )
-    {
+    {   // see javadoc for better understanding of what this does
         if( layout == null )
         {
             this.conflicted[ 0 ] = conflicted;
@@ -124,7 +97,7 @@ public class LayeredEdge implements LayeredGraphEdge {
     
     @Override
     public void setStartPoint( int x, int y, LayoutType layout )
-    {
+    {   // see javadoc for better understanding of what this does
         if( layout == null )
         {
             bindPoints[ 0 ].set( 0, new Point( x, y ) );
@@ -147,7 +120,7 @@ public class LayeredEdge implements LayeredGraphEdge {
     
     @Override
     public void addBindPoint( int x, int y, LayoutType layout )
-    {
+    {   // see javadoc for better understanding of what this does
         if( layout == null )
         {
             bindPoints[ 0 ].add( bindPoints[ 0 ].size() - 1, new Point( x, y ) );
@@ -170,7 +143,7 @@ public class LayeredEdge implements LayeredGraphEdge {
     
     @Override
     public void setEndPoint( int x, int y, LayoutType layout )
-    {
+    {   // see javadoc for better understanding of what this does
         if( layout == null )
         {
             bindPoints[ 0 ].set( bindPoints[ 0 ].size() - 1, new Point( x, y ) );
@@ -193,7 +166,7 @@ public class LayeredEdge implements LayeredGraphEdge {
 
     @Override
     public ArrayList<Point> getLinePoints( LayoutType layout )
-    {
+    {   // see javadoc for better understanding of what this does
         NodeView sourceView = ((LayeredNode)sources.get( 0 )).getView( layout );
         NodeView targetView = ((LayeredNode)targets.get( 0 )).getView( layout );
         setStartPoint( sourceView.getVirtualX() + sourceView.getVirtualWidth() / 2, sourceView.getVirtualY() + sourceView.getVirtualHeight(), layout );
@@ -233,12 +206,14 @@ public class LayeredEdge implements LayeredGraphEdge {
 
     @Override
     public boolean isCrossLayerEdge() {
+        // check source
         int sl = sources.get( 0 ).getLayer();
         for( LayeredGraphNode s : sources )
         {
             if( sl != s.getLayer() )
                 return true;
         }
+        // check target
         int tl = targets.get( 0 ).getLayer();
         if( Math.abs( tl - sl ) != 1 )
             return true;
@@ -252,16 +227,17 @@ public class LayeredEdge implements LayeredGraphEdge {
 
     @Override
     public void replaceByDummyNodes() {
-        if( isCrossLayerEdge() )
+        if( isCrossLayerEdge() ) // cross layer edge?
         {
-            remove();
+            remove(); // remove this edge
             if( sources.size() == 1 && targets.size() == 1 )
             {
                 LayeredGraphNode last = sources.get( 0 );
                 int sl = last.getLayer();
                 int tl = targets.get( 0 ).getLayer();
-                for( int i = sl + 1; i < tl; i++ )
+                for( int i = sl + 1; i < tl; i++ ) // for each layer
                 {
+                    // add a dummy edge and a dummy node
                     LayeredGraphNode n = graph.createNode( null );
                     n.setLayer( i );
                     LayeredGraphEdge e = graph.createSimpleEdge( original, last, n );
@@ -270,6 +246,7 @@ public class LayeredEdge implements LayeredGraphEdge {
                         e.setReversedEdge();
                     last = n;
                 }
+                // create last dummy edge
                 LayeredGraphEdge e = graph.createSimpleEdge( original, last, targets.get( 0 ) );
                 e.setDummyEdge();
                 if( reversed )
@@ -295,7 +272,9 @@ public class LayeredEdge implements LayeredGraphEdge {
     public void removeDummyNodes() {
         if( isDummyEdge() )
         {
+            // remove the dummy edge
             remove();
+            // remove the sources
             ArrayList< LayeredGraphNode > sours = sources;
             for( int i = 0; i < sours.size(); i++ )
             {
@@ -310,6 +289,7 @@ public class LayeredEdge implements LayeredGraphEdge {
                     }
                 }
             }
+            // remove the targets
             ArrayList< LayeredGraphNode > targs = targets;
             for( int i = 0; i < targs.size(); i++ )
             {
@@ -325,6 +305,7 @@ public class LayeredEdge implements LayeredGraphEdge {
                 }
                     
             }
+            // add old edge again
             LayeredGraphEdge e = graph.createEdge( original, sours, targs );
             if( reversed )
                 e.setReversedEdge();

+ 0 - 6
src/graph/LayeredGraphEdge.java

@@ -27,12 +27,6 @@ public interface LayeredGraphEdge {
      */
     public boolean isConflicted( LayoutType layout );
     
-    /**
-     * Computes a list of edges that cross this edge.
-     * @return the list.
-     */
-    public ArrayList<LayeredGraphEdge> calcEdgeCrossings();
-    
     /**
      * Mark this edge as conflicted in the given layout.
      * @param conflicted Whether to mark the edge as conflicted or to remove this mark.

+ 60 - 2
src/graph/LayeredNode.java

@@ -68,8 +68,10 @@ public class LayeredNode implements LayeredGraphNode {
      */
     public static LayeredGraphNode convertToLayeredGraph(ElkNode n) {
         LayeredNode ln = new LayeredNode(n, null);
+        // nodes
         for (ElkNode node : n.getChildren())
             ln.addNode(convertToLayeredGraph(node));
+        // edges
         for (ElkEdge edge : n.getContainedEdges()) {
             // TODO n.getProperty(Properties.LAYERPOS) reads position of node n in his layer
             ArrayList<LayeredGraphNode> sources = new ArrayList<>();
@@ -146,6 +148,7 @@ public class LayeredNode implements LayeredGraphNode {
      * @param layout the layout
      */
     public void setView(NodeView view, LayoutType layout) {
+        // see javadoc for better understanding of what this does
         if (layout == LayoutType.LEFTMOST_UPPER)
             this.layouts[0].view = view;
         if (layout == LayoutType.RIGHTMOST_UPPER)
@@ -165,6 +168,7 @@ public class LayeredNode implements LayeredGraphNode {
      * @return the view
      */
     public NodeView getView(LayoutType layout) {
+        // see javadoc for better understanding of what this does
         if (layout == LayoutType.LEFTMOST_UPPER)
             return layouts[0].view;
         if (layout == LayoutType.RIGHTMOST_UPPER)
@@ -190,6 +194,7 @@ public class LayeredNode implements LayeredGraphNode {
 
     @Override
     public void setShift(double shift, LayoutType layout) {
+        // see javadoc for better understanding of what this does
         if (layout == null) {
             this.layouts[0].shift = shift;
             this.layouts[1].shift = shift;
@@ -208,6 +213,7 @@ public class LayeredNode implements LayeredGraphNode {
 
     @Override
     public double getShift(LayoutType layout) {
+        // see javadoc for better understanding of what this does
         if (layout == LayoutType.LEFTMOST_UPPER)
             return this.layouts[0].shift;
         if (layout == LayoutType.RIGHTMOST_UPPER)
@@ -221,6 +227,7 @@ public class LayeredNode implements LayeredGraphNode {
 
     @Override
     public void setSink(LayeredGraphNode sink, LayoutType layout) {
+        // see javadoc for better understanding of what this does
         if (layout == null) {
             this.layouts[0].sink = sink;
             this.layouts[1].sink = sink;
@@ -239,6 +246,7 @@ public class LayeredNode implements LayeredGraphNode {
 
     @Override
     public LayeredGraphNode getSink(LayoutType layout) {
+        // see javadoc for better understanding of what this does
         if (layout == LayoutType.LEFTMOST_UPPER)
             return this.layouts[0].sink;
         if (layout == LayoutType.RIGHTMOST_UPPER)
@@ -252,6 +260,7 @@ public class LayeredNode implements LayeredGraphNode {
 
     @Override
     public boolean isXUndefined(LayoutType layout) {
+        // see javadoc for better understanding of what this does
         if (layout == LayoutType.LEFTMOST_UPPER)
             return this.layouts[0].xUndef;
         if (layout == LayoutType.RIGHTMOST_UPPER)
@@ -265,6 +274,7 @@ public class LayeredNode implements LayeredGraphNode {
 
     @Override
     public void setAlign(LayeredGraphNode align, LayoutType layout) {
+        // see javadoc for better understanding of what this does
         if (layout == null) {
             this.layouts[0].align = align;
             this.layouts[1].align = align;
@@ -283,6 +293,7 @@ public class LayeredNode implements LayeredGraphNode {
 
     @Override
     public LayeredGraphNode getAlign(LayoutType layout) {
+        // see javadoc for better understanding of what this does
         if (layout == LayoutType.LEFTMOST_UPPER)
             return this.layouts[0].align;
         if (layout == LayoutType.RIGHTMOST_UPPER)
@@ -296,6 +307,7 @@ public class LayeredNode implements LayeredGraphNode {
 
     @Override
     public void setRoot(LayeredGraphNode root, LayoutType layout) {
+        // see javadoc for better understanding of what this does
         if (layout == null) {
             this.layouts[0].root = root;
             this.layouts[1].root = root;
@@ -314,6 +326,7 @@ public class LayeredNode implements LayeredGraphNode {
 
     @Override
     public LayeredGraphNode getRoot(LayoutType layout) {
+        // see javadoc for better understanding of what this does
         if (layout == LayoutType.LEFTMOST_UPPER)
             return this.layouts[0].root;
         if (layout == LayoutType.RIGHTMOST_UPPER)
@@ -327,6 +340,7 @@ public class LayeredNode implements LayeredGraphNode {
 
     @Override
     public void setSelected(LayoutType layout) {
+        // see javadoc for better understanding of what this does
         if (layout == null) {
             this.layouts[0].selected = true;
             this.layouts[1].selected = true;
@@ -348,6 +362,7 @@ public class LayeredNode implements LayeredGraphNode {
 
     @Override
     public void unselectGraph() {
+        // see javadoc for better understanding of what this does
         for (LayeredGraphNode n : nodes) {
             n.unselectGraph();
         }
@@ -360,6 +375,7 @@ public class LayeredNode implements LayeredGraphNode {
 
     @Override
     public boolean isSelected(LayoutType layout) {
+        // see javadoc for better understanding of what this does
         if (layout == LayoutType.LEFTMOST_UPPER) {
             return layouts[0].selected;
         }
@@ -381,6 +397,7 @@ public class LayeredNode implements LayeredGraphNode {
     @Override
     public void setColor( Color c, LayoutType layout )
     {
+        // see javadoc for better understanding of what this does
         if( layout == null )
         {
             this.layouts[ 0 ].color = c;
@@ -411,30 +428,39 @@ public class LayeredNode implements LayeredGraphNode {
 
     @Override
     public Color getClassColor(LayoutType layout) {
+        // leftmost upper
         if (layout == LayoutType.LEFTMOST_UPPER && this.layouts[0].sink == this && calcClassSize(this, layout) == 1)
             return Color.LIGHT_GRAY;
         if (layout == LayoutType.LEFTMOST_UPPER && this.layouts[0].sink == this)
             return this.layouts[0].color;
         else if (layout == LayoutType.LEFTMOST_UPPER)
             return this.layouts[0].sink.getClassColor(layout);
+        
+        // rightmost upper
         if (layout == LayoutType.RIGHTMOST_UPPER && this.layouts[1].sink == this && calcClassSize(this, layout) == 1)
             return Color.LIGHT_GRAY;
         if (layout == LayoutType.RIGHTMOST_UPPER && this.layouts[1].sink == this)
             return this.layouts[1].color;
         else if (layout == LayoutType.RIGHTMOST_UPPER)
             return this.layouts[1].sink.getClassColor(layout);
+        
+        // leftmost lower
         if (layout == LayoutType.LEFTMOST_LOWER && this.layouts[2].sink == this && calcClassSize(this, layout) == 1)
             return Color.LIGHT_GRAY;
         if (layout == LayoutType.LEFTMOST_LOWER && this.layouts[2].sink == this)
             return this.layouts[2].color;
         else if (layout == LayoutType.LEFTMOST_LOWER)
             return this.layouts[2].sink.getClassColor(layout);
+        
+        // rightmost lower
         if (layout == LayoutType.RIGHTMOST_LOWER && this.layouts[3].sink == this && calcClassSize(this, layout) == 1)
             return Color.LIGHT_GRAY;
         if( layout == LayoutType.RIGHTMOST_LOWER && this.layouts[ 3 ].sink == this )
             return this.layouts[ 3 ].color;
         else if( layout == LayoutType.RIGHTMOST_LOWER )
             return this.layouts[ 3 ].sink.getClassColor( layout );
+        
+        // no colors in the combined layout
         if( layout == LayoutType.COMBINED )
             return Color.LIGHT_GRAY;
         return null;
@@ -443,6 +469,7 @@ public class LayeredNode implements LayeredGraphNode {
     @Override
     public Color getColor( LayoutType layout )
     {
+        // leftmost upper
         if( layout == null )
             return this.layouts[ 0 ].color;
         if( layout == LayoutType.LEFTMOST_UPPER && this.layouts[ 0 ].root == this && this.layouts[ 0 ].align == this )
@@ -451,12 +478,16 @@ public class LayeredNode implements LayeredGraphNode {
             return this.layouts[0].root.getColor(layout);
         if (layout == LayoutType.LEFTMOST_UPPER)
             return this.layouts[0].color;
+        
+        // rightmost upper
         if (layout == LayoutType.RIGHTMOST_UPPER && this.layouts[1].root == this && this.layouts[1].align == this)
             return Color.LIGHT_GRAY;
         if (layout == LayoutType.RIGHTMOST_UPPER && this.layouts[1].root != this)
             return this.layouts[1].root.getColor(layout);
         if (layout == LayoutType.RIGHTMOST_UPPER)
             return this.layouts[1].color;
+        
+        // leftmost lower
         if (layout == LayoutType.LEFTMOST_LOWER && this.layouts[2].root == this && this.layouts[2].align == this)
             return Color.LIGHT_GRAY;
         if (layout == LayoutType.LEFTMOST_LOWER && this.layouts[2].root != this)
@@ -465,10 +496,14 @@ public class LayeredNode implements LayeredGraphNode {
             return this.layouts[2].color;
         if (layout == LayoutType.RIGHTMOST_LOWER && this.layouts[3].root == this && this.layouts[3].align == this)
             return Color.LIGHT_GRAY;
+        
+        // rightmost lower
         if( layout == LayoutType.RIGHTMOST_LOWER && this.layouts[ 3 ].root != this )
             return this.layouts[ 3 ].root.getColor( layout );
         if( layout == LayoutType.RIGHTMOST_LOWER )
             return this.layouts[ 3 ].color;
+        
+        // no colors in the combined layout
         if( layout == LayoutType.COMBINED )
             return Color.LIGHT_GRAY;
         return null;
@@ -506,6 +541,7 @@ public class LayeredNode implements LayeredGraphNode {
 
     @Override
     public void setX(double x, boolean def, LayoutType layout) {
+        // see javadoc for better understanding of what this does
         if (layout == null) {
             layouts[0].x = x;
             layouts[1].x = x;
@@ -535,6 +571,7 @@ public class LayeredNode implements LayeredGraphNode {
 
     @Override
     public void setY(double y, LayoutType layout) {
+        // see javadoc for better understanding of what this does
         if (layout == null) {
             layouts[0].y = y;
             layouts[1].y = y;
@@ -556,6 +593,7 @@ public class LayeredNode implements LayeredGraphNode {
 
     @Override
     public double getX(LayoutType layout) {
+        // see javadoc for better understanding of what this does
         if (layout == LayoutType.LEFTMOST_UPPER)
             return this.layouts[0].x;
         if (layout == LayoutType.RIGHTMOST_UPPER)
@@ -571,6 +609,7 @@ public class LayeredNode implements LayeredGraphNode {
 
     @Override
     public double getY(LayoutType layout) {
+        // see javadoc for better understanding of what this does
         if (layout == LayoutType.LEFTMOST_UPPER)
             return this.layouts[0].y;
         if (layout == LayoutType.RIGHTMOST_UPPER)
@@ -589,6 +628,7 @@ public class LayeredNode implements LayeredGraphNode {
         if (nodes.size() > 0) {
             double max = 0;
             double min = Double.POSITIVE_INFINITY;
+            // check contained nodes
             for( LayeredGraphNode n : nodes )
             {
                 if( max < n.getX(layout) + n.getWidth(layout) )
@@ -624,6 +664,7 @@ public class LayeredNode implements LayeredGraphNode {
         if( nodes.size() > 0 )
         {
         	double max = 0;
+          // check contained nodes
         	for( LayeredGraphNode n : nodes )
         	{
         		if( max < n.getY(layout) + n.getHeight(layout) )
@@ -655,6 +696,7 @@ public class LayeredNode implements LayeredGraphNode {
 
     @Override
     public void setWidth(double w, LayoutType layout) {
+        // see javadoc for better understanding of what this does
         if (layout == null) {
             this.layouts[0].w = w;
             this.layouts[1].w = w;
@@ -676,6 +718,7 @@ public class LayeredNode implements LayeredGraphNode {
 
     @Override
     public void setHeight(double h, LayoutType layout) {
+        // see javadoc for better understanding of what this does
         if (layout == null) {
             this.layouts[0].h = h;
             this.layouts[1].h = h;
@@ -702,11 +745,14 @@ public class LayeredNode implements LayeredGraphNode {
 
     @Override
     public void removeNode(LayeredGraphNode n) {
+        // remove all edges containing this node
         for (LayeredGraphEdge e : n.getIncomingEdges())
             e.remove();
         for (LayeredGraphEdge e : n.getOutgoingEdges())
             e.remove();
+        // remove node itself
         nodes.remove(n);
+        // remove node from layers
         for (ArrayList<LayeredGraphNode> l : layers) {
             l.remove(n);
         }
@@ -714,18 +760,24 @@ public class LayeredNode implements LayeredGraphNode {
 
     @Override
     public void setNodeLayer(LayeredGraphNode n, int index) {
+        // add new layers
         while (index >= layers.size())
             layers.add(new ArrayList<>());
+        // remove from old layer
         int old = n.getLayer();
         if (old >= 0)
             layers.get(old).remove(n);
+        // add to new layer
         layers.get(index).add(n);
     }
 
     @Override
     public void setOrderedLayer(ArrayList<Double> indizes, int layerIndex) {
+        // which layer?
         ArrayList<LayeredGraphNode> l2 = layers.get(layerIndex);
         ArrayList<LayeredGraphNode> result = new ArrayList<LayeredGraphNode>();
+        
+        // sort layer
         while (indizes.size() > 0) {
             int mIndex = 0;
             double min = indizes.get(0);
@@ -799,7 +851,7 @@ public class LayeredNode implements LayeredGraphNode {
     public ArrayList<LayeredGraphEdge> getOutgoingEdges(LayeredGraphNode n) {
         ArrayList<LayeredGraphEdge> result = new ArrayList<>();
         for( LayeredGraphEdge e : edges )
-        {
+        { // is this edge outgoing?
             if( e.getSources().contains( n ) && !result.contains( e ) )
                 result.add( e );
         }
@@ -810,7 +862,7 @@ public class LayeredNode implements LayeredGraphNode {
     public ArrayList<LayeredGraphEdge> getIncomingEdges(LayeredGraphNode n) {
         ArrayList<LayeredGraphEdge> result = new ArrayList<>();
         for( LayeredGraphEdge e : edges )
-        {
+        { // is this edge incoming?
             if( e.getTargets().contains( n ) && !result.contains( e ) )
                 result.add( e );
         }
@@ -819,10 +871,13 @@ public class LayeredNode implements LayeredGraphNode {
 
     @Override
     public ArrayList<LayeredGraphEdge> getSortedOutgoingEdges(LayeredGraphNode n) {
+        // get edges
         ArrayList<LayeredGraphEdge> result = new ArrayList<>();
     	if( n.getLayer() + 1 >= layers.size() )
     		return result;
         ArrayList< LayeredGraphEdge > unsorted = getOutgoingEdges( n );
+        
+        // sort
         for( LayeredGraphNode node : layers.get( n.getLayer() + 1 ) )
         {
         	for( LayeredGraphEdge e : unsorted )
@@ -836,9 +891,12 @@ public class LayeredNode implements LayeredGraphNode {
 
     @Override
     public ArrayList<LayeredGraphEdge> getSortedIncomingEdges(LayeredGraphNode n) {
+        // get edges
         ArrayList<LayeredGraphEdge> result = new ArrayList<>();
     	if( n.getLayer() - 1 < 0 )
     		return result;
+    	
+        // sort
         ArrayList< LayeredGraphEdge > unsorted = getIncomingEdges( n );
         for( LayeredGraphNode node : layers.get( n.getLayer() - 1 ) )
         {

+ 20 - 0
src/graph/io/Reader.java

@@ -34,6 +34,7 @@ public class Reader {
     public LayeredGraphNode readInputGraph()
     {
         String file = "";
+        // read file
         try {
             BufferedReader r = new BufferedReader( new FileReader( fileName ) );
             String tmp = null;
@@ -43,6 +44,7 @@ public class Reader {
         } catch (IOException e) {
             e.printStackTrace();
         }
+        // parse json
         try {
             JSONObject json = new JSONObject( file );
             return parseNode( json, null );
@@ -57,24 +59,34 @@ public class Reader {
         LayeredGraphNode newNode = new LayeredNode( null, null );
         if( parent != null )
             newNode = parent.createNode( null );
+        
+        // dummy
         if( node.has( "dummy" ) && node.getBoolean( "dummy" ) )
         {
             newNode.setDummyNode( true );
         }
+        
+        // name
         if( node.has( "name" ) )
         {
             if( parent != null && parent.findNodeByName( node.getString( "name" ) ) != null )
                 throw new JSONException( "Node " + node.getString( "name" ) + " is already known" );
             newNode.setName( node.getString( "name" ) );
         }
+        
+        // width
         if( node.has( "width" ) )
             newNode.setWidth( node.getInt( "width" ), null );
         else
             newNode.setWidth( 40, null );
+        
+        // height
         if( node.has( "height" ) )
             newNode.setHeight( node.getInt( "height" ), null );
         else
             newNode.setHeight( 40, null );
+        
+        // layers
         if( node.has( "layers" ) )
         {
             JSONArray layers = node.getJSONArray( "layers" );
@@ -84,6 +96,8 @@ public class Reader {
                     n.setLayer( i );
             }
         }
+        
+        // edges
         if( node.has( "edges" ) )
         {
             JSONArray edges = node.getJSONArray( "edges" );
@@ -98,18 +112,24 @@ public class Reader {
 
     private LayeredGraphEdge parseEdge( JSONObject edge, LayeredGraphNode parent ) throws JSONException
     {
+        // check if attributes are available
         if( !edge.has( "source" ) || !edge.has( "target" ) )
             throw new JSONException( edge + " is not a valid LayeredGraphEdge." );
         if( parent.findNodeByName( edge.getString( "source" ) ) == null )
             throw new JSONException( edge + " is not a valid LayeredGraphEdge." );
         if( parent.findNodeByName( edge.getString( "target" ) ) == null )
             throw new JSONException( edge + " is not a valid LayeredGraphEdge." );
+        
+        // create the edges
         LayeredGraphEdge newEdge = parent.createSimpleEdge( null, parent.findNodeByName( edge.getString( "source" ) ), parent.findNodeByName( edge.getString( "target" ) ) );
         if( parent.findNodeByName( edge.getString( "source" ) ).isDummyNode() && parent.findNodeByName( edge.getString( "target" ) ).isDummyNode() )
             newEdge.setDummyEdge();
         return newEdge;
     }
 
+    /**
+     * parse a whole layer of nodes
+     */
     private ArrayList<LayeredGraphNode> parseLayer( JSONArray layer, LayeredGraphNode parent ) throws JSONException
     {
         ArrayList<LayeredGraphNode> nodes = new ArrayList<>();

+ 8 - 0
src/graph/io/Writer.java

@@ -46,6 +46,7 @@ public class Writer {
         JSONObject node = new JSONObject();
         JSONArray layers = new JSONArray();
         int id = 0;
+        // layers
         for( ArrayList<LayeredGraphNode> l : graph.getContainedLayers() )
         {
             JSONArray layer = new JSONArray();
@@ -57,15 +58,22 @@ public class Writer {
             layers.put( layer );
         }
         node.put( "layers", layers );
+        
+        // edges
         JSONArray edges = new JSONArray();
         for( LayeredGraphEdge e : graph.getContainedEdges() )
         {
             edges.put( parseEdge( e ) );
         }
         node.put( "edges", edges );
+        
+        // name
         node.put( "name", graph.toString() );
+        
+        // dummy
         if( graph.isDummyNode() )
             node.put( "dummy", "true" );
+        
         return node;
     }