Class PolicyAssociation

    • 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 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 Detail

      • 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 java.util.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
      • 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 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:
        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:

         
         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:
        java.lang.IllegalArgumentException - if there is no method annotated with @IpsAssociationAdder. This is the case if the association is 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:

         
         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:
        java.lang.IllegalArgumentException - if there is no method annotated with @IpsAssociationAdder. This is the case if the association is 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 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:
        java.lang.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.
        java.lang.IllegalArgumentException - if there are multiple or no target objects provided for a ..1 ("to one") association
        Since:
        3.22
      • 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:
        java.lang.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.
        java.lang.IllegalArgumentException - if there are multiple target objects provided for a ..1 ("to one") association
        Since:
        3.22