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. Anyelementof such a graph may or may not refer to anEObjecton 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
EObjectmay 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.
Nodesandedgesare 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 booleanaddEdge(ModelEdge edge)Adds anedgeto the graph if the edge is not already in the graph and its source and target nodes are part of the graph.booleanaddNode(ModelNode node)Adds anodeto 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 ofedgesof 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 ofelementsof 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 ofnodesof the graph referencing the given object.ModelNodegetRoot()booleanremoveEdge(ModelEdge edge)Removes the edge from the graph.booleanremoveNode(ModelNode node)Removes the node and its connected edges from the graph.voidsetRoot(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 theHashSetsused to store nodes and edges internally. The last two parameters influence the number of buckets of theIdentityHashMapsused 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 allownullvalues. In case of anullvalue 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 thenodesof the graph.expectedEdgeToObjectReferences- expected maximum number of objects referenced by theedgesof the graph.
-
-
Method Detail
-
addNode
public boolean addNode(ModelNode node) throws GraphManipulationException
Adds anodeto 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- ifnodeis not in the graph yet but references edgesIllegalArgumentException- ifnodeisnull
-
addEdge
public boolean addEdge(ModelEdge edge) throws GraphManipulationException
Adds anedgeto 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- ifedgeis not in the graph yet but either source or target nodes of the edge are missing in the graphIllegalArgumentException- ifedgeisnull
-
getNodes
public Set<ModelNode> getNodes(org.eclipse.emf.ecore.EObject object)
Returns the set ofnodesof the graph referencing the given object. Does not check for edges referencing the object.- Parameters:
object- object to look up- Returns:
- set of
nodesreferencing the given object
-
getEdges
public Set<ModelEdge> getEdges(org.eclipse.emf.ecore.EObject object)
Returns the set ofedgesof the graph referencing the given object. Does not check for nodes referencing the object.- Parameters:
object- object to look up- Returns:
- set of
edgesreferencing the given object
-
getElements
public Set<ModelGraphElement> getElements(org.eclipse.emf.ecore.EObject object)
Returns the set ofelementsof 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
elementsreferencing 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. Ifrootis notnullit 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- ifrootis neither null nor part of the graph
-
getRoot
public ModelNode getRoot()
-
-