Class ClassifierHelper

Direct Known Subclasses:
InstanceSpecificationHelper

@OpenApiAll public class ClassifierHelper extends ValueSpecificationHelper
Utility class for working with UML classifiers
  • Constructor Details

    • ClassifierHelper

      public ClassifierHelper()
  • Method Details

    • getDerivedClassifiersRecursively

      public static Collection<Classifier> getDerivedClassifiersRecursively(Classifier general)
      Get all derived classifiers for given classifier. Result does not include the given classifier.
      Parameters:
      general - given classifier to collect specific classifiers for
      Returns:
      collection of all derived classifiers
    • getClassifiersIncludingDerivedRecursively

      public static Collection<Classifier> getClassifiersIncludingDerivedRecursively(Collection<? extends Classifier> classifiers)
      Returns all general classifiers including the indirect ones down to the leafs of the hierarchy. Result includes given classifiers.
      Parameters:
      classifiers - classifiers
      Returns:
      general elements
      See Also:
    • collectDerivedClassifiersRecursively

      public static void collectDerivedClassifiersRecursively(Collection<? extends Classifier> result, Classifier general)
      Collect all derived classifiers recursively (not only the direct children).
      Parameters:
      result - collection of all derived classifiers
      general - general classifier
    • getDerivedClassifiers

      public static Collection<Classifier> getDerivedClassifiers(@CheckForNull Classifier general)
      Return classifiers derived directly from the given classifier
      Parameters:
      general - general classifier
      Returns:
      collection of derived classifiers
    • getClassifiersIncludingDerived

      public static Collection<Classifier> getClassifiersIncludingDerived(Collection<Classifier> generalClassifiers)
      Returns set of provided classifiers plus directly derived ones
      Parameters:
      generalClassifiers - classifier collection
      Returns:
      collection of classifiers including derived
      See Also:
    • getGeneralClassifiers

      public static List<Classifier> getGeneralClassifiers(Classifier classifier)
      Returns general classifiers from which the given classifier is directly derived.
      Parameters:
      classifier - classifier
      Returns:
      direct general classifiers
      See Also:
    • getGeneralClassifiersRecursively

      public static List<Classifier> getGeneralClassifiersRecursively(Classifier classifier)
      Returns all general classifiers including the indirect ones up to hierarchy top. Result does not include the given classifier.
      Parameters:
      classifier - classifier
      Returns:
      general elements
      See Also:
    • getClassifiersIncludingGeneralRecursively

      public static List<Classifier> getClassifiersIncludingGeneralRecursively(Classifier classifier)
      Returns all general classifiers including the indirect ones up to hierarchy top. Result includes given classifier.
      Parameters:
      classifier - classifier
      Returns:
      general elements
      See Also:
    • getClassifiersIncludingGeneralRecursively

      public static Collection<Classifier> getClassifiersIncludingGeneralRecursively(Collection<? extends Classifier> classifiers)
      Returns all general classifiers including the indirect ones up to hierarchy top. Result includes given classifiers.
      Parameters:
      classifiers - classifier
      Returns:
      general elements
      See Also:
    • collectGeneralClassifiersRecursively

      public static <T extends Classifier> Collection<T> collectGeneralClassifiersRecursively(Classifier classifier, Collection<T> result)
      Collects all general classifiers including the indirect ones up to hierarchy top.
      Parameters:
      classifier - classifier
      result - result collection
      Returns:
      result collection
    • collectGeneralClassifiersAndRealizedInterfacesRecursively

      public static <T extends Classifier> Collection<T> collectGeneralClassifiersAndRealizedInterfacesRecursively(Classifier classifier, Collection<T> result)
      Collects all general classifiers including the indirect ones up to hierarchy top. Also collects all realized interfaces from the collected general classifiers.
      Parameters:
      classifier - classifier
      result - result collection
      Returns:
      result collection
    • getInheritanceDeep

      public static int getInheritanceDeep(Classifier classifier)
      Gets the deep of inherited tree for classifier. Used to sort stereotypes by inheritance.
      Parameters:
      classifier - classifier
      Returns:
      result deep
    • isLegalInheritance

      public static boolean isLegalInheritance(Classifier parent, Classifier child)
      Checks if new generalization relationship is legal between given parent and child. Legal if it does not create cycle and child isKindOf parent.
      Parameters:
      parent - parent element of generalization.
      child - child element of generalization.
      Returns:
      true - if generalization is legal, otherwise return false.
    • isLegalInheritance

      public static boolean isLegalInheritance(Classifier parent, Classifier child, @CheckForNull Collection<? extends Relationship> ignore)
      Checks if new generalization relationship is legal between given parent and child. Legal if it does not create cycle and child isKindOf parent.
      Parameters:
      parent - parent element of generalization.
      child - child element of generalization.
      ignore - a collection of classifiers that should be ignored.
      Returns:
      true - if generalization is legal, otherwise return false.
    • findAssociationEndForType

      @CheckForNull public static Property findAssociationEndForType(Classifier classifier, Classifier type, String name)
      Looks for AssociationEnd connected to the given classifier 'classifier' which can be mapped into 'classifier' attribute with name 'name' and type 'type'.
      Parameters:
      classifier - the given classifier.
      type - the type of the association end.
      name - the name of the association end.
      Returns:
      found AssociationEnd or null.
    • getReturnParameter

      public static Parameter getReturnParameter(BehavioralFeature feature)
      Return parameter of given behaviour feature. A new parameter is created if feature does not have it.
      Parameters:
      feature - a given feature
      Returns:
      return parameter (existing one or created)
    • isReturnParameter

      public static boolean isReturnParameter(Parameter parameter)
      Parameters:
      parameter - parameter
      Returns:
      true if given Parameter has return kind
    • getReturnParameter

      @CheckForNull public static Parameter getReturnParameter(BehavioralFeature feature, boolean create)
      Return parameter of given behaviour feature. A new parameter may be created if feature does not have it.
      Parameters:
      feature - a given feature
      create - creates a new parameter if needed
      Returns:
      return parameter
    • getReturnParameter

      @CheckForNull public static Parameter getReturnParameter(Behavior behavior, boolean create)
      Return parameter of given behaviour. A new parameter may be created if behavior does not have it.
      Parameters:
      behavior - a given behavior
      create - creates a new parameter if needed
      Returns:
      return parameter
    • operations

      public static Iterator<Operation> operations(Classifier classifier)
      Get iterator of operations from given classifier.
      Parameters:
      classifier - The given classifier.
      Returns:
      iterator
    • receptions

      public static Iterator<Reception> receptions(Classifier classifier)
      Get iterator of reception from given classifier.
      Parameters:
      classifier - The given classifier.
      Returns:
      iterator
    • attributes

      public static Iterator<Property> attributes(Classifier classifier)
      Get iterator of Attribute from given classifier.
      Parameters:
      classifier - The given classifier.
      Returns:
      iterator
    • ports

      public static Iterator<Port> ports(Classifier classifier)
      Get iterator of port from given classifier.
      Parameters:
      classifier - The given classifier.
      Returns:
      iterator
    • pureAttributes

      public static Iterator<Property> pureAttributes(Classifier classifier)
      Get iterator of pure attribute from given classifier.
      Parameters:
      classifier - The given classifier.
      Returns:
      iterator
    • associations

      public static Iterator<Association> associations(Classifier classifier)
      Get iterator of association from given classifier.
      Parameters:
      classifier - The given classifier.
      Returns:
      iterator
    • associationsIncludingInherited

      public static Iterator<Association> associationsIncludingInherited(Classifier classifier)
      Collects connected directly and inherited associations
      Parameters:
      classifier - classifier
    • collectInheritedAttributes

      public static void collectInheritedAttributes(Classifier classifier, Collection result, boolean collectOwned, boolean collectPrivate)
      Collect inherited and owned attributes from the given classifier.
      Parameters:
      classifier - classifier
      result - result collection
      collectOwned - if true, collected also owned
      collectPrivate - if false, do not collect private
    • collectBaseClassInheritableAttributes

      public static void collectBaseClassInheritableAttributes(Classifier classifier, Collection result, boolean collectOwned, boolean collectPrivate)
      Collect inherited and owned attributes from the given classifier.
      Parameters:
      classifier - classifier
      result - result collection
      collectOwned - if true, collected also owned
      collectPrivate - if false, do not collect private
    • collectInheritedPureAttributes

      public static void collectInheritedPureAttributes(Classifier classifier, Collection result, boolean collectOwned)
      Collect inherited and owned attributes (just Property, not Port and etc) from the given classifier. Private attributes are collected.
      Parameters:
      classifier - classifier
      result - result collection
      collectOwned - if true, collected also owned
    • collectInheritedPureAttributes

      public static void collectInheritedPureAttributes(Classifier classifier, Collection result, boolean collectOwned, boolean collectPrivate)
      Collect inherited and owned attributes (just Property, not Port and etc) from the given classifier.
      Parameters:
      classifier - classifier
      result - result collection
      collectOwned - if true, collected also owned
      collectPrivate - if false, do not collect private
    • collectInheritedRelations

      public static void collectInheritedRelations(Classifier classifier, Collection<Element> result, boolean collectOwned)
      Collect inherited and directly connected relationships to the classifier
      Parameters:
      classifier - classifier
      result - result collection
      collectOwned - if true, collected also owned
    • getAssociationEndOwnedByAssociation

      public static Collection<TypedElement> getAssociationEndOwnedByAssociation(Classifier classifier)
      Returns a collection of properties connected to given classifier by associations. Properties are owned by Association
      Parameters:
      classifier - the given classifier
      Returns:
      collection of properties
    • collectInheritedPorts

      public static void collectInheritedPorts(Classifier classifier, Collection result, boolean collectOwned, boolean collectPrivate)
      Collect inherited and owned ports from the given classifier.
      Parameters:
      classifier - classifier
      result - result collection
      collectOwned - if true, collected also owned
      collectPrivate - if false, do not collect private
    • collectInheritedExtensionPoints

      public static void collectInheritedExtensionPoints(UseCase useCase, Collection result, boolean collectOwned, boolean collectPrivate)
      Collect inherited and owned extension points from the given use case.
      Parameters:
      useCase - use case
      result - result collection
      collectOwned - if true, collected also owned
      collectPrivate - if false, do not collect private
    • collectInheritedOperations

      public static void collectInheritedOperations(Classifier classifier, Collection result, boolean collectOwned, boolean collectPrivate)
      Collect inherited and owned operations from the given classifier.
      Parameters:
      classifier - classifier
      result - result collection
      collectOwned - if true, collected also owned
      collectPrivate - if false, do not collect private
    • collectInheritedBehaviors

      public static void collectInheritedBehaviors(BehavioredClassifier classifier, Collection<Behavior> result, boolean collectOwned, boolean collectPrivate)
      Collect inherited and owned behaviors from the given classifier
      Parameters:
      classifier - classifier
      result - result collection
      collectOwned - if true, collected also owned
      collectPrivate - if false, do not collect private
    • collectInheritedReceptions

      public static void collectInheritedReceptions(Classifier classifier, Collection result, boolean collectOwned, boolean collectPrivate)
      Collect inherited and owned receptions from the given classifier
      Parameters:
      classifier - classifier
      result - result collection
      collectOwned - if true, collected also owned
      collectPrivate - if false, do not collect private
    • collectInheritedRealizedInterfaces

      public static void collectInheritedRealizedInterfaces(BehavioredClassifier classifier, Collection result, boolean collectOwned)
      Collect inherited and directly realized interfaces from the given classifier
      Parameters:
      classifier - classifier
      result - result collection
      collectOwned - if true, collected also owned
    • getAllLiterals

      public static List<EnumerationLiteral> getAllLiterals(Enumeration enumeration)
      Return owned and inherited enumeration literals
      Parameters:
      enumeration - enumeration
      Returns:
      literals
    • collectInheritedEnumerationLiterals

      public static void collectInheritedEnumerationLiterals(Enumeration enumeration, Collection result, boolean collectOwned, boolean collectPrivate)
      Collect inherited and owned literals from the given enumeration.
      Parameters:
      enumeration - enumeration
      result - result collection
      collectOwned - if true, collected also owned
      collectPrivate - if false, do not collect private
    • isClassifierOfType

      public static boolean isClassifierOfType(Classifier classifier, Classifier type)
      Tests if given classifier isTypeOf (equals or is derived) given type.
      Parameters:
      classifier - the give classifier
      type - the given type
      Returns:
      true if classifier isTypeOf type
    • isClassifierOfType

      public static boolean isClassifierOfType(Collection<? extends Classifier> classifiers, Classifier type)
      Tests if there is at least one classifier among given ones which isTypeOf (equals or is derived) given type.
      Parameters:
      classifiers - the given classifier
      type - the given type
      Returns:
      true if classifiers contains at least one classifier which isTypeOf type
    • getRealizedInterfaces

      public static List<Interface> getRealizedInterfaces(BehavioredClassifier classifier)
      Collects realized interfaces by the given classifier.
      Parameters:
      classifier - given classifier
      Returns:
      a collection of realized interfaces(may be empty)
    • checkForDerivedClassifier

      @CheckForNull public static Classifier checkForDerivedClassifier(Collection<? extends Classifier> classifiers, Classifier checkFor)
      Checks if there are given classifier or some derived classifier in a given classifier collection.
      Parameters:
      classifiers - collection of classifiers to look in
      checkFor - target classifier
      Returns:
      returns classifier which equals to the given or is derived
    • isSameOrDerivedClassifier

      public static boolean isSameOrDerivedClassifier(@CheckForNull Classifier parent, @CheckForNull Classifier child)
      Checks if given classifier "child" is same as "parent" or is derived from "parent".
      Parameters:
      parent - parent classifier
      child - child classifier
      Returns:
      true if same or derived
      See Also:
    • isDerivedClassifier

      public static boolean isDerivedClassifier(@CheckForNull Classifier parent, @CheckForNull Classifier child)
      Checks if child is derived from parent by generalization
      Parameters:
      parent - parent
      child - possible parent
      Returns:
      true if derived
    • isDerivedOrRealizes

      public static boolean isDerivedOrRealizes(Classifier classifier, Classifier type)
      Checks if classifier is derived from given type or realizes the given type.
      Parameters:
      classifier - classifier to check
      type - type
      Returns:
      true if derived or realizes
    • isSecondTypeCompatibleToFirst

      public static boolean isSecondTypeCompatibleToFirst(Type firstType, Collection<Type> secondType, boolean checkRealizedInterfaces)
      Indicates at least one type from second type collection is compatible to the first type.
      Parameters:
      firstType - type to which types should be checked.
      secondType - types which should be compared to the first type.
      checkRealizedInterfaces - indicates if realized interfaces should be taken into account when checking type compatibility.
      Returns:
      true if parameters are compatible, false otherwise.
    • isSecondTypeCompatibleToFirst

      public static boolean isSecondTypeCompatibleToFirst(@CheckForNull Type firstType, @CheckForNull Type secondType, boolean checkRealizedInterfaces)
      Indicates if second parameter type is compatible to the first (is same type or a subtype).
      Parameters:
      firstType - parameter, to which the 2nd parameter must be compatible.
      secondType - parameter, which should be compatible to the 1st.
      checkRealizedInterfaces - indicates if realized interfaces should be taken into account when checking type compatibility.
      Returns:
      true if parameters are compatible, false otherwise.
    • collectRealizedInterfaces

      public static void collectRealizedInterfaces(Collection<? extends Classifier> classifiers, Collection<Interface> result)
      Collects realized interfaces by given classifiers.
      Parameters:
      classifiers - classifiers for which realized interfaces should be collected.
      result - a set in which realized interfaces should be collected.
    • removeDerivedClassifiers

      public static Collection<Classifier> removeDerivedClassifiers(Collection<Classifier> classifiers)
      Given a collection of classifiers, returns a collection without derived classifiers in their generalization hierarchy.
      Parameters:
      classifiers - classifier hierarchy to optimize
      Returns:
      optimized classifier hierarchy.
    • isOperationEqual

      public static boolean isOperationEqual(Operation op1, Operation op2)
      Compare the two given operation.
      Parameters:
      op1 - First operation.
      op2 - Second operation.
      Returns:
      boolean
    • isBehavioralFeatureEqual

      public static boolean isBehavioralFeatureEqual(BehavioralFeature feature1, BehavioralFeature feature2, boolean compareReturnParameter)
      Compare the two given features by name and by parameters
      Parameters:
      feature1 - first feature
      feature2 - second feature
      compareReturnParameter - take into account return parameter(s)
      Returns:
      true if names are equals and parameters are equals
    • areEqualParameterTypes

      public static boolean areEqualParameterTypes(BehavioralFeature feature1, BehavioralFeature feature2)
      Method compares parameters and returns true if parameters types are equals.
      Parameters:
      feature1 - feature to be compared with.
      feature2 - feature to be compared with.
      Returns:
      true if parameters are equals.
    • areEqualParameterTypes

      public static boolean areEqualParameterTypes(BehavioralFeature feature1, BehavioralFeature feature2, boolean compareReturnParameter)
      Method compares parameters and returns true if parameters types are equals.
      Parameters:
      feature1 - feature to be compared with.
      feature2 - feature to be compared with.
      compareReturnParameter - take into account return parameter(s)
      Returns:
      true if parameters are equals.
    • findInterfaceRealization

      @CheckForNull public static InterfaceRealization findInterfaceRealization(BehavioredClassifier implementingClass, Interface contract)
      Look for interface realization between given class and interface.
      Parameters:
      implementingClass - class
      contract - interface
    • findGeneralization

      @CheckForNull public static Generalization findGeneralization(Classifier general, Classifier specific)
      Look for generalization between given classifiers.
      Parameters:
      general - general classifier
      specific - specific classifier
    • getParameters

      public static List<Parameter> getParameters(BehavioralFeature feature)
      Returns parameters without return parameter
      Parameters:
      feature - the given feature
    • getReturnParameters

      public static List<Parameter> getReturnParameters(BehavioralFeature feature)
      Returns parameters without return parameter
      Parameters:
      feature - the given feature
    • collectCommonAssociations

      public static Collection<Association> collectCommonAssociations(Collection<? extends Classifier> classifiers1, Collection<? extends Classifier> classifiers2)
      Collect association connected between given classifiers
      Parameters:
      classifiers1 - one classifiers collection
      classifiers2 - second classifiers collection
      Returns:
      common Associations between two collections of classifiers
    • getProvided

      public static Collection<Interface> getProvided(Class component)
      Component provided interfaces collection consists of: 1) interfaces, realized by the component through InterfaceRealization, 2) provided interfaces of the component ports, 3) component port types which are interfaces.
      Returns:
      provided interfaces.
    • getImplementedClasses

      public static List<BehavioredClassifier> getImplementedClasses(Interface anInterface)
      Gets classifiers which realize (implement) a given interface.
      Parameters:
      anInterface - an interface for which to get classifiers.
      Returns:
      list of classifiers which realize a given interface.
    • removeRedefined

      public static void removeRedefined(Collection<? extends RedefinableElement> major, Collection<? extends RedefinableElement>... additional)
      Removes redefined elements from a given major collection. Major collection is a result. Additional collections are optional and are used only for redefined elements collecting
      Parameters:
      major - elements to remove redefined elements from
      additional - elements to remove redefined elements from major
    • isSameOrRedefined

      public static boolean isSameOrRedefined(@CheckForNull Property first, @CheckForNull Property second)
      Check if given first property is the same as second property or first property is redefined by second property
      Parameters:
      first - first property
      second - second property
      Returns:
      first is the same as second or is redefined by second
    • getPropertiesWithoutRedefined

      public static List<Property> getPropertiesWithoutRedefined(Classifier classifier)
      Gets owned and inherited properties without redefined ones.
      Parameters:
      classifier - classifiers from which properties will be collected
      Returns:
      owned and inherited properties without redefined ones.