/** * 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; }
/** * 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; }
/** * Check that UnitLiteral unit is part of Property pd's UnitsType and returns the property value * by calling ph.getSimplePropertyValue(pd) * * @param ph The property holder from which to retrieve the property value. * @param pd The property to retrieve. * @param unit The literal to test against pd's units type. * @return The retrieved property value. * @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 property's type is not a RangeType or a NumberType. */ private static PropertyExpression checkUnitsAndGetSimplePropertyValue( final NamedElement ph, final Property pd, final UnitLiteral unit) throws InvalidModelException, PropertyNotPresentException, PropertyIsModalException, IllegalStateException, IllegalArgumentException, PropertyDoesNotApplyToHolderException, PropertyIsListException, ClassCastException { if (unit == null) { throw new IllegalArgumentException("UnitLiteral unit cannot be null."); } final PropertyExpression pv = getSimplePropertyValue(ph, pd); PropertyType pt = (PropertyType) pd.getType(); if (pt instanceof RangeType) { pt = ((RangeType) pt).getNumberType(); } final UnitsType theUnitsType = ((NumberType) pt).getUnitsType(); if (unit.eContainer() != theUnitsType) { throw new IllegalArgumentException( "Unit literal " + unit.getName() + " is not from the property's type " + theUnitsType.getName()); } return pv; }