Class EntityReference<EntityType extends org.palladiosimulator.pcm.core.entity.Entity>
java.lang.Object
org.palladiosimulator.simulizar.entity.EntityReference<EntityType>
- Type Parameters:
EntityType
- the type of the referenced model entity.
- All Implemented Interfaces:
InterpretableLocationReference
- Direct Known Subclasses:
LinkingResourceReference
,ResourceContainerReference
,UsageScenarioReference
public class EntityReference<EntityType extends org.palladiosimulator.pcm.core.entity.Entity>
extends Object
implements InterpretableLocationReference
The entity reference class serves as a type safe model element pointer. As the blackboard
partitions reflect the current state of the global model at the point in time when the
interpretation started, there can be several model element instances pointing to the same entity.
Storing model elements directly can lead to memory leaks, as older resource sets which are not
referenced by interpreters anymore are not properly cleaned up. The entity model reference allows
to access the model element directly given a
PCMResourceSetPartition
. It encapsulates the
required lookup logic. Once a lookup is done, the model element is cached, but may be cleaned up
by the garbage collector.
Using an entity reference has the advantage of giving some semantics and type-safety to a
Identifier.getId()
. It can be stored, and checked for equality using
Object.equals(Object)
and Object.hashCode()
.
NOTE: In order to provide a more efficient model element lookup mechanism a specialized
implementation can be provided. The default behavior is to check the ID of every single Entity in
the provided partition until a suitable match is found.-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
EntityReference.AbstractEntityReferenceFactory<EntityType extends org.palladiosimulator.pcm.core.entity.Entity>
-
Method Summary
Modifier and TypeMethodDescriptionboolean
getId()
Provides an identifier, which is derived based on all of the representing entities.getModelElement
(org.palladiosimulator.analyzer.workflow.blackboard.PCMResourceSetPartition partition) Gets the model element of the referenced entity from the given resource set partition.getModelElementIfPresent
(org.palladiosimulator.analyzer.workflow.blackboard.PCMResourceSetPartition partition) Gets the model element of the referenced entity from the given resource set partition.int
hashCode()
boolean
isLocationIdentifiedBy
(EntityReference<?>... entityReferences) Checks whether the referenced location is represented by the union of the provided references.protected Iterator<EntityType>
retrieveModelElements
(org.palladiosimulator.analyzer.workflow.blackboard.PCMResourceSetPartition partition)
-
Method Details
-
getModelElement
public EntityType getModelElement(org.palladiosimulator.analyzer.workflow.blackboard.PCMResourceSetPartition partition) Gets the model element of the referenced entity from the given resource set partition. -
getModelElementIfPresent
public Optional<EntityType> getModelElementIfPresent(org.palladiosimulator.analyzer.workflow.blackboard.PCMResourceSetPartition partition) Gets the model element of the referenced entity from the given resource set partition. -
getId
-
retrieveModelElements
protected Iterator<EntityType> retrieveModelElements(org.palladiosimulator.analyzer.workflow.blackboard.PCMResourceSetPartition partition) -
hashCode
public int hashCode() -
equals
-
isLocationIdentifiedBy
Description copied from interface:InterpretableLocationReference
Checks whether the referenced location is represented by the union of the provided references.- Specified by:
isLocationIdentifiedBy
in interfaceInterpretableLocationReference
- Returns:
- true, if the location is the same
-
getLocationIdentifier
Description copied from interface:InterpretableLocationReference
Provides an identifier, which is derived based on all of the representing entities. The identifier can be used as a lookup key for storing related elements is hash map like data structs.- Specified by:
getLocationIdentifier
in interfaceInterpretableLocationReference
- Returns:
- a stable identifier, uniquely determined based on the representing elements.
-