예제 #1
0
 /**
  * Creates a PropertyValue for a range of aadlreal.
  *
  * @throws IllegalArgumentException Thrown if min is greater than max.
  */
 public static RangeValue createRealRangeValue(double min, double max)
     throws IllegalArgumentException {
   if (min > max) throw new IllegalArgumentException("min cannot be greater than max.");
   RangeValue newPropertyValue = Aadl2Factory.eINSTANCE.createRangeValue();
   newPropertyValue.setMinimum(createRealValue(min));
   newPropertyValue.setMaximum(createRealValue(max));
   return newPropertyValue;
 }
예제 #2
0
 /**
  * Return the delta value of a non-modal range property value scaled to a given unit. Throws an
  * exception if no property value exists or an error occurs.
  *
  * @param ph The property holder from which to retrieve the property value.
  * @param pd The property to retrieve.
  * @param unit The unit to scale the value to.
  * @return The delta of the range value scaled to the given unit.
  * @throws InvalidModelException Thrown if the property value cannot be retrieved because the
  *     model is incomplete or otherwise invalid.
  * @throws PropertyNotPresentException Thrown if the property is undefined for ph.
  * @throws PropertyIsModalException Thrown if ph is modal and declarative.
  * @throws IllegalStateException Thrown if the lookup encounters a cycle of property reference
  *     dependencies.
  * @throws IllegalArgumentException Thrown if the given unit literal is not from the property's
  *     unit type or if ph, pd, or unit is null.
  * @throws PropertyDoesNotApplyToHolderException Thrown if pd does not apply to ph.
  * @throws PropertyIsListException Thrown if the property is not scalar.
  * @throws ClassCastException Thrown if the retrieved value is not a range value.
  */
 public static double getScaledRangeDelta(
     final NamedElement ph, final Property pd, final UnitLiteral unit)
     throws InvalidModelException, PropertyNotPresentException, PropertyIsModalException,
         IllegalStateException, IllegalArgumentException, PropertyDoesNotApplyToHolderException,
         PropertyIsListException, ClassCastException {
   final PropertyExpression pv = checkUnitsAndGetSimplePropertyValue(ph, pd, unit);
   RangeValue rv = (RangeValue) pv;
   return rv.getDeltaValue().getScaledValue(unit);
 }
예제 #3
0
 /**
  * Return the delta value of a non-modal range property value scaled to a given unit. Returns a
  * given default value if no property value exists. Throws an exception if an error occurs.
  *
  * @param ph The property holder from which to retrieve the property value.
  * @param pd The property to retrieve.
  * @param unit The unit to scale the value to.
  * @param defaultVal The value to return if the property has no value.
  * @return The delta of the range value scaled to the given unit.
  */
 public static double getScaledRangeDelta(
     final NamedElement ph, final Property pd, final UnitLiteral unit, final double defaultVal) {
   try {
     final PropertyExpression pv = checkUnitsAndGetSimplePropertyValue(ph, pd, unit);
     final RangeValue rv = (RangeValue) pv;
     return rv.getDeltaValue().getScaledValue(unit);
   } catch (PropertyLookupException e) {
     return defaultVal;
   }
 }
예제 #4
0
  /**
   * Return the maximum value of a non-modal range property value scaled to a given unit. Throws an
   * exception if no property value exists or an error occurs.
   *
   * @param ph The property holder from which to retrieve the property value.
   * @param pd The property to retrieve.
   * @param unit The unit to scale the value to.
   * @return The maximum of the range value scaled to the given unit.
   * @throws InvalidModelException Thrown if the property value cannot be retrieved because the
   *     model is incomplete or otherwise invalid.
   * @throws PropertyNotPresentException Thrown if the property is undefined for ph.
   * @throws PropertyIsModalException Thrown if ph is modal and declarative.
   * @throws IllegalStateException Thrown if the lookup encounters a cycle of property reference
   *     dependencies.
   * @throws IllegalArgumentException Thrown if the given unit literal is not from the property's
   *     unit type or if ph, pd, or unit is null.
   * @throws PropertyDoesNotApplyToHolderException Thrown if pd does not apply to ph.
   * @throws PropertyIsListException Thrown if the property is not scalar.
   * @throws ClassCastException Thrown if the retrieved value is not a range value.
   */
  public static double getScaledRangeMaximum(
      final NamedElement ph, final Property pd, final UnitLiteral unit)
      throws InvalidModelException, PropertyNotPresentException, PropertyIsModalException,
          IllegalStateException, IllegalArgumentException, PropertyDoesNotApplyToHolderException,
          PropertyIsListException, ClassCastException {
    final PropertyExpression pv = checkUnitsAndGetSimplePropertyValue(ph, pd, unit);
    RangeValue rv = (RangeValue) pv;
    PropertyExpression maximum = rv.getMaximum().evaluate(null).first().getValue();

    if (maximum instanceof NumberValue) {
      return ((NumberValue) maximum).getScaledValue(unit);
    }
    throw new InvalidModelException(maximum, "Cannot evaluate upper range limit");
  }
