use of com.google.api.ads.admanager.axis.v202205.NumberValue in project osate2 by osate.
the class AadlBaTypeChecker method integerValueConstantToArrayDimension.
private ArrayDimension integerValueConstantToArrayDimension(IntegerValueConstant ivc) {
ArrayDimension result = Aadl2Factory.eINSTANCE.createArrayDimension();
ArraySize size = result.createSize();
result.setSize(size);
result.setLocationReference(ivc.getLocationReference());
size.setLocationReference(ivc.getLocationReference());
if (ivc instanceof BehaviorIntegerLiteral) {
size.setSize(((BehaviorIntegerLiteral) ivc).getValue());
} else if (ivc instanceof BehaviorPropertyConstant) {
PropertyExpression pe = null;
PropertyConstant pc = ((BehaviorPropertyConstant) ivc).getProperty();
pe = pc.getConstantValue();
if (pe instanceof NumberValue) {
double value = ((NumberValue) pe).getScaledValue();
size.setSize((long) value);
} else {
String msg = "cannot evaluate the property constant";
_errManager.warning(ivc, msg);
}
} else if (ivc instanceof PropertyReference) {
PropertyReference pr = (PropertyReference) ivc;
PropertyNameHolder last = pr.getProperties().get(pr.getProperties().size() - 1);
Element el = last.getProperty().getElement();
if (el instanceof NumberValue) {
double value = ((NumberValue) el).getScaledValue();
size.setSize((long) value);
} else {
String msg = "cannot evaluate the property value";
_errManager.warning(ivc, msg);
}
} else {
String errorMsg = "integerValueConstantToArrayDimension : " + ivc.getClass().getSimpleName() + " is not supported yet.";
System.err.println(errorMsg);
throw new UnsupportedOperationException(errorMsg);
}
return result;
}
use of com.google.api.ads.admanager.axis.v202205.NumberValue in project osate2 by osate.
the class QualifiedNamedElementImpl method basicSetFactor.
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public NotificationChain basicSetFactor(NumberValue newFactor, NotificationChain msgs) {
NumberValue oldFactor = factor;
factor = newFactor;
if (eNotificationRequired()) {
ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, DeclarativePackage.QUALIFIED_NAMED_ELEMENT__FACTOR, oldFactor, newFactor);
if (msgs == null) {
msgs = notification;
} else {
msgs.add(notification);
}
}
return msgs;
}
use of com.google.api.ads.admanager.axis.v202205.NumberValue in project osate2 by osate.
the class PropertyUtils method getFloatValue.
/**
* Extract float value from a specified property. May return null.
*
* @param i
* component instance.
* @param propertyName
* property name.
* @return property value.
*/
public static Float getFloatValue(NamedElement i, String propertyName, String unit) {
PropertyAssociation pa = findPropertyAssociation(propertyName, i);
if (pa != null) {
Property p = pa.getProperty();
if (p.getName().equalsIgnoreCase(propertyName)) {
List<ModalPropertyValue> values = pa.getOwnedValues();
if (values.size() == 1) {
ModalPropertyValue v = values.get(0);
PropertyExpression expr = v.getOwnedValue();
if (expr instanceof NumberValue) {
NumberValue val = (NumberValue) expr;
float fVal = 0f;
if (val instanceof IntegerLiteral) {
fVal = ((IntegerLiteral) val).getValue();
} else if (val instanceof RealLiteral) {
fVal = (float) ((RealLiteral) val).getValue();
}
return UnitConversion.convertInMs(fVal, val.getUnit().getName());
}
}
}
}
// try on a refined NamedElement
if (i instanceof RefinableElement) {
RefinableElement re = (RefinableElement) i;
if (re.getRefinedElement() != null) {
return getFloatValue(re.getRefinedElement(), propertyName, unit);
}
}
return null;
}
use of com.google.api.ads.admanager.axis.v202205.NumberValue in project osate2 by osate.
the class RangeValueImpl method evaluate.
public final EvaluatedProperty evaluate(EvaluationContext ctx, int depth) throws InvalidModelException {
/*
* The min, max, and delta attributes can refer to PropertyReferences to
* signed property constants that we need to resolve. So we first
* evaluate the min, max, and delta values, and then create a new
* RangeValue out of the evaluated contents.
*/
try {
NumberValue maxNumberValue;
NumberValue minNumberValue;
EvaluatedProperty maxVal = maximum.evaluate(ctx, depth);
EvaluatedProperty minVal = minimum.evaluate(ctx, depth);
EvaluatedProperty deltaVal = null;
maxNumberValue = null;
minNumberValue = null;
/*
* First, retrieve the maximum value.
*/
if (maxVal.size() != 1 || maxVal.first().isModal()) {
throw new InvalidModelException(ctx.getInstanceObject(), "Range maximum is modal");
}
if (maxVal.first().getValue() instanceof NumberValue) {
maxNumberValue = (NumberValue) maxVal.first().getValue();
} else {
throw new InvalidModelException(ctx.getInstanceObject(), "Range maximum is not numeric");
}
/*
* So now, retrieve the minimum value.
*/
if (minVal.size() != 1 || minVal.first().isModal()) {
throw new InvalidModelException(ctx.getInstanceObject(), "Range minimum is modal");
}
if (minVal.first().getValue() instanceof NumberValue) {
minNumberValue = (NumberValue) minVal.first().getValue();
} else {
throw new InvalidModelException(ctx.getInstanceObject(), "Range minimum is not numeric");
}
if (delta != null) {
deltaVal = delta.evaluate(ctx, depth);
if (deltaVal.size() != 1 || deltaVal.first().isModal()) {
throw new InvalidModelException(ctx.getInstanceObject(), "Range delta is modal");
}
if (!(deltaVal.first().getValue() instanceof NumberValue)) {
throw new InvalidModelException(ctx.getInstanceObject(), "Range delta is not numeric");
}
}
RangeValue newVal = Aadl2Factory.eINSTANCE.createRangeValue();
newVal.setMaximum(maxNumberValue);
newVal.setMinimum(minNumberValue);
if (deltaVal != null) {
newVal.setDelta(deltaVal.first().getValue());
}
return new EvaluatedProperty(newVal);
} catch (NullPointerException e) {
throw new InvalidModelException(ctx.getInstanceObject(), "Incomplete range value");
} catch (ClassCastException e) {
throw new InvalidModelException(ctx.getInstanceObject(), "Incomplete range value");
}
}
use of com.google.api.ads.admanager.axis.v202205.NumberValue in project osate2 by osate.
the class GetProperties method getMaxDataRate.
public static double getMaxDataRate(RecordValue rate) {
BasicPropertyAssociation vr = GetProperties.getRecordField(rate.getOwnedFieldValues(), "Value_Range");
if (vr == null) {
return 0;
}
RangeValue rv = (RangeValue) vr.getOwnedValue();
PropertyExpression maximum = rv.getMaximum().evaluate(null, 0).first().getValue();
return ((NumberValue) maximum).getScaledValue();
}
Aggregations