Class SerializableGraph


  • public class SerializableGraph
    extends java.lang.Object
    A graph that can be serialized. This graph contains SerializableNodes as nodes, identified through a numeric id. This graph is compound, meaning that each node can contain subnodes, recursively. Nodes are linked by SerializableEdges, identifying their bounds through the numeric ids, while also carrying a textual kind. Each node can be enriched with a SerializableNodeDescription, providing some extra information on each node.
    • 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 graph
        description - a description of the graph
        nodes - the set of nodes
        edges - the set of edges
        descriptions - 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 class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • dump

        public void dump​(java.io.Writer writer)
                  throws java.io.IOException
        Dumps this graph, in JSON format through the given Writer. If the system property lisa.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
      • toDot

        public DotGraph toDot()
        Converts this graph to a DotGraph.
        Returns:
        the converted graph
      • toGraphml

        public GraphmlGraph toGraphml​(boolean includeSubnodes)
        Converts this graph to a GraphmlGraph.
        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 an HtmlGraph.
        Parameters:
        includeSubnodes - whether or not sub-nodes should be part of the graph
        descriptionLabel - 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 given Reader, 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 as equals(Object) but ignoring the descriptions.
        Parameters:
        other - the other graph
        Returns:
        true if the given graph has the same structure as this one