use of com.google.api.ads.admanager.jaxws.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.jaxws.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.jaxws.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.jaxws.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();
}
use of com.google.api.ads.admanager.jaxws.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;
}
Aggregations