Package org.faktorips.runtime.model.type
Class PolicyAssociation
- java.lang.Object
-
- org.faktorips.runtime.model.type.ModelElement
-
- org.faktorips.runtime.model.type.TypePart
-
- org.faktorips.runtime.model.type.Association
-
- org.faktorips.runtime.model.type.PolicyAssociation
-
public class PolicyAssociation extends Association
An association between twoPolicyCmptTypes.
-
-
Constructor Summary
Constructors Constructor Description PolicyAssociation(Type type, java.lang.reflect.Method getterMethod, java.lang.reflect.Method addMethod, java.lang.reflect.Method removeMethod)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description <S extends IModelObject>
SaddTargetObjects(S source, java.util.Collection<IModelObject> targets)Adds the target objects to this association in the source object.<S extends IModelObject>
SaddTargetObjects(S source, IModelObject... targets)Adds the target objects to this association in the source object.PolicyAssociationcreateOverwritingAssociationFor(Type subType)java.util.Optional<ProductAssociation>findMatchingAssociation()Returns the matching product component type association or anempty Optionalif no matching association is defined for this association.ProductAssociationgetMatchingAssociation()Returns the matching product component type association ornullif no matching association is defined for this association.ProductCmptTypegetMatchingAssociationSourceType()Returns theProductCmptTypeidentified byAssociation.getMatchingAssociationSource()PolicyCmptTypegetModelType()Deprecated.UsegetType()PolicyAssociationgetSuperAssociation()Returns the association that is overridden by this association if this association overrides another one.PolicyCmptTypegetTarget()Returns the targetTypeof this association.java.util.List<IModelObject>getTargetObjects(IModelObject source)Returns a list of the target(s) of the given model object's association identified by this model type association.PolicyCmptTypegetType()Returns thePolicyCmptTypethis association belongs to.booleanisQualified()Returns whether this association is "qualified".<S extends IModelObject>
SremoveTargetObjects(S source, java.util.List<IModelObject> targetsToRemove)Removes the target object from this association in the source object.<S extends IModelObject>
SremoveTargetObjects(S source, IModelObject... targetsToRemove)Removes the target objects from this association in the source object.-
Methods inherited from class org.faktorips.runtime.model.type.Association
findSuperAssociation, getAnnotation, getAssociationKind, getGetterMethod, getInverseAssociation, getLabelForPlural, getMatchingAssociationName, getMatchingAssociationSource, getMaxCardinality, getMinCardinality, getNamePlural, getUsedName, isDerivedUnion, isMatchingAssociationPresent, isOverriding, isSubsetOfADerivedUnion, isToOneAssociation, toString
-
Methods inherited from class org.faktorips.runtime.model.type.TypePart
getMessageHelper, getMessageKey, getTypeName
-
Methods inherited from class org.faktorips.runtime.model.type.ModelElement
createMessageHelper, getDeprecation, getDescription, getDocumentation, getExtensionPropertyIds, getExtensionPropertyValue, getLabel, getName, getRelevantProductObject, invokeField, invokeMethod, isDeprecated
-
-
-
-
Constructor Detail
-
PolicyAssociation
public PolicyAssociation(Type type, java.lang.reflect.Method getterMethod, java.lang.reflect.Method addMethod, java.lang.reflect.Method removeMethod)
- Parameters:
type- the type the association belongs togetterMethod- the getter method for retrieving all associated instancesaddMethod- the method for associating new instances (add-method for ..N associations, set-method for ..1 associations)removeMethod- the method for removing instances from the association (nullin case of a ..1 association, as no method is generated)
-
-
Method Detail
-
getType
public PolicyCmptType getType()
Returns thePolicyCmptTypethis association belongs to.
-
getModelType
@Deprecated public PolicyCmptType getModelType()
Deprecated.UsegetType()Returns the model type this association belongs to.- Overrides:
getModelTypein classTypePart
-
createOverwritingAssociationFor
public PolicyAssociation createOverwritingAssociationFor(Type subType)
- Specified by:
createOverwritingAssociationForin classAssociation
-
getMatchingAssociationSourceType
public ProductCmptType getMatchingAssociationSourceType()
Returns theProductCmptTypeidentified byAssociation.getMatchingAssociationSource()- Overrides:
getMatchingAssociationSourceTypein classAssociation- Returns:
- The model type object of the matching association source
- See Also:
Association.getMatchingAssociationSource()
-
getMatchingAssociation
public ProductAssociation getMatchingAssociation()
Returns the matching product component type association ornullif no matching association is defined for this association.- Overrides:
getMatchingAssociationin classAssociation- Returns:
- The matching association
-
findMatchingAssociation
public java.util.Optional<ProductAssociation> findMatchingAssociation()
Returns the matching product component type association or anempty Optionalif no matching association is defined for this association.- Overrides:
findMatchingAssociationin classAssociation- Returns:
- The matching association
-
getTarget
public PolicyCmptType getTarget()
Description copied from class:AssociationReturns the targetTypeof this association.- Overrides:
getTargetin classAssociation
-
getTargetObjects
public java.util.List<IModelObject> getTargetObjects(IModelObject source)
Returns a list of the target(s) of the given model object's association identified by this model type association.- Parameters:
source- a model object corresponding to thePolicyCmptTypethis association belongs to- Returns:
- a list of the target(s) of the given model object's association identified by this model type association
- Throws:
java.lang.IllegalArgumentException- if the model object does not have an association fitting this model type association or that association is not accessible for any reason
-
addTargetObjects
public <S extends IModelObject> S addTargetObjects(S source, java.util.Collection<IModelObject> targets)
Adds the target objects to this association in the source object. If this is a ..1 ("to one") association, the target object is set (and thus the potentially existing object is overwritten).The return value is the updated source object. It could be used to directly create a tree of objects. For example with a model like:
You could write such code:Policy <>---- Contract <>---- Coveragecontracts.addTargetObjects(policy, coverages.addTargetObjects(contract, coverage1, coverage2));- Parameters:
source- the object to add a target object totargets- the objects to add to source- Returns:
- the changed source object
- Throws:
java.lang.IllegalArgumentException- if there is no method annotated with@IpsAssociationAdder. This is the case if the associationis a derived union.java.lang.IllegalArgumentException- if there are multiple target objects provided for a ..1 ("to one") association- Since:
- 3.22
-
addTargetObjects
public <S extends IModelObject> S addTargetObjects(S source, IModelObject... targets)
Adds the target objects to this association in the source object. If this is a ..1 ("to one") association, the target object is set (and thus the potentially existing object is overwritten).The return value is the updated source object. It could be used to directly create a tree of objects. For example with a model like:
You could write such code:Policy <>---- Contract <>---- Coveragecontracts.addTargetObjects(policy, coverages.addTargetObjects(contract, coverage1, coverage2));- Parameters:
source- the object to add a target object totargets- the objects to add to source- Returns:
- the changed source object
- Throws:
java.lang.IllegalArgumentException- if there is no method annotated with@IpsAssociationAdder. This is the case if the associationis a derived union.java.lang.IllegalArgumentException- if there are multiple target objects provided for a ..1 ("to one") association- Since:
- 3.22
-
removeTargetObjects
public <S extends IModelObject> S removeTargetObjects(S source, java.util.List<IModelObject> targetsToRemove)
Removes the target object from this association in the source object. Does nothing if the target object is not currently referenced (in this association). Sets tonullif this is a ..1 ("to one") association.The return value is the updated source object. It could be used to directly remove objects in a tree of objects. For example with a model like:
You could write such code:Policy <>---- Contract <>---- Coveragecontracts.removeTargetObjects(policy, coverages.removeTargetObjects(contract, coverage1, coverage2));- Parameters:
source- the object to remove a target object fromtargetsToRemove- the objects to remove from this association in source- Returns:
- the changed source object
- Throws:
java.lang.IllegalArgumentException- if there is no method annotated with@IpsAssociationRemover(or@IpsAssociationAdderfor a ..1 association). This is the case if the associationis a derived union.java.lang.IllegalArgumentException- if there are multiple or no target objects provided for a ..1 ("to one") association- Since:
- 3.22
-
getSuperAssociation
public PolicyAssociation getSuperAssociation()
Description copied from class:AssociationReturns the association that is overridden by this association if this association overrides another one. Otherwise returnsnull.- Overrides:
getSuperAssociationin classAssociation- Returns:
- The association that is overridden by this attribute.
- See Also:
Association.isOverriding()
-
removeTargetObjects
public <S extends IModelObject> S removeTargetObjects(S source, IModelObject... targetsToRemove)
Removes the target objects from this association in the source object. Does nothing if the target object is not currently referenced (in this association). Sets tonullif this is a ..1 ("to one") association.The return value is the updated source object. It could be used to directly remove objects in a tree of objects. For example with a model like:
You could write such code:Policy <>---- Contract <>---- Coveragecontracts.removeTargetObjects(policy, coverages.removeTargetObjects(contract, coverage1, coverage2));- Parameters:
source- the object to remove a target object fromtargetsToRemove- the objects to remove from this association in source- Returns:
- the changed source object
- Throws:
java.lang.IllegalArgumentException- if there is no method annotated with@IpsAssociationRemover(or@IpsAssociationAdderfor a ..1 association). This is the case if the associationis a derived union.java.lang.IllegalArgumentException- if there are multiple target objects provided for a ..1 ("to one") association- Since:
- 3.22
-
isQualified
public boolean isQualified()
Returns whether this association is "qualified". A "qualified"PolicyAssociation's cardinalities are not defined for all targets but per target of the matchingProductAssociation.- Since:
- 22.6
-
-