Search in sources :

Example 61 with NumberValue

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;
}
Also used : Element(org.osate.aadl2.Element) QualifiedNamedElement(org.osate.ba.declarative.QualifiedNamedElement) DeclarativeBehaviorElement(org.osate.ba.declarative.DeclarativeBehaviorElement) NamedElement(org.osate.aadl2.NamedElement) PropertyConstant(org.osate.aadl2.PropertyConstant) DeclarativePropertyReference(org.osate.ba.declarative.DeclarativePropertyReference) NumberValue(org.osate.aadl2.NumberValue) ArraySize(org.osate.aadl2.ArraySize) PropertyExpression(org.osate.aadl2.PropertyExpression) ArrayDimension(org.osate.aadl2.ArrayDimension) DeclarativeArrayDimension(org.osate.ba.declarative.DeclarativeArrayDimension)

Example 62 with NumberValue

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

Example 63 with NumberValue

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;
}
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 64 with NumberValue

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");
    }
}
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 65 with NumberValue

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