Class SerializableGraph
- java.lang.Object
-
- it.unive.lisa.outputs.serializableGraph.SerializableGraph
-
public class SerializableGraph extends java.lang.Object
A graph that can be serialized. This graph containsSerializableNode
s as nodes, identified through a numeric id. This graph is compound, meaning that each node can contain subnodes, recursively. Nodes are linked bySerializableEdge
s, identifying their bounds through the numeric ids, while also carrying a textual kind. Each node can be enriched with aSerializableNodeDescription
, providing some extra information on each node.
-
-
Constructor Summary
Constructors Constructor Description SerializableGraph()
Builds an empty graph.SerializableGraph(java.lang.String name, java.lang.String description, java.util.SortedSet<SerializableNode> nodes, java.util.SortedSet<SerializableEdge> edges, java.util.SortedSet<SerializableNodeDescription> descriptions)
Builds a graph.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addEdge(SerializableEdge edge)
Adds the given edge to the graph.void
addNode(SerializableNode node)
Adds the given node to the graph.void
addNodeDescription(SerializableNodeDescription desc)
Adds the given node description to the graph.void
dump(java.io.Writer writer)
Dumps this graph, in JSON format through the givenWriter
.boolean
equals(java.lang.Object obj)
java.lang.String
getDescription()
Yields the description of the graph.java.util.SortedSet<SerializableNodeDescription>
getDescriptions()
Yields the set of descriptions of the nodes of this graph.java.util.SortedSet<SerializableEdge>
getEdges()
Yields the set of edges of this graph.java.lang.String
getName()
Yields the name of the graph.java.util.SortedSet<SerializableNode>
getNodes()
Yields the set of nodes of this graph.int
hashCode()
static SerializableGraph
readGraph(java.io.Reader reader)
Reads a graph through the givenReader
, deserializing it as a JSON file.boolean
sameStructure(SerializableGraph other)
Checks if this graph and the given one share the same structure, that is, if they are equal up to the descriptions of their nodes.DotGraph
toDot()
Converts this graph to aDotGraph
.GraphmlGraph
toGraphml(boolean includeSubnodes)
Converts this graph to aGraphmlGraph
.HtmlGraph
toHtml(boolean includeSubnodes, java.lang.String descriptionLabel)
Converts this graph to anHtmlGraph
.java.lang.String
toString()
-
-
-
Constructor Detail
-
SerializableGraph
public SerializableGraph()
Builds an empty graph.
-
SerializableGraph
public SerializableGraph(java.lang.String name, java.lang.String description, java.util.SortedSet<SerializableNode> nodes, java.util.SortedSet<SerializableEdge> edges, java.util.SortedSet<SerializableNodeDescription> descriptions)
Builds a graph.- Parameters:
name
- the name of the graphdescription
- a description of the graphnodes
- the set of nodesedges
- the set of edgesdescriptions
- the descriptions of the nodes
-
-
Method Detail
-
getName
public java.lang.String getName()
Yields the name of the graph.- Returns:
- the name
-
getDescription
public java.lang.String getDescription()
Yields the description of the graph.- Returns:
- the description
-
getNodes
public java.util.SortedSet<SerializableNode> getNodes()
Yields the set of nodes of this graph.- Returns:
- the nodes
-
getEdges
public java.util.SortedSet<SerializableEdge> getEdges()
Yields the set of edges of this graph.- Returns:
- the edges
-
getDescriptions
public java.util.SortedSet<SerializableNodeDescription> getDescriptions()
Yields the set of descriptions of the nodes of this graph.- Returns:
- the descriptions
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
dump
public void dump(java.io.Writer writer) throws java.io.IOException
Dumps this graph, in JSON format through the givenWriter
. If the system propertylisa.json.indent
is set to any value, the json will be formatted.- Parameters:
writer
- the writer to use for dumping the graph- Throws:
java.io.IOException
- if an I/O error occurs while writing
-
addNode
public void addNode(SerializableNode node)
Adds the given node to the graph.- Parameters:
node
- the node to add- Throws:
java.lang.IllegalArgumentException
- if a node with the same id already exists in the graph
-
addNodeDescription
public void addNodeDescription(SerializableNodeDescription desc)
Adds the given node description to the graph.- Parameters:
desc
- the description to add- Throws:
java.lang.IllegalArgumentException
- if a description for the same node already exists in the graph
-
addEdge
public void addEdge(SerializableEdge edge)
Adds the given edge to the graph.- Parameters:
edge
- the edge to add
-
toGraphml
public GraphmlGraph toGraphml(boolean includeSubnodes)
Converts this graph to aGraphmlGraph
.- Parameters:
includeSubnodes
- whether or not sub-nodes should be part of the graph- Returns:
- the converted graph
-
toHtml
public HtmlGraph toHtml(boolean includeSubnodes, java.lang.String descriptionLabel)
Converts this graph to anHtmlGraph
.- Parameters:
includeSubnodes
- whether or not sub-nodes should be part of the graphdescriptionLabel
- the display name of the descriptions, used as label in the collapse/expand toggles- Returns:
- the converted graph
-
readGraph
public static SerializableGraph readGraph(java.io.Reader reader) throws java.io.IOException
Reads a graph through the givenReader
, deserializing it as a JSON file.- Parameters:
reader
- the reader to use for reading the graph- Returns:
- the deserialized graph
- Throws:
java.io.IOException
- if an I/O error occurs while reading
-
sameStructure
public boolean sameStructure(SerializableGraph other)
Checks if this graph and the given one share the same structure, that is, if they are equal up to the descriptions of their nodes. This is effectively the same asequals(Object)
but ignoring the descriptions.- Parameters:
other
- the other graph- Returns:
true
if the given graph has the same structure as this one
-
-