Package com.nomagic.magicdraw.uml2
Class InstanceSpecifications
- java.lang.Object
-
- com.nomagic.magicdraw.uml2.InstanceSpecifications
-
public class InstanceSpecifications extends java.lang.ObjectConvenience static methods that operate on or return InstanceSpecification elements.
-
-
Constructor Summary
Constructors Constructor Description InstanceSpecifications()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.util.Collection<InstanceSpecification>collectInstancesOf(Classifier classifier, java.util.Collection<InstanceSpecification> instances)Collect all instances of given classifier.static voidcreateSlotsForDefaultValues(InstanceSpecification instance, boolean createAll)Creates slots for properties of all assigned classifiers to instance.static voidcreateSlotsForDefaultValues(InstanceSpecification instance, Classifier classifier, boolean createAll)Creates slots for properties of given classifier.static java.util.Collection<InstanceSpecification>getLinksBetweenInstances(InstanceSpecification client, InstanceSpecification supplier)Returns links found between client and supplier instancesstatic SlotgetNestedSlot(InstanceSpecification instanceSpecification, Property property, java.util.List<Property> path, int index)static SlotgetSlot(InstanceSpecification instanceSpecification, Property property)Returns existing slot for a given property in given instance, if anystatic SlotgetSlot(InstanceSpecification instance, Property property, boolean createSlotIfNotExists, boolean createDefaultValue)Returns existing of creates a new Slot for the given propertystatic java.lang.ObjectgetValueBySlot(Slot slot)Retrieves values of slots as object, not as ValueSpecifications.private static booleanisConnectedToClient(InstanceSpecification client, Element link)static booleanisDefiningFeatureSuitable(InstanceSpecification instanceSpecification, Property definingFeature)Method to check if instance owns definingFeature (property) directly or indirectlystatic booleanisInstanceSpecificationCompatibleWithType(Classifier type, InstanceSpecification instance, boolean checkInherited)Checks if given instance specification is compatible with given Type.static voidsetClassifiers(InstanceSpecification instance, java.util.Collection<? extends Classifier> classifiers, boolean createSlots)Set classifiers for instance.
-
-
-
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- instanceproperty- 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- instanceSpecificationdefiningFeature- 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 specificationproperty- featurecreateSlotIfNotExists- create a new slot if neededcreateDefaultValue- fill slot value from property default value- Returns:
- slot
-
getNestedSlot
@CheckForNull public static Slot getNestedSlot(InstanceSpecification instanceSpecification, Property property, java.util.List<Property> path, int index)
-
createSlotsForDefaultValues
public static void createSlotsForDefaultValues(InstanceSpecification instance, Classifier classifier, boolean createAll)
Creates slots for properties of given classifier.- Parameters:
instance- instance to create slots forclassifier- classifier of the instancecreateAll- 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- instancecreateAll- 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 typeinstance- instance to check for compatible classifierscheckInherited- 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
-
getLinksBetweenInstances
public static java.util.Collection<InstanceSpecification> getLinksBetweenInstances(InstanceSpecification client, InstanceSpecification supplier)
Returns links found between client and supplier instances- Parameters:
client- instancesupplier- instance- Returns:
- links
-
isConnectedToClient
private static boolean isConnectedToClient(InstanceSpecification client, Element link)
-
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 forclassifiers- classifierscreateSlots- true if slots with default values needs to be created- See Also:
createSlotsForDefaultValues(InstanceSpecification, boolean)
-
-