-
Notifications
You must be signed in to change notification settings - Fork 115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
see #199: add support for attr.name and attr.type #200
base: master
Are you sure you want to change the base?
Changes from 1 commit
8fc3cae
f2577f2
3ffea6e
9144b49
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,9 @@ | |
|
||
import com.google.common.graph.EndpointPair; | ||
import com.google.common.graph.Network; | ||
import edu.uci.ics.jung.io.graphml.AttributeType; | ||
|
||
import java.beans.XMLEncoder; | ||
import java.io.BufferedWriter; | ||
import java.io.IOException; | ||
import java.io.Writer; | ||
|
@@ -211,6 +214,11 @@ protected void writeEdgeData(Network<N, E> g, Writer w) throws IOException { | |
protected void writeKeySpecification( | ||
String key, String type, GraphMLMetadata<?> ds, BufferedWriter bw) throws IOException { | ||
bw.write("<key id=\"" + key + "\" for=\"" + type + "\""); | ||
|
||
if (null != ds.attributeName) | ||
bw.write(" attr.name=\"" + ds.attributeName.replace("\"", """) + "\""); | ||
if (null != ds.attributeType) bw.write(" attr.type=\"" + ds.attributeType.getValue() + "\""); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems that these if statements are lacking braces. Please run There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Uhm, the formatter isn't adding the braces, I'll add them. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oops, very sorry, I thought it did! Thank your very much for adding them anyway. :) |
||
|
||
boolean closed = false; | ||
// write out description if any | ||
String desc = ds.description; | ||
|
@@ -318,11 +326,24 @@ public void addGraphData( | |
* @param node_transformer a mapping from nodes to their string representations | ||
*/ | ||
public void addNodeData( | ||
String id, String description, String default_value, Function<N, String> node_transformer) { | ||
String id, | ||
String description, | ||
String default_value, | ||
Function<N, String> node_transformer, | ||
String attributeName, | ||
AttributeType attributeType) { | ||
if (node_data.equals(Collections.EMPTY_MAP)) { | ||
node_data = new HashMap<String, GraphMLMetadata<N>>(); | ||
} | ||
node_data.put(id, new GraphMLMetadata<N>(description, default_value, node_transformer)); | ||
node_data.put( | ||
id, | ||
new GraphMLMetadata<N>( | ||
description, default_value, node_transformer, attributeName, attributeType)); | ||
} | ||
|
||
public void addNodeData( | ||
String id, String description, String default_value, Function<N, String> node_transformer) { | ||
addNodeData(id, description, default_value, node_transformer, null, null); | ||
} | ||
|
||
/** | ||
|
@@ -334,11 +355,24 @@ public void addNodeData( | |
* @param edge_transformer a mapping from edges to their string representations | ||
*/ | ||
public void addEdgeData( | ||
String id, String description, String default_value, Function<E, String> edge_transformer) { | ||
String id, | ||
String description, | ||
String default_value, | ||
Function<E, String> edge_transformer, | ||
String attributeName, | ||
AttributeType attributeType) { | ||
if (edge_data.equals(Collections.EMPTY_MAP)) { | ||
edge_data = new HashMap<String, GraphMLMetadata<E>>(); | ||
} | ||
edge_data.put(id, new GraphMLMetadata<E>(description, default_value, edge_transformer)); | ||
edge_data.put( | ||
id, | ||
new GraphMLMetadata<E>( | ||
description, default_value, edge_transformer, attributeName, attributeType)); | ||
} | ||
|
||
public void addEdgeData( | ||
String id, String description, String default_value, Function<E, String> edge_transformer) { | ||
addEdgeData(id, description, default_value, edge_transformer, null, null); | ||
} | ||
|
||
/** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package edu.uci.ics.jung.io.graphml; | ||
|
||
public enum AttributeType { | ||
BOOLEAN("boolean"), | ||
INT("int"), | ||
LONG("long"), | ||
FLOAT("float"), | ||
DOUBLE("double"), | ||
STRING("string"); | ||
|
||
private final String value; | ||
|
||
AttributeType(String value) { | ||
this.value = value; | ||
} | ||
|
||
public String getValue() { | ||
return value; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ziodave It looks to me that
java.beans.XMLEncoder
is never used, so this import should be removed if possible.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ta!