commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From c.@apache.org
Subject svn commit: r1302942 - /commons/sandbox/graph/branches/exporters-with-mappers/src/main/java/org/apache/commons/graph/export/DotExporter.java
Date Tue, 20 Mar 2012 15:38:23 GMT
Author: cs
Date: Tue Mar 20 15:38:23 2012
New Revision: 1302942

URL: http://svn.apache.org/viewvc?rev=1302942&view=rev
Log:
factored out property writing for edge/vertex and fixed output format (still more to do!)
for DOT exporter

Modified:
    commons/sandbox/graph/branches/exporters-with-mappers/src/main/java/org/apache/commons/graph/export/DotExporter.java

Modified: commons/sandbox/graph/branches/exporters-with-mappers/src/main/java/org/apache/commons/graph/export/DotExporter.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/branches/exporters-with-mappers/src/main/java/org/apache/commons/graph/export/DotExporter.java?rev=1302942&r1=1302941&r2=1302942&view=diff
==============================================================================
--- commons/sandbox/graph/branches/exporters-with-mappers/src/main/java/org/apache/commons/graph/export/DotExporter.java
(original)
+++ commons/sandbox/graph/branches/exporters-with-mappers/src/main/java/org/apache/commons/graph/export/DotExporter.java
Tue Mar 20 15:38:23 2012
@@ -127,17 +127,7 @@ final class DotExporter<V, E>
     {
         printWriter.format( "  %s", vertex.hashCode() );
 
-        if ( !properties.isEmpty() )
-        {
-            printWriter.write( '[' );
-
-            for ( Entry<String, Object> property : properties.entrySet() )
-            {
-                printWriter.format( "\"%s\"=%s", property.getKey(), property.getValue() );
-            }
-
-            printWriter.format( "];%n" );
-        }
+        printVertexOrEdgeProperties( properties );
     }
 
     @Override
@@ -149,13 +139,22 @@ final class DotExporter<V, E>
                             connector,
                             tail.hashCode() );
 
+        printVertexOrEdgeProperties( properties );
+    }
+    
+    private void printVertexOrEdgeProperties( Map<String, Object> properties )
+    {
         if ( !properties.isEmpty() )
         {
-            printWriter.write( '[' );
+        	int countAddedProperties = 0;
+            printWriter.write( " [" );
 
             for ( Entry<String, Object> property : properties.entrySet() )
             {
-                printWriter.format( "\"%s\"=%s", property.getKey(), property.getValue() );
+            	String formattedString = countAddedProperties == properties.size() - 1 ? "\"%s\"=%s"
: 
+            		                                                                     "\"%s\"=%s
";
+                printWriter.format( formattedString, property.getKey(), property.getValue()
);
+                countAddedProperties++;
             }
 
             printWriter.format( "];%n" );



Mime
View raw message