Search in sources :

Example 66 with NumberValue

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;
}
Also used : InvalidModelException(org.osate.aadl2.properties.InvalidModelException) NumberValue(org.osate.aadl2.NumberValue) BooleanLiteral(org.osate.aadl2.BooleanLiteral) EvaluatedProperty(org.osate.aadl2.properties.EvaluatedProperty) PropertyExpression(org.osate.aadl2.PropertyExpression)

Example 67 with NumberValue

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;
}
Also used : NumberValue(org.osate.aadl2.NumberValue) ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl)

Example 68 with NumberValue

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();
}
Also used : NumberValue(org.osate.aadl2.NumberValue) PropertyExpression(org.osate.aadl2.PropertyExpression) BasicPropertyAssociation(org.osate.aadl2.BasicPropertyAssociation) RangeValue(org.osate.aadl2.RangeValue)

Example 69 with NumberValue

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;
    }
}
Also used : NumberValue(org.osate.aadl2.NumberValue) PropertyExpression(org.osate.aadl2.PropertyExpression) PropertyLookupException(org.osate.aadl2.properties.PropertyLookupException) RangeValue(org.osate.aadl2.RangeValue)

Aggregations

LinkedHashSet (java.util.LinkedHashSet)30 NumberValue (org.osate.aadl2.NumberValue)24 RangeValue (org.osate.aadl2.RangeValue)13 PropertyExpression (org.osate.aadl2.PropertyExpression)12 Test (org.junit.Test)11 ParseException (java.text.ParseException)10 Set (java.util.Set)10 Before (org.junit.Before)10 RecordValue (org.osate.aadl2.RecordValue)6 NumberValue (com.google.api.ads.admanager.axis.v202108.NumberValue)5 NumberValue (com.google.api.ads.admanager.axis.v202111.NumberValue)5 BooleanValue (com.google.api.ads.admanager.axis.v202105.BooleanValue)4 DateTimeValue (com.google.api.ads.admanager.axis.v202105.DateTimeValue)4 DateValue (com.google.api.ads.admanager.axis.v202105.DateValue)4 NumberValue (com.google.api.ads.admanager.axis.v202105.NumberValue)4 SetValue (com.google.api.ads.admanager.axis.v202105.SetValue)4 TargetingValue (com.google.api.ads.admanager.axis.v202105.TargetingValue)4 TextValue (com.google.api.ads.admanager.axis.v202105.TextValue)4 BooleanValue (com.google.api.ads.admanager.axis.v202202.BooleanValue)4 BooleanValue (com.google.api.ads.admanager.jaxws.v202205.BooleanValue)4