Class InstanceSpecifications


  • public class InstanceSpecifications
    extends java.lang.Object
    Convenience static methods that operate on or return InstanceSpecification elements.
    • Constructor Detail

      • InstanceSpecifications

        public InstanceSpecifications()
    • Method Detail

      • getSlot

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

        public static boolean isDefiningFeatureSuitable​(InstanceSpecification instanceSpecification,
                                                        Property definingFeature)
        Method to check if instance owns definingFeature (property) directly or indirectly
        Parameters:
        instanceSpecification - instanceSpecification
        definingFeature - definingFeature/property
        Returns:
        true if instance has property, else false
      • 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,
                                                       Classifier classifier,
                                                       boolean createAll)
        Creates slots for properties of given classifier.
        Parameters:
        instance - instance to create slots for
        classifier - classifier of the 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,
                                                       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.
      • 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 for compatible classifiers
        checkInherited - if set to true, then classifiers derived/realized from given type will be treated as compatible.
        Returns:
        true if instance is compatible with given type
      • collectInstancesOf

        public static java.util.Collection<InstanceSpecification> collectInstancesOf​(Classifier classifier,
                                                                                     java.util.Collection<InstanceSpecification> instances)
        Collect all instances of given classifier. Instances of derived classifiers are also collected.
        Parameters:
        classifier - classifier
        Returns:
        the passed in collection, appended with instances of the classifier and its' subtypes
      • 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
      • setClassifiers

        public static void setClassifiers​(InstanceSpecification instance,
                                          @CheckForNull
                                          java.util.Collection<? extends Classifier> classifiers,
                                          boolean createSlots)
        Set classifiers for instance. Method replaces the classifiers, does not append to the current value
        Parameters:
        instance - instance to set classifiers for
        classifiers - classifiers
        createSlots - true if slots with default values needs to be created
        See Also:
        createSlotsForDefaultValues(InstanceSpecification, boolean)