You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by cs...@apache.org on 2012/03/20 16:14:46 UTC

svn commit: r1302930 - in /commons/sandbox/graph/branches/exporters-with-mappers/src/main/java/org/apache/commons/graph/export: AbstractExporter.java DotExporter.java GraphMLExporter.java

Author: cs
Date: Tue Mar 20 15:14:45 2012
New Revision: 1302930

URL: http://svn.apache.org/viewvc?rev=1302930&view=rev
Log:
removed property setters (withEdgeWeights, etc) from AbstractExporter, replaced them with protected methods (addEdgeProperty, addVertexProperty) that can be called by the concrete implementations

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

Modified: commons/sandbox/graph/branches/exporters-with-mappers/src/main/java/org/apache/commons/graph/export/AbstractExporter.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/branches/exporters-with-mappers/src/main/java/org/apache/commons/graph/export/AbstractExporter.java?rev=1302930&r1=1302929&r2=1302930&view=diff
==============================================================================
--- commons/sandbox/graph/branches/exporters-with-mappers/src/main/java/org/apache/commons/graph/export/AbstractExporter.java (original)
+++ commons/sandbox/graph/branches/exporters-with-mappers/src/main/java/org/apache/commons/graph/export/AbstractExporter.java Tue Mar 20 15:14:45 2012
@@ -62,14 +62,6 @@ abstract class AbstractExporter<V, E, T 
         this.name = name != null ? name : G;
     }
 
-    public abstract <N extends Number> T withEdgeWeights( Mapper<E, N> edgeWeights );
-
-    public abstract <N extends Number> T withVertexWeights( Mapper<V, N> vertexWeights );
-
-    public abstract T withEdgeLabels( Mapper<E, String> edgeLabels );
-
-    public abstract T withVertexLabels( Mapper<V, String> vertexLabels );
-
     public final void to( File outputFile )
         throws GraphExportException
     {
@@ -168,6 +160,16 @@ abstract class AbstractExporter<V, E, T 
     {
         return writer;
     }
+    
+    protected void addVertexProperty(String propertyName, Mapper<V, ?> vertexProperty) 
+    {
+    	this.vertexProperties.put(propertyName, vertexProperty);
+    }
+    
+    protected void addEdgeProperty(String propertyName, Mapper<E, ?> edgeProperty)
+    {
+    	this.edgeProperties.put(propertyName, edgeProperty);
+    }
 
     protected abstract void startSerialization()
         throws Exception;

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=1302930&r1=1302929&r2=1302930&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:14:45 2012
@@ -158,28 +158,18 @@ final class DotExporter<V, E>
         }
     }
 
-    @Override
     public <N extends Number> DotExporter<V, E> withEdgeWeights( Mapper<E, N> edgeWeights )
     {
         // TODO Auto-generated method stub
         return this;
     }
 
-    @Override
-    public <N extends Number> DotExporter<V, E> withVertexWeights( Mapper<V, N> vertexWeights )
-    {
-        // TODO Auto-generated method stub
-        return this;
-    }
-
-    @Override
     public DotExporter<V, E> withEdgeLabels( Mapper<E, String> edgeLabels )
     {
         // TODO Auto-generated method stub
         return this;
     }
 
-    @Override
     public DotExporter<V, E> withVertexLabels( Mapper<V, String> vertexLabels )
     {
         // TODO Auto-generated method stub

Modified: commons/sandbox/graph/branches/exporters-with-mappers/src/main/java/org/apache/commons/graph/export/GraphMLExporter.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/branches/exporters-with-mappers/src/main/java/org/apache/commons/graph/export/GraphMLExporter.java?rev=1302930&r1=1302929&r2=1302930&view=diff
==============================================================================
--- commons/sandbox/graph/branches/exporters-with-mappers/src/main/java/org/apache/commons/graph/export/GraphMLExporter.java (original)
+++ commons/sandbox/graph/branches/exporters-with-mappers/src/main/java/org/apache/commons/graph/export/GraphMLExporter.java Tue Mar 20 15:14:45 2012
@@ -178,28 +178,24 @@ final class GraphMLExporter<V, E>
         return STRING;
     }
 
