Class ModelGraph
- java.lang.Object
-
- de.uni_marburg.mdo_over.model.modelgraph.ModelGraph
-
public class ModelGraph extends Object
ModelGraph is meant to represent (parts of) EMF models in a simple graph structure. Anyelement
of such a graph may or may not refer to anEObject
on the EMF side allowing the user to work with graphs mapping only partially to an existing EMF model. A root node may be specified but note that this class does not tie specific semantics to it.There are intentionally no restrictions on how often the same
EObject
may be referenced by different elements of the graph. Some examples where this may be useful are:- One-to-one mappings where edges refer to probably many-valued EReferences, i.e., an EReference may be represented by multiple edges.
- Abstract model representations where EReferences are represented as nodes.
Nodes
andedges
are stored in the order of their insertion into the graph.- Author:
- S. John
-
-
Constructor Summary
Constructors Constructor Description ModelGraph()
ModelGraph(Integer expNodes, Integer expEdges, Integer expNodeToObjectReferences, Integer expectedEdgeToObjectReferences)
Creates a graph anticipating the maximum number of nodes, edges and objects referenced by either the set of nodes or the set of edges.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
addEdge(ModelEdge edge)
Adds anedge
to the graph if the edge is not already in the graph and its source and target nodes are part of the graph.boolean
addNode(ModelNode node)
Adds anode
to the graph if the node is not already in the graph and does not reference any edges.Set<org.eclipse.emf.ecore.EObject>
getAllEdgeReferences()
Set<org.eclipse.emf.ecore.EObject>
getAllNodeReferences()
Set<ModelEdge>
getEdges()
The edges of the graph are returned in the order of their insertion.Set<ModelEdge>
getEdges(org.eclipse.emf.ecore.EObject object)
Returns the set ofedges
of the graph referencing the given object.Set<ModelGraphElement>
getElements()
Returns all elements of the graph.Set<ModelGraphElement>
getElements(org.eclipse.emf.ecore.EObject object)
Returns the set ofelements
of the graph referencing the given object.Set<ModelNode>
getNodes()
The nodes of the graph are returned in the order of their insertion.Set<ModelNode>
getNodes(org.eclipse.emf.ecore.EObject object)
Returns the set ofnodes
of the graph referencing the given object.ModelNode
getRoot()
boolean
removeEdge(ModelEdge edge)
Removes the edge from the graph.boolean
removeNode(ModelNode node)
Removes the node and its connected edges from the graph.void
setRoot(ModelNode root)
Sets the root node of this graph.
-
-
-
Constructor Detail
-
ModelGraph
public ModelGraph()
-
ModelGraph
public ModelGraph(Integer expNodes, Integer expEdges, Integer expNodeToObjectReferences, Integer expectedEdgeToObjectReferences)
Creates a graph anticipating the maximum number of nodes, edges and objects referenced by either the set of nodes or the set of edges. The first two parameters influence the number of buckets of theHashSets
used to store nodes and edges internally. The last two parameters influence the number of buckets of theIdentityHashMaps
used to store the mappings between objects and their referencingelements
. All parameters have an impact on performance and, if possible, should be chosen carefully to prevent excessive rehashing (to few buckets) and lengthy iterations (too many buckets). Parameters are specified as Integer objects to allownull
values. In case of anull
value the standard size of the respective data structure will be used.- Parameters:
expNodes
- expected maximum number of nodes stored in the graphexpEdges
- expected maximum number of edges stored in the graphexpNodeToObjectReferences
- expected maximum number of objects referenced by thenodes
of the graph.expectedEdgeToObjectReferences
- expected maximum number of objects referenced by theedges
of the graph.
-
-
Method Detail
-
addNode
public boolean addNode(ModelNode node) throws GraphManipulationException
Adds anode
to the graph if the node is not already in the graph and does not reference any edges.- Parameters:
node
- node to be added to the graph- Returns:
- true if the node has successfully been added - false otherwise
- Throws:
GraphManipulationException
- ifnode
is not in the graph yet but references edgesIllegalArgumentException
- ifnode
isnull
-
addEdge
public boolean addEdge(ModelEdge edge) throws GraphManipulationException
Adds anedge
to the graph if the edge is not already in the graph and its source and target nodes are part of the graph.- Parameters:
edge
- edge to be added to the graph- Returns:
- true if the edge has successfully been added - false otherwise
- Throws:
GraphManipulationException
- ifedge
is not in the graph yet but either source or target nodes of the edge are missing in the graphIllegalArgumentException
- ifedge
isnull
-
getNodes
public Set<ModelNode> getNodes(org.eclipse.emf.ecore.EObject object)
Returns the set ofnodes
of the graph referencing the given object. Does not check for edges referencing the object.- Parameters:
object
- object to look up- Returns:
- set of
nodes
referencing the given object
-
getEdges
public Set<ModelEdge> getEdges(org.eclipse.emf.ecore.EObject object)
Returns the set ofedges
of the graph referencing the given object. Does not check for nodes referencing the object.- Parameters:
object
- object to look up- Returns:
- set of
edges
referencing the given object
-
getElements
public Set<ModelGraphElement> getElements(org.eclipse.emf.ecore.EObject object)
Returns the set ofelements
of the graph referencing the given object. Iterating over the elements will first iterate over all nodes and then over all edges referencing the object in the order of their insertion into the graph, respectively.- Parameters:
object
- object to look up- Returns:
- set of
elements
referencing the given object
-
getNodes
public Set<ModelNode> getNodes()
The nodes of the graph are returned in the order of their insertion.- Returns:
- the nodes
-
getEdges
public Set<ModelEdge> getEdges()
The edges of the graph are returned in the order of their insertion.- Returns:
- the edges
-
getElements
public Set<ModelGraphElement> getElements()
Returns all elements of the graph. Iterating over the elements will first iterate over all nodes and then over all edges in the order of their insertion into the graph, respectively.- Returns:
-
removeNode
public boolean removeNode(ModelNode node)
Removes the node and its connected edges from the graph.- Parameters:
node
- a node to remove from the graph- Returns:
- true if the node was present in the graph - false otherwise
-
removeEdge
public boolean removeEdge(ModelEdge edge)
Removes the edge from the graph.- Parameters:
edge
- an edege to remove from the graph- Returns:
- true if the edge was present in the graph - false otherwise
-
getAllNodeReferences
public Set<org.eclipse.emf.ecore.EObject> getAllNodeReferences()
-
getAllEdgeReferences
public Set<org.eclipse.emf.ecore.EObject> getAllEdgeReferences()
-
setRoot
public void setRoot(ModelNode root) throws GraphManipulationException
Sets the root node of this graph. Ifroot
is notnull
it needs to be part of the graph. The semantics of the root are not defined here and may depend on the context in which the graph is used.- Parameters:
root
- the node which should be treated as the root- Throws:
GraphManipulationException
- ifroot
is neither null nor part of the graph
-
getRoot
public ModelNode getRoot()
-
-