Class GraphExporter<N,E>
- java.lang.Object
-
- com.apple.foundationdb.record.query.plan.temp.explain.GraphExporter<N,E>
-
- Type Parameters:
N
- the network node typeE
- the network edge type
- Direct Known Subclasses:
DotExporter
,GmlExporter
public abstract class GraphExporter<N,E> extends Object
Exports a graph into a DOT file.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
GraphExporter.ClusterProvider<N,E>
Shorthand-type for the extended functional interface.static interface
GraphExporter.ComponentAttributeProvider<T>
Shorthand-type for the extended functional interface.static interface
GraphExporter.ComponentIdProvider<T>
Shorthand-type for the extended functional interface.class
GraphExporter.ExporterContext
Context class used while serializing the graph.
-
Constructor Summary
Constructors Modifier Constructor Description protected
GraphExporter(GraphExporter.ComponentIdProvider<N> vertexIDProvider, GraphExporter.ComponentAttributeProvider<N> vertexAttributeProvider, GraphExporter.ComponentIdProvider<E> edgeIDProvider, GraphExporter.ComponentAttributeProvider<E> edgeAttributeProvider, Map<String,Attribute> graphAttributes, GraphExporter.ClusterProvider<N,E> clusterProvider, GraphExporter.ComponentAttributeProvider<N> clusterAttributeProvider)
Constructs a new GraphExporter object with the given ID, label, attribute, and graph ID providers.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
exportGraph(com.google.common.graph.ImmutableNetwork<N,E> network, Writer writer)
Exports a network in DOT format.protected GraphExporter.ComponentAttributeProvider<N>
getClusterAttributeProvider()
protected GraphExporter.ClusterProvider<N,E>
getClusterProvider()
protected GraphExporter.ComponentAttributeProvider<E>
getEdgeAttributeProvider()
protected String
getEdgeID(E edge)
Get a unique string for a edge which adheres to the current language.GraphExporter.ComponentIdProvider<E>
getEdgeIDProvider()
protected com.google.common.collect.ImmutableMap<String,Attribute>
getGraphAttributes()
protected GraphExporter.ComponentAttributeProvider<N>
getVertexAttributeProvider()
protected String
getVertexID(N node)
Get a unique string for a node which adheres to the current language.protected GraphExporter.ComponentIdProvider<N>
getVertexIDProvider()
protected Map<N,String>
getVertexIds()
protected abstract boolean
isValidId(String idCandidate)
protected abstract void
renderCluster(GraphExporter.ExporterContext context, String clusterId, N head, Set<N> nodeSet, Map<String,Attribute> attributes)
Render a sub cluster.protected void
renderClusters(GraphExporter.ExporterContext context)
Render all sub clusters in a given network.protected abstract void
renderEdge(GraphExporter.ExporterContext context, boolean isDirected, N source, N target, Map<String,Attribute> attributes)
Render an edge.protected void
renderEdges(GraphExporter.ExporterContext context)
Render all edges in a given network.protected abstract void
renderFooter(GraphExporter.ExporterContext context)
Render the footer.protected abstract void
renderGraphAttributes(GraphExporter.ExporterContext context, Map<String,Attribute> attributes)
Render the global graph attributes.protected abstract void
renderHeader(GraphExporter.ExporterContext context, com.google.common.graph.ImmutableNetwork<N,E> graph)
Render the header.protected abstract void
renderNode(GraphExporter.ExporterContext context, N node, Map<String,Attribute> attributes)
Render a node.protected void
renderNodes(GraphExporter.ExporterContext context)
Render all nodes in the given network.
-
-
-
Constructor Detail
-
GraphExporter
protected GraphExporter(@Nonnull GraphExporter.ComponentIdProvider<N> vertexIDProvider, @Nonnull GraphExporter.ComponentAttributeProvider<N> vertexAttributeProvider, @Nonnull GraphExporter.ComponentIdProvider<E> edgeIDProvider, @Nonnull GraphExporter.ComponentAttributeProvider<E> edgeAttributeProvider, @Nonnull Map<String,Attribute> graphAttributes, @Nonnull GraphExporter.ClusterProvider<N,E> clusterProvider, @Nonnull GraphExporter.ComponentAttributeProvider<N> clusterAttributeProvider)
Constructs a new GraphExporter object with the given ID, label, attribute, and graph ID providers. Note that if a label provider conflicts with a label-supplying attribute provider, the label provider is given precedence.- Parameters:
vertexIDProvider
- for generating vertex IDs. Must not be null.vertexAttributeProvider
- for generating vertex attributes. If null, vertex attributes will not be written to the file.edgeIDProvider
- for generating edge IDs. Must not be null.edgeAttributeProvider
- for generating edge attributes. If null, edge attributes will not be written to the file.graphAttributes
- map of global graph-wide attributesclusterProvider
- for partitioning the graph into clusters if warrantedclusterAttributeProvider
- for providing attributes to clusters
-
-
Method Detail
-
getVertexIDProvider
@Nonnull protected GraphExporter.ComponentIdProvider<N> getVertexIDProvider()
-
getVertexAttributeProvider
@Nonnull protected GraphExporter.ComponentAttributeProvider<N> getVertexAttributeProvider()
-
getEdgeIDProvider
@Nonnull public GraphExporter.ComponentIdProvider<E> getEdgeIDProvider()
-
getEdgeAttributeProvider
@Nonnull protected GraphExporter.ComponentAttributeProvider<E> getEdgeAttributeProvider()
-
getGraphAttributes
@Nonnull protected com.google.common.collect.ImmutableMap<String,Attribute> getGraphAttributes()
-
getClusterProvider
@Nonnull protected GraphExporter.ClusterProvider<N,E> getClusterProvider()
-
getClusterAttributeProvider
@Nonnull protected GraphExporter.ComponentAttributeProvider<N> getClusterAttributeProvider()
-
exportGraph
public void exportGraph(@Nonnull com.google.common.graph.ImmutableNetwork<N,E> network, @Nonnull Writer writer)
Exports a network in DOT format.- Parameters:
network
- the network to be exportedwriter
- the context to which the network to be exported
-
getVertexID
@Nonnull protected String getVertexID(@Nonnull N node)
Get a unique string for a node which adheres to the current language.- Parameters:
node
- a node- Returns:
- a unique identifier
-
getEdgeID
@Nonnull protected String getEdgeID(@Nonnull E edge)
Get a unique string for a edge which adheres to the current language.- Parameters:
edge
- a edge- Returns:
- a unique identifier
-
renderHeader
protected abstract void renderHeader(@Nonnull GraphExporter.ExporterContext context, @Nonnull com.google.common.graph.ImmutableNetwork<N,E> graph)
Render the header. To be implemented by subclass.- Parameters:
context
- the contextgraph
- the graph
-
renderGraphAttributes
protected abstract void renderGraphAttributes(@Nonnull GraphExporter.ExporterContext context, @Nonnull Map<String,Attribute> attributes)
Render the global graph attributes. To be implemented by subclass.- Parameters:
context
- the contextattributes
- the attributes of the graph
-
renderNodes
protected void renderNodes(@Nonnull GraphExporter.ExporterContext context)
Render all nodes in the given network.- Parameters:
context
- the context
-
renderNode
protected abstract void renderNode(@Nonnull GraphExporter.ExporterContext context, @Nonnull N node, @Nonnull Map<String,Attribute> attributes)
Render a node. To be implemented by subclass.- Parameters:
context
- the contextnode
- the node to be renderedattributes
- the attributes of the node
-
renderEdges
protected void renderEdges(@Nonnull GraphExporter.ExporterContext context)
Render all edges in a given network.- Parameters:
context
- the context to use
-
renderEdge
protected abstract void renderEdge(@Nonnull GraphExporter.ExporterContext context, boolean isDirected, @Nonnull N source, @Nonnull N target, @Nonnull Map<String,Attribute> attributes)
Render an edge. To be implemented by subclass.- Parameters:
context
- the contextisDirected
- true iff edge is directedsource
- the source node of the edgetarget
- the target node of the edgeattributes
- the attributes of the edge
-
renderClusters
protected void renderClusters(@Nonnull GraphExporter.ExporterContext context)
Render all sub clusters in a given network.- Parameters:
context
- the context to use
-
renderCluster
protected abstract void renderCluster(@Nonnull GraphExporter.ExporterContext context, @Nonnull String clusterId, @Nonnull N head, @Nonnull Set<N> nodeSet, @Nonnull Map<String,Attribute> attributes)
Render a sub cluster. To be implemented by subclass.- Parameters:
context
- the contextclusterId
- id of the cluster, can be used for naming purposeshead
- head node representative of the clusternodeSet
- set of nodes making up the clusterattributes
- the attributes of the sub cluster
-
renderFooter
protected abstract void renderFooter(@Nonnull GraphExporter.ExporterContext context)
Render the footer.- Parameters:
context
- the context
-
-