Class PolicyAssociation


public class PolicyAssociation extends Association
An association between two PolicyCmptTypes.
  • Constructor Details

    • PolicyAssociation

      public PolicyAssociation(Type type, Method getterMethod, Method addMethod, Method removeMethod)
      Parameters:
      type - the type the association belongs to
      getterMethod - the getter method for retrieving all associated instances
      addMethod - 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 (null in case of a ..1 association, as no method is generated)
  • Method Details

    • getType

      public PolicyCmptType getType()
      Returns the PolicyCmptType this association belongs to.
      Overrides:
      getType in class TypePart
    • getModelType

      @Deprecated public PolicyCmptType getModelType()
      Deprecated.
      Returns the model type this association belongs to.
      Overrides:
      getModelType in class TypePart
    • createOverwritingAssociationFor

      public PolicyAssociation createOverwritingAssociationFor(Type subType)
      Specified by:
      createOverwritingAssociationFor in class Association
    • getMatchingAssociationSourceType

      public ProductCmptType getMatchingAssociationSourceType()
      Overrides:
      getMatchingAssociationSourceType in class Association
      Returns:
      The model type object of the matching association source
      See Also:
    • getMatchingAssociation

      public ProductAssociation getMatchingAssociation()
      Returns the matching product component type association or null if no matching association is defined for this association.
      Overrides:
      getMatchingAssociation in class Association
      Returns:
      The matching association
    • findMatchingAssociation

      public Optional<ProductAssociation> findMatchingAssociation()
      Returns the matching product component type association or an empty Optional if no matching association is defined for this association.
      Overrides:
      findMatchingAssociation in class Association
      Returns:
      The matching association
    • getTarget

      public PolicyCmptType getTarget()
      Description copied from class: Association
      Returns the target Type of this association.
      Overrides:
      getTarget in class Association
    • getTargetObjects

      public 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 the PolicyCmptType this association belongs to
      Returns:
      a list of the target(s) of the given model object's association identified by this model type association
      Throws:
      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, 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:

       
       Policy <>---- Contract <>---- Coverage
       
       
      You could write such code:
       
            contracts.addTargetObjects(policy,
                coverages.addTargetObjects(contract,
                    coverage1, coverage2));
       
       
      Parameters:
      source - the object to add a target object to
      targets - the objects to add to source
      Returns:
      the changed source object
      Throws:
      IllegalArgumentException - if there is no method annotated with @IpsAssociationAdder. This is the case if the association is a derived union.
      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:

       
       Policy <>---- Contract <>---- Coverage
       
       
      You could write such code:
       
            contracts.addTargetObjects(policy,
                coverages.addTargetObjects(contract,
                    coverage1, coverage2));
       
       
      Parameters:
      source - the object to add a target object to
      targets - the objects to add to source
      Returns:
      the changed source object
      Throws:
      IllegalArgumentException - if there is no method annotated with @IpsAssociationAdder. This is the case if the association is a derived union.
      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, 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 to null if 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:

       
       Policy <>---- Contract <>---- Coverage
       
       
      You could write such code:
       
            contracts.removeTargetObjects(policy,
                coverages.removeTargetObjects(contract,
                    coverage1, coverage2));
       
       
      Parameters:
      source - the object to remove a target object from
      targetsToRemove - the objects to remove from this association in source
      Returns:
      the changed source object
      Throws:
      IllegalArgumentException - if there is no method annotated with @IpsAssociationRemover (or @IpsAssociationAdder for a ..1 association). This is the case if the association is a derived union.
      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: Association
      Returns the association that is overridden by this association if this association overrides another one. Otherwise returns null.
      Overrides:
      getSuperAssociation in class Association
      Returns:
      The association that is overridden by this attribute.
      See Also:
    • 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 to null if 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:

       
       Policy <>---- Contract <>---- Coverage
       
       
      You could write such code:
       
            contracts.removeTargetObjects(policy,
                coverages.removeTargetObjects(contract,
                    coverage1, coverage2));
       
       
      Parameters:
      source - the object to remove a target object from
      targetsToRemove - the objects to remove from this association in source
      Returns:
      the changed source object
      Throws:
      IllegalArgumentException - if there is no method annotated with @IpsAssociationRemover (or @IpsAssociationAdder for a ..1 association). This is the case if the association is a derived union.
      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 matching ProductAssociation.
      Since:
      22.6