org.eclipse.emf.henshin.interpreter.impl
Class EGraphImpl

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractSet<E>
          extended by java.util.HashSet<E>
              extended by java.util.LinkedHashSet<EObject>
                  extended by org.eclipse.emf.henshin.interpreter.impl.EGraphImpl
All Implemented Interfaces:
Serializable, Cloneable, Iterable<EObject>, Collection<EObject>, Set<EObject>, EGraph
Direct Known Subclasses:
HenshinEGraph, PartitionedEGraphImpl

public class EGraphImpl
extends LinkedHashSet<EObject>
implements EGraph

Default EGraph implementation. Based on linked hash sets.

See Also:
Serialized Form

Field Summary
protected  ECrossReferenceAdapter crossReferenceAdapter
          Cross reference adapter for determining cross references between registered objects.
protected  Map<EClass,List<EObject>> domainMap
          Mappings from each type to all its instances.
protected  Map<EClass,Set<EClass>> inheritanceMap
          Mappings from each type to all its extending subtypes.
protected  Set<EPackage> packages
          All involved EPackages.
 
Constructor Summary
EGraphImpl()
          Default constructor.
EGraphImpl(Collection<? extends EObject> collection)
          Convenience constructor.
EGraphImpl(EObject object)
          Convenience constructor.
EGraphImpl(int initialCapacity)
          Constructor.
EGraphImpl(Resource resource)
          Convenience constructor.
 
Method Summary
 boolean add(EObject object)
           
 boolean addAll(Collection<? extends EObject> objs)
           
protected  void addChildParentRelation(EClass child, EClass parent)
          Update the inheritance map.
protected  boolean addEPackage(EPackage ePackage)
          Add an EPackage.
 boolean addGraph(EObject object)
          Adds an EObject and all reachable objects to this graph.
 boolean addTree(EObject root)
          Adds an EObject and all its children to this graph.
 void clear()
           
 EGraph copy(Map<EObject,EObject> copies)
          Copy this object graph.
protected  void didAdd(EObject object)
          Notify that an object has been added to the graph.
protected  void didRemove(EObject object)
          Notify that an object has been removed from the graph.
 ECrossReferenceAdapter getCrossReferenceAdapter()
          Get the cross reference adapter of this graph.
protected  Collection<EObject> getDomain(EClass type)
           
 List<EObject> getDomain(EClass type, boolean strict)
          Get all EObjects of this graph which are compatible with the given type.
 int getDomainSize(EClass type, boolean strict)
          Returns the size of the domain for a type.
 List<EObject> getRoots()
          Get the root objects in this graph.
protected  void initializeContents(Collection<? extends EObject> collection)
          Initialize this EGraph.
 boolean remove(Object object)
           
 boolean removeAll(Collection<?> objs)
           
 boolean removeGraph(EObject object)
          Removes an EObject and all reachable objects from this graph.
 boolean removeTree(EObject root)
          Removes an EObject and all its children from this graph.
 String toString()
           
 
Methods inherited from class java.util.HashSet
clone, contains, isEmpty, iterator, size
 
Methods inherited from class java.util.AbstractSet
equals, hashCode
 
Methods inherited from class java.util.AbstractCollection
containsAll, retainAll, toArray, toArray
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Collection
contains, containsAll, equals, hashCode, isEmpty, iterator, retainAll, size, toArray, toArray
 
Methods inherited from interface java.util.Set
contains, containsAll, equals, hashCode, isEmpty, iterator, retainAll, size, toArray, toArray
 

Field Detail

packages

protected final Set<EPackage> packages
All involved EPackages.


domainMap

protected final Map<EClass,List<EObject>> domainMap
Mappings from each type to all its instances.


inheritanceMap

protected final Map<EClass,Set<EClass>> inheritanceMap
Mappings from each type to all its extending subtypes.


crossReferenceAdapter

protected final ECrossReferenceAdapter crossReferenceAdapter
Cross reference adapter for determining cross references between registered objects.

Constructor Detail

EGraphImpl

public EGraphImpl()
Default constructor.


EGraphImpl

public EGraphImpl(int initialCapacity)
Constructor.

Parameters:
initialCapacity - Initial capacity of the graph.

EGraphImpl

public EGraphImpl(EObject object)
Convenience constructor. Adds an object and all reachable objects to this graph.

Parameters:
object - An object.

EGraphImpl

public EGraphImpl(Collection<? extends EObject> collection)
Convenience constructor. Adds a collection of objects and all reachable objects to this graph.

Parameters:
collection - A collection of objects.

EGraphImpl

public EGraphImpl(Resource resource)
Convenience constructor. Adds the contents of a resource and all reachable objects to this graph.

Parameters:
resource - A resource.
Method Detail

initializeContents

protected void initializeContents(Collection<? extends EObject> collection)
Initialize this EGraph.

