Class InstanceSpecificationHelper

  • Direct Known Subclasses:
    ModelHelper

    @OpenApiAll
    public class InstanceSpecificationHelper
    extends ClassifierHelper
    An utility class with utility methods operating on InstanceSpecification domain elements
    • Constructor Detail

      • InstanceSpecificationHelper

        public InstanceSpecificationHelper()
    • Method Detail

      • findSlot

        @CheckForNull
        public static Slot findSlot​(InstanceSpecification instanceSpecification,
                                    Property property)
        Looks for existing slot for a given property in given instance.
        Parameters:
        instanceSpecification - instance
        property - definingFeature of slot
        Returns:
        found slot or null
      • getSlot

        @CheckForNull
        public static Slot getSlot​(InstanceSpecification instance,
                                   Property property,
                                   boolean createSlotIfNotExists)
        Returns existing of creates a new Slot for the given property. If new Slot is created, it will be filled with value from the property default values.
        Parameters:
        instance - instance specification
        property - feature
        createSlotIfNotExists - create a new slot if needed
        Returns:
        slot
      • getSlot

        @CheckForNull
        public static Slot getSlot​(InstanceSpecification instance,
                                   Property property,
                                   boolean createSlotIfNotExists,
                                   boolean createDefaultValue)
        Returns existing of creates a new Slot for the given property
        Parameters:
        instance - instance specification
        property - feature
        createSlotIfNotExists - create a new slot if needed
        createDefaultValue - fill slot value from property default value
        Returns:
        slot
      • createSlotsForDefaultValues

        public static void createSlotsForDefaultValues​(InstanceSpecification instance,
                                                       boolean createAll)
        Creates slots for properties of all assigned classifiers to instance.
        Parameters:
        instance - instance
        createAll - true, if creates slots for all properties (do not check multiplicity). false, to create slots for properties with mandatory value, i.e. with lower multiplicity >= 1.
      • createSlotsForDefaultValues

        public static void createSlotsForDefaultValues​(InstanceSpecification instance,
                                                       Classifier classifier,
                                                       boolean createAll)
        Creates slots for properties of given classifier.
        Parameters:
        instance - instance
        classifier - classifier
        createAll - true, if creates slots for all properties (do not check multiplicity). false, to create slots for properties with mandatory value, i.e. with lower multiplicity >= 1.
      • createSlot

        @CheckForNull
        public static Slot createSlot​(InstanceSpecification instance,
                                      Property property,
                                      boolean createDefaultValue)
        Creates slot for property
        Parameters:
        instance - instance
        property - property
        createDefaultValue - fill slot value from property default value
        Returns:
        slot for property
      • setSlotValue

        public static void setSlotValue​(Slot slot,
                                        @CheckForNull
                                        java.lang.String value)
        Set slot value from a given string. Given string will by parsed by the slot type. For example if slot values are booleans, string should be "true".
        Parameters:
        slot - slot
        value - value string representation.
      • getValueBySlot

        @CheckForNull
        public static java.lang.Object getValueBySlot​(@CheckForNull
                                                      Slot slot)
        Retrieves values of slots as object, not as ValueSpecifications. Takes into account multiplicity of slot's defining feature. Collection is returned if slot multiplicity is many.
        Parameters:
        slot - slot
        Returns:
        value of slot
      • setClassifierForInstanceSpecification

        public static void setClassifierForInstanceSpecification​(Classifier classifier,
                                                                 InstanceSpecification instance,
                                                                 boolean createSlots)
        Set classifier for instance
        Parameters:
        classifier - classifier
        instance - instance
        createSlots - true if slots needs to be created
      • getAssignableAssociationsForLink

        public static java.util.List<Association> getAssignableAssociationsForLink​(InstanceSpecification clientInstance,
                                                                                   InstanceSpecification supplierInstance)
        Gets available associations which are allowed to assign for a link.
        Parameters:
        clientInstance - client instance specification
        supplierInstance - supplier instance specification
        Returns:
        a list of assignable associations for a link
      • isLink

        public static boolean isLink​(@CheckForNull
                                     InstanceSpecification instance)
        Checks if InstanceSpecification is Link.
        Parameters:
        instance - instance to check
        Returns:
        true if it is Link element - it has Association as classifier or has a Link symbol in diagram
      • collectAllInstances

        public static java.util.Collection<InstanceSpecification> collectAllInstances​(Classifier classifier,
                                                                                      java.util.Collection<InstanceSpecification> result)
        Collect all instances of given classifier. Instances of derived classifiers are also collected.
        Parameters:
        classifier - classifier
        result - result collection
        Returns:
        result collection
      • isInstanceSpecificationCompatibleWithType

        public static boolean isInstanceSpecificationCompatibleWithType​(Classifier type,
                                                                        InstanceSpecification instance)
        Checks if given instance specification is compatible with given Type. Instance is compatible if its classifiers are compatible with given type.
        Parameters:
        type - instance compatibility will be checked against this type
        instance - instance to check
        Returns:
        true if instance is compatible with given type
      • isInstanceSpecificationCompatibleWithType

        public static boolean isInstanceSpecificationCompatibleWithType​(Classifier type,
                                                                        InstanceSpecification instance,
                                                                        boolean checkInherited)
        Checks if given instance specification is compatible with given Type. Instance is compatible if its classifiers are compatible with given type.
        Parameters:
        type - instance compatibility will be checked against this type
        instance - instance to check
        checkInherited - if set to true, parent type will be treated as compatible.
        Returns:
        true if instance is compatible with given type
      • getAssociationOfLink

        public static java.util.Collection<Association> getAssociationOfLink​(InstanceSpecification instance)
        Gets Association classifier from Link InstanceSpecification, if exists.
        Parameters:
        instance - Link instance
        Returns:
        Associations or empty collection