예제 #5
0
  /**
   * Return the maximum value of a non-modal range property value scaled to a given unit. Returns a
   * given default value if no property value exists. Throws an exception if an error occurs.
   *
   * @param ph The property holder from which to retrieve the property value.
   * @param pd The property to retrieve.
   * @param unit The unit to scale the value to.
   * @param defaultVal The value to return if the property has no value.
   * @return The maximum of the range value scaled to the given unit.
   */
  public static double getScaledRangeMaximum(
      final NamedElement ne, final Property pd, final UnitLiteral unit, final double defaultVal) {
    try {
      final PropertyExpression pv = checkUnitsAndGetSimplePropertyValue(ne, pd, unit);
      final RangeValue rv = (RangeValue) pv;
      PropertyExpression maximum = rv.getMaximum().evaluate(null).first().getValue();

      if (maximum instanceof NumberValue) {
        return ((NumberValue) maximum).getScaledValue(unit);
      } else {
        return defaultVal;
      }
    } catch (PropertyLookupException e) {
      return defaultVal;
    }
  }
예제 #6
0
  /**
   * Creates a PropertyValue for a range of aadlreal with units.
   *
   * @throws IllegalArgumentException Thrown if minUnits, maxUnits, or deltaUnits is null, if
   *     minUnits, maxUnits, and deltaUnits are not of the same UnitType, or if min is greater than
   *     max.
   */
  public static RangeValue createRealRangeValue(
      double min,
      UnitLiteral minUnits,
      double max,
      UnitLiteral maxUnits,
      double delta,
      UnitLiteral deltaUnits)
      throws IllegalArgumentException {
    RangeValue newPropertyValue = createRealRangeValue(min, minUnits, max, maxUnits);

    if (deltaUnits == null) throw new IllegalArgumentException("deltaUnits cannot be null.");
    if (!minUnits.eContainer().equals(deltaUnits.eContainer()))
      throw new IllegalArgumentException(
          "minUnits, maxUnits, and deltaUnits are not of the same type.");

    newPropertyValue.setDelta(createRealValue(delta, deltaUnits));
    return newPropertyValue;
  }
예제 #7
0
  /**
   * Creates a PropertyValue for a range of aadlreal with units.
   *
   * @throws IllegalArgumentException Thrown if minUnits or maxUnits is null, if minUnits and
   *     maxUnits are not of the same UnitType, or if min is greater than max.
   */
  public static RangeValue createRealRangeValue(
      double min, UnitLiteral minUnits, double max, UnitLiteral maxUnits)
      throws IllegalArgumentException {
    if (minUnits == null) throw new IllegalArgumentException("minUnits cannot be null.");
    if (maxUnits == null) throw new IllegalArgumentException("maxUnits cannot be null.");
    if (!minUnits.eContainer().equals(maxUnits.eContainer()))
      throw new IllegalArgumentException("minUnits and maxUnits are not of the same type.");

    RealLiteral minimumValue = createRealValue(min, minUnits);
    RealLiteral maximumValue = createRealValue(max, maxUnits);
    if (minimumValue.getScaledValue() > maximumValue.getScaledValue())
      throw new IllegalArgumentException("min cannot be greater than max.");

    RangeValue newPropertyValue = Aadl2Factory.eINSTANCE.createRangeValue();
    newPropertyValue.setMinimum(minimumValue);
    newPropertyValue.setMaximum(maximumValue);
    return newPropertyValue;
  }
예제 #8
0
 /**
  * Creates a PropertyValue for a range of aadlreal.
  *
  * @throws IllegalArgumentException Thrown if min is greater than max.
  */
 public static RangeValue createRealRangeValue(double min, double max, double delta)
     throws IllegalArgumentException {
   RangeValue newPropertyValue = createRealRangeValue(min, max);
   newPropertyValue.setDelta(createRealValue(delta));
   return newPropertyValue;
 }
예제 #9
0
 /**
  * Creates a PropertyValue for a range of aadlinteger.
  *
  * @throws IllegalArgumentException Thrown if min is greater than max.
  */
 public static RangeValue createIntegerRangeValue(long min, long max, long delta)
     throws IllegalArgumentException {
   RangeValue newPropertyValue = createIntegerRangeValue(min, max);
   newPropertyValue.setDelta(createIntegerValue(delta));
   return newPropertyValue;
 }