use of org.osate.aadl2.NumberValue in project osate2 by osate.
the class GetProperties method getMinimumTransmissionTimeFixed.
public static double getMinimumTransmissionTimeFixed(final NamedElement bus) {
RecordValue rv;
RangeValue bpa;
NumberValue nv;
rv = GetProperties.getTransmissionTime(bus);
if (rv == null) {
return 0;
}
bpa = (RangeValue) PropertyUtils.getRecordFieldValue(rv, "Fixed");
if (bpa != null) {
nv = bpa.getMinimumValue();
return nv.getScaledValue(GetProperties.getMSUnitLiteral(bus));
}
return 0;
}
use of org.osate.aadl2.NumberValue in project osate2 by osate.
the class PropertyUtils method getScaledRangeMaximum.
/**
* 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, 0).first().getValue();
if (maximum instanceof NumberValue) {
return ((NumberValue) maximum).getScaledValue(unit);
}
throw new InvalidModelException(maximum, "Cannot evaluate upper range limit");
}
use of org.osate.aadl2.NumberValue in project osate2 by osate.
the class NumberValueOperations method getScaledValue.
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated NOT
*/
public static double getScaledValue(NumberValue numberValue) {
final double value = getValue(numberValue);
final UnitLiteral unit = numberValue.getUnit();
final double factor = (unit == null) ? 1.0 : unit.getAbsoluteFactor();
return value * factor;
}
use of org.osate.aadl2.NumberValue in project osate2 by osate.
the class NumberValueOperations method getScaledValue.
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated NOT
*/
public static double getScaledValue(NumberValue numberValue, UnitLiteral target) {
final double value = getValue(numberValue);
final UnitLiteral unit = numberValue.getUnit();
final double factor = (unit == null) ? 1.0 : unit.getAbsoluteFactor(target);
return value * factor;
}
use of org.osate.aadl2.NumberValue in project osate2 by osate.
the class InterpreterUtil method divideInt.
public static NumberValue divideInt(IntegerLiteral v1, IntegerLiteral v2) {
UnitLiteral minUnit = smallerUnit(v1.getUnit(), v2.getUnit());
boolean twoUnits = v1.getUnit() != null && v2.getUnit() != null;
UnitLiteral unit = (v1.getUnit() != null) ? v1.getUnit() : v2.getUnit();
long s1 = (!twoUnits) ? v1.getValue() : Math.round(v1.getScaledValue(minUnit));
long s2 = (!twoUnits) ? v2.getValue() : Math.round(v2.getScaledValue(minUnit));
IntegerLiteral result = Aadl2Factory.eINSTANCE.createIntegerLiteral();
result.setValue(s1 / s2);
result.setUnit(twoUnits ? minUnit : unit);
return result;
}
Aggregations