-
Notifications
You must be signed in to change notification settings - Fork 1
Getting Started
Both directed and undirected graphs are supported. A directed graph is a graph where edges have direction. The order of declaring an edge matters.
Graph<String> graph = new DirectedGraph<>("directed");
graph.getVertex("A").connectsTo("B").connectsTo("C");
graph.edge("A", "E")
.edge("E", "C");
graph.getVertex("C").connectsFrom("B").connectsTo("D");
In this example edges are created with a color property showing a path. Properties allow clients to add extra information to the graph, vertices or edges. There are even vertex and edge properties that are inherited by all elements in the graph.
Graph<String> graph = new UndirectedGraph<>("undirected");
graph.edge("e", "b", Map.of("color", "green"));
graph.edge("e", "e");
graph.edge("c", "e", Map.of("color", "green"));
graph.edge("c", "b");
graph.edge("a", "b");
graph.edge("a", "c", Map.of("color", "green"));
One of the goals in this project is to support events when the graph changes. With an EventGraph any modification to the graph will result in events being sent. The example implemntation sends events to greenrobot’s EventBus.
First get the dependency
<<<dependency info>>>
Then create the graph.
Consumer<GraphEvent> subscriber = new Consumer<GraphEvent>() {
@Subscribe
void accept(GraphEvent event) {
System.out.println(event);
}
};
EventBus.getDefault().register(subscriber);
Graph<String> graph = new DirectedEventGraph("directedEventGraph", EventBus.getDefault());
graph.edge("A", "B")
.edge("B", "C")
.edge("C", "D");
This will result in each event being printed.
Events describe the history of the graph as it changes and can be used to recreate and exact copy of a graph. Events can be used with graphs-graphviz to visualize the history of the graph.