diff --git a/jung-io/src/main/java/edu/uci/ics/jung/io/GraphMLMetadata.java b/jung-io/src/main/java/edu/uci/ics/jung/io/GraphMLMetadata.java index 8ad62f4f..267bbeab 100644 --- a/jung-io/src/main/java/edu/uci/ics/jung/io/GraphMLMetadata.java +++ b/jung-io/src/main/java/edu/uci/ics/jung/io/GraphMLMetadata.java @@ -8,6 +8,7 @@ */ package edu.uci.ics.jung.io; +import edu.uci.ics.jung.io.graphml.AttributeType; import java.util.function.Function; /** @@ -24,6 +25,10 @@ public class GraphMLMetadata { /** A Function mapping objects to string representations of their values. */ public Function transformer; + public String attributeName; + + public AttributeType attributeType; + /** * Creates a new instance with the specified description, default value, and function. * @@ -31,9 +36,20 @@ public class GraphMLMetadata { * @param default_value the default value for the object, as a String * @param function maps objects of this type to string representations */ - public GraphMLMetadata(String description, String default_value, Function function) { + public GraphMLMetadata( + String description, + String default_value, + Function function, + String attributeName, + AttributeType attributeType) { this.description = description; this.transformer = function; this.default_value = default_value; + this.attributeName = attributeName; + this.attributeType = attributeType; + } + + public GraphMLMetadata(String description, String default_value, Function function) { + this(description, default_value, function, null, null); } } diff --git a/jung-io/src/main/java/edu/uci/ics/jung/io/GraphMLWriter.java b/jung-io/src/main/java/edu/uci/ics/jung/io/GraphMLWriter.java index 7b88e1f8..3a919721 100644 --- a/jung-io/src/main/java/edu/uci/ics/jung/io/GraphMLWriter.java +++ b/jung-io/src/main/java/edu/uci/ics/jung/io/GraphMLWriter.java @@ -13,6 +13,7 @@ import com.google.common.graph.EndpointPair; import com.google.common.graph.Network; +import edu.uci.ics.jung.io.graphml.AttributeType; import java.io.BufferedWriter; import java.io.IOException; import java.io.Writer; @@ -211,6 +212,15 @@ protected void writeEdgeData(Network g, Writer w) throws IOException { protected void writeKeySpecification( String key, String type, GraphMLMetadata ds, BufferedWriter bw) throws IOException { bw.write(" node_transformer) { + String id, + String description, + String default_value, + Function node_transformer, + String attributeName, + AttributeType attributeType) { if (node_data.equals(Collections.EMPTY_MAP)) { node_data = new HashMap>(); } - node_data.put(id, new GraphMLMetadata(description, default_value, node_transformer)); + node_data.put( + id, + new GraphMLMetadata( + description, default_value, node_transformer, attributeName, attributeType)); + } + + public void addNodeData( + String id, String description, String default_value, Function node_transformer) { + addNodeData(id, description, default_value, node_transformer, null, null); } /** @@ -334,11 +357,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 edge_transformer) { + String id, + String description, + String default_value, + Function edge_transformer, + String attributeName, + AttributeType attributeType) { if (edge_data.equals(Collections.EMPTY_MAP)) { edge_data = new HashMap>(); } - edge_data.put(id, new GraphMLMetadata(description, default_value, edge_transformer)); + edge_data.put( + id, + new GraphMLMetadata( + description, default_value, edge_transformer, attributeName, attributeType)); + } + + public void addEdgeData( + String id, String description, String default_value, Function edge_transformer) { + addEdgeData(id, description, default_value, edge_transformer, null, null); } /** diff --git a/jung-io/src/main/java/edu/uci/ics/jung/io/graphml/AttributeType.java b/jung-io/src/main/java/edu/uci/ics/jung/io/graphml/AttributeType.java new file mode 100644 index 00000000..4a8e9660 --- /dev/null +++ b/jung-io/src/main/java/edu/uci/ics/jung/io/graphml/AttributeType.java @@ -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; + } +}