Parameters:
collection - Collection of objects to be added.

add

public final boolean add(EObject object)
Specified by:
add in interface Collection<EObject>
Specified by:
add in interface Set<EObject>
Overrides:
add in class HashSet<EObject>

didAdd

protected void didAdd(EObject object)
Notify that an object has been added to the graph.

Parameters:
object - Added object.

remove

public final boolean remove(Object object)
Specified by:
remove in interface Collection<EObject>
Specified by:
remove in interface Set<EObject>
Overrides:
remove in class HashSet<EObject>

didRemove

protected void didRemove(EObject object)
Notify that an object has been removed from the graph.

Parameters:
object - Removed object.

addTree

public boolean addTree(EObject root)
Description copied from interface: EGraph
Adds an EObject and all its children to this graph.

Specified by:
addTree in interface EGraph
Parameters:
root - The root object of the tree.
Returns:
true if an object was added.

removeTree

public boolean removeTree(EObject root)
Description copied from interface: EGraph
Removes an EObject and all its children from this graph.

Specified by:
removeTree in interface EGraph
Parameters:
root - The root object of the tree.
Returns:
true if any object was removed.
See Also:
EGraph.addTree(EObject)

addGraph

public boolean addGraph(EObject object)
Description copied from interface: EGraph
Adds an EObject and all reachable objects to this graph. In contrast to EGraph.addTree(EObject) this method adds all referenced objects to the graph, and not just the children of the containment tree.

Specified by:
addGraph in interface EGraph
Parameters:
object - An arbitrary object.
Returns:
true if at least one object was added.

removeGraph

public boolean removeGraph(EObject object)
Description copied from interface: EGraph
Removes an EObject and all reachable objects from this graph.

Specified by:
removeGraph in interface EGraph
Parameters:
object - An arbitrary object.
Returns:
true if any object was removed.
See Also:
EGraph.addGraph(EObject)

addAll

public boolean addAll(Collection<? extends EObject> objs)
Specified by:
addAll in interface Collection<EObject>
Specified by:
addAll in interface Set<EObject>
Overrides:
addAll in class AbstractCollection<EObject>

removeAll

public boolean removeAll(Collection<?> objs)
Specified by:
removeAll in interface Collection<EObject>
Specified by:
removeAll in interface Set<EObject>
Overrides:
removeAll in class AbstractSet<EObject>

clear

public void clear()
Specified by:
clear in interface Collection<EObject>
Specified by:
clear in interface Set<EObject>
Overrides:
clear in class HashSet<EObject>

addEPackage

protected boolean addEPackage(EPackage ePackage)
Add an EPackage. Update the internal inheritance map.

Parameters:
ePackage - EPackage to be added.
Returns:
true if it is new.

addChildParentRelation

protected void addChildParentRelation(EClass child,
                                      EClass parent)
Update the inheritance map. Add a child-parent relationship.

Parameters:
child - Child class.
parent - Parent class.

getDomain

public List<EObject> getDomain(EClass type,
                               boolean strict)
Description copied from interface: EGraph
Get all EObjects of this graph which are compatible with the given type. This returns a fresh and modifiable list.

Specified by:
getDomain in interface EGraph
Parameters:
type - The type of the objects.
strict - Whether subtypes are excluded from the result.
Returns:
A set of EObjects compatible with the type.

getDomainSize

public int getDomainSize(EClass type,
                         boolean strict)
Description copied from interface: EGraph
Returns the size of the domain for a type. The returned number equals the size of the list returned by EGraph.getDomain(EClass, boolean). This method should be used whenever the actual objects are not needed.

Specified by:
getDomainSize in interface EGraph
Parameters:
type - The type.
strict - Whether subtypes are excluded.
Returns:
The size of the domain.

getDomain

protected Collection<EObject> getDomain(EClass type)

getCrossReferenceAdapter

public ECrossReferenceAdapter getCrossReferenceAdapter()
Description copied from interface: EGraph
Get the cross reference adapter of this graph.

Specified by:
getCrossReferenceAdapter in interface EGraph
Returns:
The cross reference adapter.

copy

public EGraph copy(Map<EObject,EObject> copies)
Description copied from interface: EGraph
Copy this object graph. If the parameter map is null the objects in the graph will be copied too. If the map is not null, the images of the map will be used as the new objects.

Specified by:
copy in interface EGraph
Parameters:
copies - Map associating object of this graph to copies. Can be null.
Returns:
The copied version of this EGraph.

getRoots

public List<EObject> getRoots()
Description copied from interface: EGraph
Get the root objects in this graph. This returns a fresh and modifiable list.

Specified by:
getRoots in interface EGraph
Returns:
The root objects.

toString

public String toString()
Overrides:
toString in class AbstractCollection<EObject>