-    @Override
     public <N extends Number> GraphMLExporter<V, E> withEdgeWeights( Mapper<E, N> edgeWeights )
     {
         // TODO Auto-generated method stub
         return this;
     }
 
-    @Override
     public <N extends Number> GraphMLExporter<V, E> withVertexWeights( Mapper<V, N> vertexWeights )
     {
         // TODO Auto-generated method stub
         return this;
     }
 
-    @Override
     public GraphMLExporter<V, E> withEdgeLabels( Mapper<E, String> edgeLabels )
     {
         // TODO Auto-generated method stub
         return this;
     }
 
-    @Override
     public GraphMLExporter<V, E> withVertexLabels( Mapper<V, String> vertexLabels )
     {
         // TODO Auto-generated method stub



Re: svn commit: r1302930 - in /commons/sandbox/graph/branches/exporters-with-mappers/src/main/java/org/apache/commons/graph/export: AbstractExporter.java DotExporter.java GraphMLExporter.java

Posted by Simone Tripodi <si...@apache.org>.
Hi Claudio,

> the thing is: even if (for example) edge weights are supported in ALL the
> file formats of the world (which is quite plausible), the actual attribute
> will likely be called in different ways for each format: "weight", "w",
> "value" or whatever. So even a unified implementation in AbstractExporter
> should still rely on concrete implementations to discover the name of the
> attribute (see e.g. the static fields DotExporter.WEIGHT and
> DotExporter.LABEL).

OK!

> But it's still fine for me to keep at least the abstract
> common denominator.

OK sounds a reasonable compromise!

>
> Another issue I'm facing: some of the output formats depend on the actual
> type of the printed value. For example in the DOT format, Strings
> (especially those with whitespaces) should be double-quoted while numbers
> (doubles) should not, e.g.:
>
>  * 192 [label="hello world" weight=3.4]
>
> So we should also seek a unified way to keep track of attribute types when
> serializing them, so that each exporter can choose the appropriate output
> format for each of them. I saw the
> "enlistVerticesProperty"/"enlistEdgesProperty" methods in the code, are they
> supposed to help on this matter?
>

I honestly started prototyping that method because of the need of
GraphML of enlisting all properties first :S Can't you discover the
propert type simply by checking the returned object class?

Thanks for taking care of it!
-Simo

http://people.apache.org/~simonetripodi/
http://simonetripodi.livejournal.com/
http://twitter.com/simonetripodi
http://www.99soft.org/

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: svn commit: r1302930 - in /commons/sandbox/graph/branches/exporters-with-mappers/src/main/java/org/apache/commons/graph/export: AbstractExporter.java DotExporter.java GraphMLExporter.java

Posted by Claudio Squarcella <sq...@dia.uniroma3.it>.
Hi,

> yes I think that having the "common denominator" would help on
> avoiding to repeat ourselves in various implementations. Methods in
> the AbstractExporter could be even final, no needs to provide same
> implementation in the different exporters.

the thing is: even if (for example) edge weights are supported in ALL 
the file formats of the world (which is quite plausible), the actual 
attribute will likely be called in different ways for each format: 
"weight", "w", "value" or whatever. So even a unified implementation in 
AbstractExporter should still rely on concrete implementations to 
discover the name of the attribute (see e.g. the static fields 
DotExporter.WEIGHT and DotExporter.LABEL). But it's still fine for me to 
keep at least the abstract common denominator.

Another issue I'm facing: some of the output formats depend on the 
actual type of the printed value. For example in the DOT format, Strings 
(especially those with whitespaces) should be double-quoted while 
numbers (doubles) should not, e.g.:

  * 192 [label="hello world" weight=3.4]

So we should also seek a unified way to keep track of attribute types 
when serializing them, so that each exporter can choose the appropriate 
output format for each of them. I saw the 
"enlistVerticesProperty"/"enlistEdgesProperty" methods in the code, are 
they supposed to help on this matter?

Ciao,
Claudio

-- 
Claudio Squarcella
PhD student at Roma Tre University
http://www.dia.uniroma3.it/~squarcel
http://twitter.com/hyperboreans
http://claudio.squarcella.com/


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: svn commit: r1302930 - in /commons/sandbox/graph/branches/exporters-with-mappers/src/main/java/org/apache/commons/graph/export: AbstractExporter.java DotExporter.java GraphMLExporter.java

Posted by Simone Tripodi <si...@apache.org>.
Hola,

yes I think that having the "common denominator" would help on
avoiding to repeat ourselves in various implementations. Methods in
the AbstractExporter could be even final, no needs to provide same
implementation in the different exporters.

All the best,
-Simo

http://people.apache.org/~simonetripodi/
http://simonetripodi.livejournal.com/
http://twitter.com/simonetripodi
http://www.99soft.org/



On Tue, Mar 20, 2012 at 5:46 PM, Claudio Squarcella
<sq...@dia.uniroma3.it> wrote:
> Hi Simone,
>
>
> On 20/03/2012 17:35, Simone Tripodi wrote:
>>
>> OH :( I liked the fact that commons properties were defined just once
>> in the Abstract impl :(
>
>
> I did it after realizing that the DOT language does not support weights on
> vertices. Of course I could have kept the others (withEdgeWeights,
> withVertexLabels, etc), but we could face the same problem if later we
> introduce a new format that does not support e.g. labels...
>
> WDIT? do you want me to reintegrate the "common denominator" for now?
>
> Claudio
>
> --
> Claudio Squarcella
> PhD student at Roma Tre University
> http://www.dia.uniroma3.it/~squarcel
> http://twitter.com/hyperboreans
> http://claudio.squarcella.com/
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: svn commit: r1302930 - in /commons/sandbox/graph/branches/exporters-with-mappers/src/main/java/org/apache/commons/graph/export: AbstractExporter.java DotExporter.java GraphMLExporter.java

Posted by Claudio Squarcella <sq...@dia.uniroma3.it>.
Hi Simone,

On 20/03/2012 17:35, Simone Tripodi wrote:
> OH :( I liked the fact that commons properties were defined just once
> in the Abstract impl :(

I did it after realizing that the DOT language does not support weights 
on vertices. Of course I could have kept the others (withEdgeWeights, 
withVertexLabels, etc), but we could face the same problem if later we 
introduce a new format that does not support e.g. labels...

WDIT? do you want me to reintegrate the "common denominator" for now?

Claudio

-- 
Claudio Squarcella
PhD student at Roma Tre University
http://www.dia.uniroma3.it/~squarcel
http://twitter.com/hyperboreans
http://claudio.squarcella.com/


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: svn commit: r1302930 - in /commons/sandbox/graph/branches/exporters-with-mappers/src/main/java/org/apache/commons/graph/export: AbstractExporter.java DotExporter.java GraphMLExporter.java

Posted by Simone Tripodi <si...@apache.org>.
OH :( I liked the fact that commons properties were defined just once
in the Abstract impl :(

http://people.apache.org/~simonetripodi/
http://simonetripodi.livejournal.com/
http://twitter.com/simonetripodi
http://www.99soft.org/



On Tue, Mar 20, 2012 at 4:14 PM,  <cs...@apache.org> wrote:
> Author: cs
> Date: Tue Mar 20 15:14:45 2012
> New Revision: 1302930
>
> URL: http://svn.apache.org/viewvc?rev=1302930&view=rev
> Log:
> removed property setters (withEdgeWeights, etc) from AbstractExporter, replaced them with protected methods (addEdgeProperty, addVertexProperty) that can be called by the concrete implementations
>
> Modified:
>    commons/sandbox/graph/branches/exporters-with-mappers/src/main/java/org/apache/commons/graph/export/AbstractExporter.java
>    commons/sandbox/graph/branches/exporters-with-mappers/src/main/java/org/apache/commons/graph/export/DotExporter.java
>    commons/sandbox/graph/branches/exporters-with-mappers/src/main/java/org/apache/commons/graph/export/GraphMLExporter.java
>
> Modified: commons/sandbox/graph/branches/exporters-with-mappers/src/main/java/org/apache/commons/graph/export/AbstractExporter.java
> URL: http://svn.apache.org/viewvc/commons/sandbox/graph/branches/exporters-with-mappers/src/main/java/org/apache/commons/graph/export/AbstractExporter.java?rev=1302930&r1=1302929&r2=1302930&view=diff
> ==============================================================================
> --- commons/sandbox/graph/branches/exporters-with-mappers/src/main/java/org/apache/commons/graph/export/AbstractExporter.java (original)
> +++ commons/sandbox/graph/branches/exporters-with-mappers/src/main/java/org/apache/commons/graph/export/AbstractExporter.java Tue Mar 20 15:14:45 2012
> @@ -62,14 +62,6 @@ abstract class AbstractExporter<V, E, T
>         this.name = name != null ? name : G;
>     }
>
> -    public abstract <N extends Number> T withEdgeWeights( Mapper<E, N> edgeWeights );
> -
> -    public abstract <N extends Number> T withVertexWeights( Mapper<V, N> vertexWeights );
> -
> -    public abstract T withEdgeLabels( Mapper<E, String> edgeLabels );
> -
> -    public abstract T withVertexLabels( Mapper<V, String> vertexLabels );
> -
>     public final void to( File outputFile )
>         throws GraphExportException
>     {
> @@ -168,6 +160,16 @@ abstract class AbstractExporter<V, E, T
>     {
>         return writer;
>     }
> +
> +    protected void addVertexProperty(String propertyName, Mapper<V, ?> vertexProperty)
> +    {
> +       this.vertexProperties.put(propertyName, vertexProperty);
> +    }
> +
> +    protected void addEdgeProperty(String propertyName, Mapper<E, ?> edgeProperty)
> +    {
> +       this.edgeProperties.put(propertyName, edgeProperty);
> +    }
>
>     protected abstract void startSerialization()
>         throws Exception;
>
> 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=1302930&r1=1302929&r2=1302930&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:14:45 2012
> @@ -158,28 +158,18 @@ final class DotExporter<V, E>
>         }
>     }
>
> -    @Override
>     public <N extends Number> DotExporter<V, E> withEdgeWeights( Mapper<E, N> edgeWeights )
>     {
>         // TODO Auto-generated method stub
>         return this;
>     }
>
> -    @Override
> -    public <N extends Number> DotExporter<V, E> withVertexWeights( Mapper<V, N> vertexWeights )
> -    {
> -        // TODO Auto-generated method stub
> -        return this;
> -    }
> -
> -    @Override
>     public DotExporter<V, E> withEdgeLabels( Mapper<E, String> edgeLabels )
>     {
>         // TODO Auto-generated method stub
>         return this;
>     }
>
> -    @Override
>     public DotExporter<V, E> withVertexLabels( Mapper<V, String> vertexLabels )
>     {
>         // TODO Auto-generated method stub
>
> Modified: commons/sandbox/graph/branches/exporters-with-mappers/src/main/java/org/apache/commons/graph/export/GraphMLExporter.java
> URL: http://svn.apache.org/viewvc/commons/sandbox/graph/branches/exporters-with-mappers/src/main/java/org/apache/commons/graph/export/GraphMLExporter.java?rev=1302930&r1=1302929&r2=1302930&view=diff
> ==============================================================================
> --- commons/sandbox/graph/branches/exporters-with-mappers/src/main/java/org/apache/commons/graph/export/GraphMLExporter.java (original)
> +++ commons/sandbox/graph/branches/exporters-with-mappers/src/main/java/org/apache/commons/graph/export/GraphMLExporter.java Tue Mar 20 15:14:45 2012
> @@ -178,28 +178,24 @@ final class GraphMLExporter<V, E>
>         return STRING;
>     }
>
> -    @Override
>     public <N extends Number> GraphMLExporter<V, E> withEdgeWeights( Mapper<E, N> edgeWeights )
>     {
>         // TODO Auto-generated method stub
>         return this;
>     }
>
> -    @Override
>     public <N extends Number> GraphMLExporter<V, E> withVertexWeights( Mapper<V, N> vertexWeights )
>     {
>         // TODO Auto-generated method stub
>         return this;
>     }
>
> -    @Override
>     public GraphMLExporter<V, E> withEdgeLabels( Mapper<E, String> edgeLabels )
>     {
>         // TODO Auto-generated method stub
>         return this;
>     }
>
> -    @Override
>     public GraphMLExporter<V, E> withVertexLabels( Mapper<V, String> vertexLabels )
>     {
>         // TODO Auto-generated method stub
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org