-
- Type Parameters:
ID
- type of all identifiers in graph
- All Known Subinterfaces:
EventGraph<ID>
- All Known Implementing Classes:
AbstractGraph
,DirectedGraph
,UndirectedGraph
public interface Graph<ID>
A graph is composed of vertices and edges. A vertex is able to connect to other vertices through edges. Edges connect two vertices. A graph can be directed or undirected.Vertices have an 'id' which uniquely identifies the vertex within the graph. Edges have a 'to' and 'from' property which are the ids of the vertex endpoints. Edges are optionally identified.
At all times the graph is valid event when removing connected vertices.
Undirected graphs ignore 'from'/'to' order in edges.
Once a vertex or edge is removed it can no longer modify the graph or be modified.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interface
Graph.Edge<ID>
An edge between two vertices in a graph.static interface
Graph.Vertex<ID>
Vertex of graph.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description Graph.Edge<ID>
edge(ID from, ID to)
Ensures an edge exists between 'from' and 'to' vertices.Graph<ID>
edgeProperty(String name, Object value)
Sets edge property returning this graphOptional<Graph.Edge<ID>>
findEdge(ID id)
finds edge with given id.Optional<Graph.Edge<ID>>
findEdge(ID from, ID to)
Finds edge connecting 'from' and 'to' vertex.Optional<Graph.Vertex<ID>>
findVertex(ID id)
Finds vertex with given id.Map<ID,Graph.Edge<ID>>
getEdgeIds()
Returns a map of edge ids to edges.Map<String,Object>
getEdgeProperties()
Returns an unmodifiable map of edge properties.Optional<Object>
getEdgeProperty(String name)
ReturnsOptional
of an edge property.Collection<Graph.Edge<ID>>
getEdges()
Returns an ordered collection of all edges in this graph.Optional<ID>
getId()
Returns the id of this graph.Map<String,Object>
getProperties()
Returns an unmodifiable map of properties for this graph.Optional<Object>
getProperty(String name)
ReturnsOptional
of a property.Map<String,Object>
getVertexProperties()
Retruns an unmodifiable map of vertex properties.Optional<Object>
getVertexProperty(String name)
ReturnsOptional
of a vertex property.Map<ID,Graph.Vertex<ID>>
getVertices()
Returns an ordered map of all vertices in this graph.Graph<ID>
id(ID id)
Sets the id of this graphboolean
isDirected()
Returns true if this graph is directed.Graph<ID>
property(String name, Object value)
Sets property on this graph returning this graphvoid
removeEdge(ID id)
Removes edge with given idvoid
removeEdge(ID from, ID to)
Removes edge with given from and to.Graph<ID>
removeEdgeProperty(String name)
Removes edge property returning this graphGraph<ID>
removeProperty(String name)
Removes property on this graph returning this graphvoid
removeVertex(ID id)
Removes vertex with given id.Graph<ID>
removeVertexProperty(String name)
Removes vertex property returning this graphvoid
setEdgeProperty(String name, Object value)
Sets edge property.void
setId(ID id)
Sets the id of this graph.void
setProperty(String name, Object value)
Sets property on this graphvoid
setVertexProperty(String name, Object value)
Sets vertex property.Graph.Vertex<ID>
vertex(ID id)
Ensure a vertex exists with id and returns the vertex.Graph<ID>
vertexProperty(String name, Object value)
Sets vertex property returning this graph
-
-
-
Method Detail
-
getVertices
Map<ID,Graph.Vertex<ID>> getVertices()
Returns an ordered map of all vertices in this graph. The key is the vertex id. Ordering is determined by implementing class.- Returns:
- ordered map of all vertices in this graph
-
getEdges
Collection<Graph.Edge<ID>> getEdges()
Returns an ordered collection of all edges in this graph.- Returns:
- ordered collection of all edges
-
getEdgeIds
Map<ID,Graph.Edge<ID>> getEdgeIds()
Returns a map of edge ids to edges.- Returns:
- map of edge ids to edges
-
findVertex
Optional<Graph.Vertex<ID>> findVertex(ID id)
Finds vertex with given id. If vertex is not in this graph the optional is empty.- Parameters:
id
- of vertex- Returns:
- optional of vertex
- Throws:
NullPointerException
- if id is null
-
vertex
Graph.Vertex<ID> vertex(ID id)
Ensure a vertex exists with id and returns the vertex. If the vertex does not exist it is created.- Parameters:
id
- of vertex- Returns:
- created or existing vertex
- Throws:
NullPointerException
- if id is null
-
removeVertex
void removeVertex(ID id)
Removes vertex with given id. If edges connect to the vertex they are removed first.- Parameters:
id
- of vertex- Throws:
NullPointerException
- if id is null
-
findEdge
Optional<Graph.Edge<ID>> findEdge(ID from, ID to)
Finds edge connecting 'from' and 'to' vertex. If edge is not in this graph the optional is empty. The order of 'from' and 'to' does not matter in undirected implementations. However, if the graph is directed 'from' and 'to' must match 'from' and 'to' of the edge exactly.- Parameters:
from
- of edgeto
- of edge- Returns:
- optional of edge
- Throws:
NullPointerException
- if from or to is null
-
findEdge
Optional<Graph.Edge<ID>> findEdge(ID id)
finds edge with given id. If edge is not in this graph the optional is empty.- Parameters:
id
- of edge- Returns:
- optional of edge
- Throws:
NullPointerException
- if id is null
-
edge
Graph.Edge<ID> edge(ID from, ID to)
Ensures an edge exists between 'from' and 'to' vertices. If an edge does not exist it is created. If any of the vertices do not exist they are created.If this graph is undirected and contains an edge connecting 'to' and 'from' the edge will not be created. Undirected graphs ignore 'from'/'to' order in edges.
- Parameters:
from
- of edgeto
- of edge- Returns:
- created or existing edge
-
removeEdge
void removeEdge(ID from, ID to)
Removes edge with given from and to.- Parameters:
from
- of edgeto
- of edge- Throws:
NullPointerException
- if from or to is nullIllegalArgumentException
- if edge does not exist
-
removeEdge
void removeEdge(ID id)
Removes edge with given id- Parameters:
id
- of edge- Throws:
NullPointerException
- if id is nullIllegalArgumentException
- if edge with id does not exist
-
getId
Optional<ID> getId()
Returns the id of this graph. If the id is not set and empty optional is returned.- Returns:
- optional of id
-
setId
void setId(ID id)
Sets the id of this graph.- Parameters:
id
- of graph- Throws:
NullPointerException
- if id is null
-
id
Graph<ID> id(ID id)
Sets the id of this graph- Parameters:
id
- of graph- Returns:
- this graph
- Throws:
NullPointerException
- if id is null
-
isDirected
boolean isDirected()
Returns true if this graph is directed.- Returns:
- if this graph is directed
-
getProperties
Map<String,Object> getProperties()
Returns an unmodifiable map of properties for this graph.- Returns:
- an unmodifiable map of properties for this graph
-
getProperty
Optional<Object> getProperty(String name)
- Parameters:
name
- of property- Returns:
- optional of named proeprty
- Throws:
NullPointerException
- if name is null
-
setProperty
void setProperty(String name, Object value)
Sets property on this graph- Parameters:
name
- of propertyvalue
- of property- Throws:
NullPointerException
- if name or value is null
-
property
Graph<ID> property(String name, Object value)
Sets property on this graph returning this graph- Parameters:
name
- of propertyvalue
- of property- Returns:
- this graph
- Throws:
NullPointerException
- if name or value is null
-
removeProperty
Graph<ID> removeProperty(String name)
Removes property on this graph returning this graph- Parameters:
name
- of property- Returns:
- this graph
- Throws:
NullPointerException
- if name is null
-
getEdgeProperties
Map<String,Object> getEdgeProperties()
Returns an unmodifiable map of edge properties.- Returns:
- an unmodifiable map of edge properties
-
getEdgeProperty
Optional<Object> getEdgeProperty(String name)
ReturnsOptional
of an edge property. If the property does not exist the returnedOptional
is empty.- Parameters:
name
- of property- Returns:
- optional of property
- Throws:
NullPointerException
- if name is null
-
setEdgeProperty
void setEdgeProperty(String name, Object value)
Sets edge property.- Parameters:
name
- of propertyvalue
- of property- Throws:
NullPointerException
- if name or value is null
-
edgeProperty
Graph<ID> edgeProperty(String name, Object value)
Sets edge property returning this graph- Parameters:
name
- of edge propertyvalue
- of edge property- Returns:
- this graph
- Throws:
NullPointerException
- if name or value is null
-
removeEdgeProperty
Graph<ID> removeEdgeProperty(String name)
Removes edge property returning this graph- Parameters:
name
- of property- Returns:
- this graph
- Throws:
NullPointerException
- if name is null
-
getVertexProperties
Map<String,Object> getVertexProperties()
Retruns an unmodifiable map of vertex properties.- Returns:
- an unmodifiable map of vertex properties
-
getVertexProperty
Optional<Object> getVertexProperty(String name)
ReturnsOptional
of a vertex property. If the property does not exist the returnedOptional
is empty.- Parameters:
name
- of property- Returns:
- optional of property
- Throws:
NullPointerException
- if name is null
-
setVertexProperty
void setVertexProperty(String name, Object value)
Sets vertex property.- Parameters:
name
- of propertyvalue
- of property- Throws:
NullPointerException
- if name or value is null
-
vertexProperty
Graph<ID> vertexProperty(String name, Object value)
Sets vertex property returning this graph- Parameters:
name
- of propertyvalue
- of property- Returns:
- created or existing edge
- Throws:
NullPointerException
- if name or value is null
-
removeVertexProperty
Graph<ID> removeVertexProperty(String name)
Removes vertex property returning this graph- Parameters:
name
- of property- Returns:
- this graph
- Throws:
NullPointerException
- if name is null
-
-