Search in sources :

Example 61 with NumberValue

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

Example 62 with NumberValue

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;
}
Also used : RealLiteral(org.osate.aadl2.RealLiteral) ModalPropertyValue(org.osate.aadl2.ModalPropertyValue) NumberValue(org.osate.aadl2.NumberValue) PropertyAssociation(org.osate.aadl2.PropertyAssociation) BasicPropertyAssociation(org.osate.aadl2.BasicPropertyAssociation) PropertyExpression(org.osate.aadl2.PropertyExpression) RefinableElement(org.osate.aadl2.RefinableElement) BasicProperty(org.osate.aadl2.BasicProperty) Property(org.osate.aadl2.Property) IntegerLiteral(org.osate.aadl2.IntegerLiteral)

Example 63 with NumberValue

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

Example 64 with NumberValue

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

Example 65 with NumberValue

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;
}
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)

Aggregations

LinkedHashSet (java.util.LinkedHashSet)30 NumberValue (org.osate.aadl2.NumberValue)24 RangeValue (org.osate.aadl2.RangeValue)13 PropertyExpression (org.osate.aadl2.PropertyExpression)12 ParseException (java.text.ParseException)10 Set (java.util.Set)10 Before (org.junit.Before)10 Test (org.junit.Test)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