use of com.google.api.ads.admanager.axis.v202205.NumberValue in project osate2 by osate.
the class OperationImpl method evaluate.
public EvaluatedProperty evaluate(EvaluationContext ctx, int depth) throws InvalidModelException {
if (ownedPropertyExpressions.size() < 1) {
throw new InvalidModelException(ctx.getInstanceObject(), "Property expression has no operands");
}
EvaluatedProperty left = ownedPropertyExpressions.get(0).evaluate(ctx, depth);
EvaluatedProperty right = null;
PropertyExpression arg1 = null;
PropertyExpression arg2 = null;
if (left.size() == 0) {
throw new InvalidModelException(ctx.getInstanceObject(), "Argument has no value");
}
if (left.size() != 1 || left.first().isModal()) {
throw new InvalidModelException(ctx.getInstanceObject(), "Argument to operation cannot be modal");
}
arg1 = left.first().getValue();
if (arg1 == null) {
throw new InvalidModelException(ctx.getInstanceObject(), "Argument missing");
}
// check for required arguments to operation
switch(op) {
case AND:
case OR:
if (ownedPropertyExpressions.size() < 2) {
throw new InvalidModelException(ctx.getInstanceObject(), "Second operand missing for binary operation");
}
if (ownedPropertyExpressions.size() > 2) {
throw new InvalidModelException(ctx.getInstanceObject(), "Too many operands in expression");
}
right = ownedPropertyExpressions.get(1).evaluate(ctx, depth);
if (right.size() != 1 || right.first().isModal()) {
throw new InvalidModelException(ctx.getInstanceObject(), "Argument to operation cannot be modal");
}
if (right.size() == 0) {
throw new InvalidModelException(ctx.getInstanceObject(), "Argument has no value");
}
arg2 = right.first().getValue();
if (arg2 == null) {
throw new InvalidModelException(ctx.getInstanceObject(), "Argument missing");
}
break;
default:
if (ownedPropertyExpressions.size() > 1) {
throw new InvalidModelException(ctx.getInstanceObject(), "Too many operands in expression");
}
break;
}
// check argument types
switch(op) {
case NOT:
if (!(arg1 instanceof BooleanLiteral)) {
throw new InvalidModelException(ctx.getInstanceObject(), "Argument to NOT does not evaluate to a boolean value");
}
// fall through!
case AND:
case OR:
if (!(arg2 instanceof BooleanLiteral)) {
throw new InvalidModelException(ctx.getInstanceObject(), "Second argument does not evaluate to a boolean value");
}
break;
default:
if (!(arg1 instanceof NumberValue)) {
throw new InvalidModelException(ctx.getInstanceObject(), "Argument does not evaluate to a numeric value");
}
break;
}
// calculate result
EvaluatedProperty result = null;
switch(op) {
case AND:
BooleanLiteral abv = Aadl2Factory.eINSTANCE.createBooleanLiteral();
abv.setValue(((BooleanLiteral) arg1).getValue() && ((BooleanLiteral) arg1).getValue());
result = new EvaluatedProperty(abv);
break;
case OR:
BooleanLiteral obv = Aadl2Factory.eINSTANCE.createBooleanLiteral();
obv.setValue(((BooleanLiteral) arg1).getValue() || ((BooleanLiteral) arg1).getValue());
result = new EvaluatedProperty(obv);
break;
case NOT:
BooleanLiteral nbv = Aadl2Factory.eINSTANCE.createBooleanLiteral();
nbv.setValue(!((BooleanLiteral) arg1).getValue());
result = new EvaluatedProperty(nbv);
break;
case PLUS:
result = left;
break;
case MINUS:
result = new EvaluatedProperty(((NumberValue) arg1).cloneAndInvert());
break;
default:
throw new AssertionError("Unexpected enum literal: " + getOp());
}
return result;
}
use of com.google.api.ads.admanager.axis.v202205.NumberValue in project osate2 by osate.
the class UnitLiteralImpl 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, Aadl2Package.UNIT_LITERAL__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 GetProperties method getMinDataRate.
public static double getMinDataRate(RecordValue rate) {
BasicPropertyAssociation vr = GetProperties.getRecordField(rate.getOwnedFieldValues(), "Value_Range");
if (vr == null) {
return 0;
}
RangeValue rv = (RangeValue) vr.getOwnedValue();
PropertyExpression minimum = rv.getMinimum().evaluate(null, 0).first().getValue();
return ((NumberValue) minimum).getScaledValue();
}
use of com.google.api.ads.admanager.axis.v202205.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. 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, 0).first().getValue();
if (maximum instanceof NumberValue) {
return ((NumberValue) maximum).getScaledValue(unit);
} else {
return defaultVal;
}
} catch (PropertyLookupException e) {
return defaultVal;
}
}
Aggregations