Package org.faktorips.runtime.model.type
Class ProductAssociation
- 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.ProductAssociation
-
public class ProductAssociation extends Association
-
-
Constructor Summary
Constructors Constructor Description ProductAssociation(Type type, java.lang.reflect.Method getterMethod, java.lang.reflect.Method addMethod, java.lang.reflect.Method addMethodWithCardinality, java.lang.reflect.Method removeMethod, boolean changingOverTime, java.lang.reflect.Method getLinksMethod)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description <S extends IProductComponent>
SaddTargetObject(S source, java.util.Calendar effectiveDate, IProductComponent target, CardinalityRange cardinality)Adds the target object with the given cardinality to this association in the source object.<S extends IProductComponent>
SaddTargetObjects(S source, java.util.Calendar effectiveDate, java.util.Collection<IProductComponent> targets)Adds the target objects to this association in the source object.<S extends IProductComponent>
SaddTargetObjects(S source, java.util.Calendar effectiveDate, IProductComponent... targets)Adds the target objects to this association in the source object.ProductAssociationcreateOverwritingAssociationFor(Type subType)java.util.Optional<PolicyAssociation>findMatchingAssociation()Returns the matching policy component type association or anempty Optionalif no matching association is defined for this association.<T extends IProductComponent>
java.util.Collection<IProductComponentLink<T>>getLinks(IProductComponent prodCmpt, java.util.Calendar effectiveDate)Retrieves alllinksfor this association from a product component.PolicyAssociationgetMatchingAssociation()Returns the matching policy component type association ornullif no matching association is defined for this association.PolicyCmptTypegetMatchingAssociationSourceType()Returns thePolicyCmptTypeidentified byAssociation.getMatchingAssociationSource()ProductCmptTypegetModelType()Deprecated.UsegetType()ProductAssociationgetSuperAssociation()Returns the association that is overridden by this association if this association overrides another one.ProductCmptTypegetTarget()Returns the target type of this association.java.util.List<IProductComponent>getTargetObjects(IProductComponent productComponentSource, java.util.Calendar effectiveDate)Returns a list of the target(s) of the given product component's association identified by this model type association.ProductCmptTypegetType()Returns theProductCmptTypethis association belongs to.booleanisChangingOverTime()Checks whether this association is changing over time (resides in the generation) or not (resides in the product component).<S extends IProductComponent>
SremoveTargetObjects(S source, java.util.Calendar effectiveDate, java.util.List<IProductComponent> targetsToRemove)Removes the target object from this association in the source object.<S extends IProductComponent>
SremoveTargetObjects(S source, java.util.Calendar effectiveDate, IProductComponent... targetsToRemove)Removes the target object from this association in the source object.-
Methods inherited from class org.faktorips.runtime.model.type.Association
findSuperAssociation, 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, getDescription, getDocumentation, getExtensionPropertyIds, getExtensionPropertyValue, getLabel, getName, getRelevantProductObject, invokeField, invokeMethod
-
-
-
-
Constructor Detail
-
ProductAssociation
public ProductAssociation(Type type, java.lang.reflect.Method getterMethod, java.lang.reflect.Method addMethod, java.lang.reflect.Method addMethodWithCardinality, java.lang.reflect.Method removeMethod, boolean changingOverTime, java.lang.reflect.Method getLinksMethod)
-
-
Method Detail
-
createOverwritingAssociationFor
public ProductAssociation createOverwritingAssociationFor(Type subType)
- Specified by:
createOverwritingAssociationForin classAssociation
-
getType
public ProductCmptType getType()
Returns theProductCmptTypethis association belongs to.
-
getModelType
@Deprecated public ProductCmptType getModelType()
Deprecated.UsegetType()Returns the model type this association belongs to.- Overrides:
getModelTypein classTypePart
-
getTarget
public ProductCmptType getTarget()
Returns the target type of this association.- Overrides:
getTargetin classAssociation
-
getTargetObjects
public java.util.List<IProductComponent> getTargetObjects(IProductComponent productComponentSource, java.util.Calendar effectiveDate)
Returns a list of the target(s) of the given product component's association identified by this model type association. If this association is changing over time (resides in the generation) the date is used to retrieve the correct generation. If the date isnullthe latest generation is used. If the association is not changing over time the date will be ignored.- Parameters:
productComponentSource- a product object corresponding to theProductCmptTypethis association belongs toeffectiveDate- The date that should be used to get theIProductComponentGenerationif this association is changing over time. May benullto get the latest generation.- 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 IProductComponent> S addTargetObjects(S source, java.util.Calendar effectiveDate, java.util.Collection<IProductComponent> 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:SalesProduct <>---- Product <>---- CoverageTypeproducts.addTargetObjects(salesProduct, coveragetypes.addTargetObjects(product, coverageType1, coverageType2));- Parameters:
source- the object to add a target object toeffectiveDate- The date that should be used to get theIProductComponentGenerationif this association is changing over time. May benullto get the latest generation.targets- 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:
- 20.6
-
addTargetObjects
public <S extends IProductComponent> S addTargetObjects(S source, java.util.Calendar effectiveDate, IProductComponent... 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:SalesProduct <>---- Product <>---- CoverageTypeproducts.addTargetObjects(salesProduct, coveragetypes.addTargetObjects(product, coverageType1, coverageType2));- Parameters:
source- the object to add a target object toeffectiveDate- the date that should be used to get theIProductComponentGenerationif this association is changing over time. May benullto get the latest generation.targets- 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:
- 20.6
-
addTargetObject
public <S extends IProductComponent> S addTargetObject(S source, java.util.Calendar effectiveDate, IProductComponent target, CardinalityRange cardinality)
Adds the target object with the given cardinality 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:SalesProduct <>---- Product <>---- CoverageTypeproducts.addTargetObject(salesProduct, coveragetypes.addTargetObject(product, coverageType));- Parameters:
source- the object to add a target object toeffectiveDate- the date that should be used to get theIProductComponentGenerationif this association is changing over time. May benullto get the latest generation.target- the object to add to sourcecardinality- the cardinality range that will be set for the target- 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:
- 20.6
-
removeTargetObjects
public <S extends IProductComponent> S removeTargetObjects(S source, java.util.Calendar effectiveDate, java.util.List<IProductComponent> 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:SalesProduct <>---- Product <>---- CoverageTypeproducts.removeTargetObjects(SalesProduct, coverageTypes.removeTargetObjects(product, coverageType1, coverageType2));- Parameters:
source- the object to remove a target object fromeffectiveDate- the date that should be used to get theIProductComponentGenerationif this association is changing over time. May benullto get the latest generation.targetsToRemove- 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:
- 20.6
-
removeTargetObjects
public <S extends IProductComponent> S removeTargetObjects(S source, java.util.Calendar effectiveDate, IProductComponent... 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:SalesProduct <>---- Product <>---- CoverageTypeproducts.removeTargetObjects(SalesProduct, coverageTypes.removeTargetObjects(product, coverageType1, coverageType2));- Parameters:
source- the object to remove a target object fromeffectiveDate- the date that should be used to get theIProductComponentGenerationif this association is changing over time. May benullto get the latest generation.targetsToRemove- 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:
- 20.6
-
getMatchingAssociationSourceType
public PolicyCmptType getMatchingAssociationSourceType()
Returns thePolicyCmptTypeidentified byAssociation.getMatchingAssociationSource()- Overrides:
getMatchingAssociationSourceTypein classAssociation- Returns:
- The policy component type of the matching association source
- See Also:
Association.getMatchingAssociationSource()
-
getMatchingAssociation
public PolicyAssociation getMatchingAssociation()
Returns the matching policy component type association ornullif no matching association is defined for this association.- Overrides:
getMatchingAssociationin classAssociation- Returns:
- The matching association
-
findMatchingAssociation
public java.util.Optional<PolicyAssociation> findMatchingAssociation()
Returns the matching policy component type association or anempty Optionalif no matching association is defined for this association.- Overrides:
findMatchingAssociationin classAssociation- Returns:
- The matching association
-
isChangingOverTime
public boolean isChangingOverTime()
Checks whether this association is changing over time (resides in the generation) or not (resides in the product component).- Returns:
trueif this association is changing over time, elsefalse
-
getLinks
public <T extends IProductComponent> java.util.Collection<IProductComponentLink<T>> getLinks(IProductComponent prodCmpt, java.util.Calendar effectiveDate)
Retrieves alllinksfor this association from a product component.- Parameters:
prodCmpt- the source product component to retrieve the links fromeffectiveDate- the effective-date of the adjustment (a.k.a. product component generation). Ignored if this is a static association (isChangingOverTime()==false).- Returns:
- the list of all link instances defined in the product component for this association. Returns a list with a single link instance for ..1 associations.
- Throws:
java.lang.IllegalArgumentException- if there is no method annotated with@IpsAssociationLinks. This is the case if the associationis a derived union.- Since:
- 3.22
-
getSuperAssociation
public ProductAssociation 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()
-
-