Class ValueSpecificationHelper

java.lang.Object
com.nomagic.uml2.ext.jmi.helpers.CoreHelper
com.nomagic.uml2.ext.jmi.helpers.ValueSpecificationHelper
Direct Known Subclasses:
ClassifierHelper

@OpenApiAll public class ValueSpecificationHelper extends CoreHelper
An utility class to work with ValueSpecifications
  • Constructor Details

    • ValueSpecificationHelper

      public ValueSpecificationHelper()
  • Method Details

    • createValueSpecification

      @CheckForNull public static ValueSpecification createValueSpecification(Project project, @CheckForNull Type valueType, @CheckForNull Object value, @CheckForNull Collection<? extends ValueSpecification> reuse)
      Create a new value specification for a given value or returns a suitable from the given specifications to reuse.
      Parameters:
      project - project
      valueType - type defining the value specification
      value - value value of ValueSpecification
      reuse - a collection of possible value specifications to reuse
      Returns:
      specification
    • createValueSpecification

      @CheckForNull public static ValueSpecification createValueSpecification(Project project, @CheckForNull Type valueType, @CheckForNull Object value, boolean checkNullValue, @CheckForNull Collection<? extends ValueSpecification> reuse)
      Create a new value specification for a given value or returns a suitable from the given specifications to reuse.
      Parameters:
      project - project
      valueType - type defining the value specification
      value - value value of ValueSpecification
      checkNullValue - if true and value is null, null is returned
      reuse - a collection of possible value specifications to reuse
      Returns:
      specification
    • createValueSpecification

      @CheckForNull public static ValueSpecification createValueSpecification(@CheckForNull Type valueType, @CheckForNull Object value, ElementsFactory elementsFactory, @CheckForNull Collection<? extends ValueSpecification> reuse)
      Create a new value specification for a given value or returns a suitable from the given specifications to reuse.
      Parameters:
      valueType - type defining the value specification
      value - value value of ValueSpecification
      elementsFactory - factory
      reuse - a collection of possible value specifications to reuse
      Returns:
      specification
    • createValueSpecification

      @CheckForNull public static ValueSpecification createValueSpecification(@CheckForNull Class<? extends ValueSpecification> valueSpecificationClass, @CheckForNull Type valueType, @CheckForNull Object value, ElementsFactory factory, @CheckForNull Collection<? extends ValueSpecification> reuse)
      Create a new value specification for a given value or returns a suitable from the given specifications to reuse.
      Parameters:
      valueSpecificationClass - meta type of value specification
      value - value value of ValueSpecification
      factory - factory
      reuse - a collection of possible value specifications to reuse
      Returns:
      specification
    • createValueSpecification

      @CheckForNull public static ValueSpecification createValueSpecification(@CheckForNull Class<? extends ValueSpecification> valueSpecificationClass, @CheckForNull Type valueType, @CheckForNull Object value, ElementsFactory factory, @CheckForNull Collection<? extends ValueSpecification> reuse, boolean ignoreValuesOfReuse)
      Create a new value specification for a given value or returns a suitable from the given specifications to reuse.
      Parameters:
      valueSpecificationClass - meta type of value specification
      value - value value of ValueSpecification
      factory - factory
      reuse - a collection of possible value specifications to reuse
      ignoreValuesOfReuse - if false, checks is value if reuse candidate is suitable, not only the meta type. If true, checks just a metatype and overwrites the value
      Returns:
      specification
    • setValueSpecificationValue

      @CheckForNull public static ValueSpecification setValueSpecificationValue(Project project, @CheckForNull ValueSpecification valueSpecification, @CheckForNull Type valueType, @CheckForNull Object value)
      Sets value to value specification, creates value specification if necessary. If valueSpecification is passed, set a value to it. If value is null, passed value specification is disposed and null is returned.
      Parameters:
      project - project
      valueSpecification - value specification
      valueType - value type
      value - value
      Returns:
      passed value specification or created a new one. If value is null, null can be returned.
    • setValueSpecificationValue

      @CheckForNull public static ValueSpecification setValueSpecificationValue(Project project, @CheckForNull ValueSpecification valueSpecification, @CheckForNull Type valueType, @CheckForNull Object value, boolean checkNullValue)
      Sets value to value specification, creates value specification if necessary. If valueSpecification is passed, set a value to it. If value is null and checkNullValue is true, passed value specification is disposed and null is returned.
      Parameters:
      project - project
      valueSpecification - value specification
      valueType - value type
      value - value
      checkNullValue - check null value
      Returns:
      passed value specification or created a new one. If value is null, null can be returned.
    • setValueSpecificationValue

      public static void setValueSpecificationValue(ValueSpecification valueSpecification, @CheckForNull Object value)
      Set a value of value specification
      Parameters:
      valueSpecification - value specification
      value - value
    • getValueSpecificationClass

      public static Class<? extends ValueSpecification> getValueSpecificationClass(@CheckForNull Type valueType, @CheckForNull Object value)
      Return a meta type of ValueSpecification which should be used to store values of given type or value. If valueType is null, value is used to define a meta type of value specification.
      Parameters:
      valueType - value type
      Returns:
      meta type of value specification
    • isValueSpecificationClassElementValue

      public static boolean isValueSpecificationClassElementValue(@CheckForNull Type valueType)
      Parameters:
      valueType - value type
      Returns:
      true if ValueSpecification for given type should be ElementValue
    • getValueSpecificationClass

      public static Class<? extends ValueSpecification> getValueSpecificationClass(@CheckForNull Type valueType)
      Return a meta type of ValueSpecification which should be used to store values of given type
      Parameters:
      valueType - value type
      Returns:
      meta type of value specification
    • cloneValueSpecification

      @CheckForNull public static ValueSpecification cloneValueSpecification(ValueSpecification valueSpecification, @CheckForNull Element newOwner)
      Clones value specification
      Parameters:
      valueSpecification - value specification to clone
      newOwner - owner of new value specification. It will not be set as owner, but it should be passed for correct cloning
      Returns:
      cloned value specification
    • getValueSpecificationValue

      @CheckForNull public static Object getValueSpecificationValue(@CheckForNull ValueSpecification valueSpecification)
      Return value of given ValueSpecification
      Parameters:
      valueSpecification - value specification
      Returns:
      value
    • getValueString

      public static String getValueString(@CheckForNull ValueSpecification valueSpecification)
      Return string representation of given ValueSpecification
      Parameters:
      valueSpecification - value specification
      Returns:
      string representation of given value specification
    • setValueDisposeIfNeeded

      public static void setValueDisposeIfNeeded(Supplier<ValueSpecification> oldValueSupplier, Consumer<ValueSpecification> newValueConsumer, @CheckForNull ValueSpecification newValue)
      Set value specification as a new value. If old value is not the same as new value, old ValueSpecification is disposed.
      Parameters:
      oldValueSupplier - the supplier of olf value
      newValueConsumer - the consumer of new value
      newValue - new value