Interface GraphBuilder<V,​E>

  • Type Parameters:
    V - the type of the decorated vertex value
    E - the type of the decorated edge value
    All Known Implementing Classes:
    GraphBuilderImpl

    public interface GraphBuilder<V,​E>

    The Graph Builder is the entry point of the builder pattern which was designed to create a graph using a fluent api. It allows adding new vertices as well as defining edges between them.

    Since:
    1.0
    Author:
    Andreas Pointner
    • Method Detail

      • getOrAddVertex

        Vertex<V,​E> getOrAddVertex​(V value)
        Method to add a new vertex to the graph builder. This method takes a value, which is used as the decorated value for the created vertex. If there is already another vertex, that confirms to the value then an existing instance of a vertex may be reused.
        Parameters:
        value - the value of the decorated element
        Returns:
        the new created or cached vertex
      • from

        EdgeBuilder<V,​E> from​(V value)
        Start to create a new Edge to the vertex that decorates value. If there is no vertex that decorated the value yet, a new vertex will be created, as it would be using addVertex(Object) method
        Parameters:
        value - the value of the decorated element
        Returns:
        a EdgeBuilder
      • fromByKey

        EdgeBuilder<V,​E> fromByKey​(Object key)
        Start to create a new Edge to the vertex that is identified by the given key. Make sure to add the vertex first, otherwise this method may fail.
        Parameters:
        key - the key which identifies the vertex
        Returns:
        a EdgeBuilder
        Throws:
        IllegalStateException - if no vertex with given key was found
      • toGraph

        Graph<V,​E> toGraph()
        Creates the graph based on the vertices and edges defines in that graph builder. This makes the GraphBuilder as "finished" which means, that all further operations on the graph builder will result in an IllegalStateException.
        Returns:
        a Graph
      • updateKey

        <T> void updateKey​(V element,
                           T key,
                           BiConsumer<V,​T> mapping)
        Allows to update the key for a given node value in the list. The key must only be updated via this method to maintain a consistent state. The element that is passed to this function must be part of the list and must have the old key. The mapping function will be called with the element and the new key, and must update the elements key value.
        Type Parameters:
        T - the type of the key
        Parameters:
        element - the element where the key should be updated
        key - the new key
        mapping - the mapping function to set the new key
      • addGraphCreationCallback

        void addGraphCreationCallback​(Consumer<Graph<V,​E>> callback)
        This method allows adding callback methods, that are applied once the toGraph method is called. One the callback method is added there is no more way to remove it and it will be executed on the graph creation. This method can be used for e.g. adding MetaTags:
        
             graphBuilder.addGraphCreationCallback(g -> g.addMetaTag(new MetaTagImpl<>("key", "value")));
         
        Parameters:
        callback - the callback method to be added
      • addSubGraph

        Graph<V,​E> addSubGraph​(Graph<V,​E> subGraph)

        Adds the subgraph to this graph, and returns a new resulting graph, that represents a view on the elements of the all vertices and edges.

        Note: subGraph is no longer valid afterwards, as the resulting vertices and edges are removed from the graph and added to the new graph.

        Parameters:
        subGraph - the subgraph that should be added
        Returns:
        the resulting snapshot on the subgraph