Package science.aist.gtf.graph.builder
Interface GraphBuilder<V,E>
-
- Type Parameters:
V
- the type of the decorated vertex valueE
- 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 Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
addGraphCreationCallback(Consumer<Graph<V,E>> callback)
This method allows adding callback methods, that are applied once the toGraph method is called.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.GraphBuilder<V,E>
addVertex(V value)
Same asgetOrAddVertex(Object)
but it returns the builder itself to provide a fluent way.VertexBuilderWith<V,E>
addVertexWith(V value)
Same asaddVertex(Object)
but returns aVertexBuilderWith
that allows to use a callback method for the returned vertex, to be able to add additional parameters (e.g.EdgeBuilder<V,E>
from(V value)
Start to create a new Edge to the vertex that decorates value.EdgeBuilder<V,E>
fromByKey(Object key)
Start to create a new Edge to the vertex that is identified by the given key.GraphStateAccessor<V,E>
getGraphState()
Returns a readonly version of the current graph state.Vertex<V,E>
getOrAddVertex(V value)
Method to add a new vertex to the graph builder.Graph<V,E>
toGraph()
Creates the graph based on the vertices and edges defines in that graph builder.<T> void
updateKey(V element, T key, BiConsumer<V,T> mapping)
Allows to update the key for a given node value in the list.
-
-
-
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
-
addVertex
GraphBuilder<V,E> addVertex(V value)
Same asgetOrAddVertex(Object)
but it returns the builder itself to provide a fluent way.- Parameters:
value
- the value of the decorated element- Returns:
- the graph builder instance
- See Also:
getOrAddVertex(Object)
-
addVertexWith
VertexBuilderWith<V,E> addVertexWith(V value)
Same asaddVertex(Object)
but returns aVertexBuilderWith
that allows to use a callback method for the returned vertex, to be able to add additional parameters (e.g.MetaTag
s)- Parameters:
value
- the value of the decorated element- Returns:
- a
VertexBuilderWith
-
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 usingaddVertex(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 anIllegalStateException
.- Returns:
- a
Graph
-
getGraphState
GraphStateAccessor<V,E> getGraphState()
Returns a readonly version of the current graph state.- Returns:
- the current graph state of the builder
- See Also:
GraphState.readonly()
-
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 updatedkey
- the new keymapping
- 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
-
-