Package ptolemy.data

Examples of ptolemy.data.ScalarToken


     * @exception IllegalActionException If there is no director.
     */
    public void fire() throws IllegalActionException  {
        super.fire();
        if (_nextPort.hasToken(0)) {
            ScalarToken readToken = (ScalarToken)_nextPort.get(0);
            if (_debugging) {
                _debug("Read input token from " + _nextPort.getName()+" with value "+readToken);
            }
            if (_recordedToken == null) {
                $ASSIGN$_tentativeRecordedToken(readToken);
                $ASSIGN$_tentativeReadFromA(true);
                $ASSIGN$_tentativeNextPort(inputB);
            } else {
                if ((readToken.isLessThan(_recordedToken)).booleanValue()) {
                    output.send(0, readToken);
                    if (_debugging) {
                        _debug("Sent output token with value " + readToken);
                    }
                    if (_nextPort == inputA) {
View Full Code Here


            // unlike other scalars.
            if ((leftToken instanceof ScalarToken)
                    && (rightToken instanceof ScalarToken)
                    && !(leftToken instanceof BooleanToken)) {
                // handle the relations like x == 2.0
                ScalarToken difference = (ScalarToken) leftToken
                        .subtract(rightToken);
                if (((BooleanToken) result).booleanValue()) {
                    _relationType = RelationType.EQUAL_INEQUAL;
                } else {
                    if (difference.doubleValue() < 0) {
                        _relationType = RelationType.LESS_THAN;
                    } else {
                        _relationType = RelationType.GREATER_THAN;
                    }
                }
                _difference = difference.doubleValue();
            } else {
                // handle the relations like x == true, x == "str", or x!= false
                if (((BooleanToken) result).booleanValue()) {
                    _relationType = RelationType.TRUE;
                } else {
                    _relationType = RelationType.FALSE;
                }
                _difference = 0.0;
            }
        } else {
            // If the operator is neither about equal nor not-equal relations,
            // both tokens must be scalar tokens.
            if (!((leftToken instanceof ScalarToken) && (rightToken instanceof ScalarToken))) {
                throw new IllegalActionException("The " + operator.image
                        + " operator can only be applied between scalars.");
            }
            ScalarToken leftScalar = (ScalarToken) leftToken;
            ScalarToken rightScalar = (ScalarToken) rightToken;
            // A relation needs strictly satisfied.
            if (operator.kind == PtParserConstants.GTE) {
                result = leftScalar.isLessThan(rightScalar).not();
            } else if (operator.kind == PtParserConstants.GT) {
                result = rightScalar.isLessThan(leftScalar);
            } else if (operator.kind == PtParserConstants.LTE) {
                result = rightScalar.isLessThan(leftScalar).not();
            } else if (operator.kind == PtParserConstants.LT) {
                result = leftScalar.isLessThan(rightScalar);
            } else {
                throw new IllegalActionException("Invalid operation "
                        + operator.image + " between "
View Full Code Here

     @exception IllegalActionException If there is no director.
     */
    public void fire() throws IllegalActionException {
        super.fire();
        if (input.hasToken(0)) {
            ScalarToken in = (ScalarToken) input.get(0);
            output.send(0, in.absolute());
        }
    }
View Full Code Here

     *  produce no output.
     *  @exception IllegalActionException If there is no director.
     */
    public void fire() throws IllegalActionException {
        super.fire();
        ScalarToken result = null;
        ScalarToken resultMagnitude = null;
        ScalarToken inMagnitude = null;
        int channelNum = -1;

        for (int i = 0; i < input.getWidth(); i++) {
            if (input.hasToken(i)) {
                ScalarToken in = (ScalarToken) input.get(i);

                if (in.getType().equals(BaseType.COMPLEX)) {
                    // If we have a complex, we use the absolute value
                    // for comparison, but save output the initial input
                    // for output at the end.
                    inMagnitude = in.absolute();
                } else {
                    inMagnitude = in;
                }

                if (result == null) {
View Full Code Here

            RecordToken defaultPropertiesValue = (RecordToken) defaultProperties
                    .getToken();

            // Type of the field must be convertible to double, but
            // need not actually be a double.
            ScalarToken field = (ScalarToken) defaultPropertiesValue
                    .get("range");
            range = field.doubleValue();
        }

        boolean result = (_distanceBetween(source, destination) <= range);

        if (result) {
View Full Code Here

        } else if (temporaryAttribute instanceof Variable) {
            Variable weightAttribute = (Variable) temporaryAttribute;
            Token weightToken = weightAttribute.getToken();

            if (weightToken instanceof ScalarToken) {
                ScalarToken weightScalarToken = (ScalarToken) weightToken;
                return weightScalarToken.intValue();
            }
            return 0;
        } else {
            _debug(" something wrong with the edge");
            return 0;
View Full Code Here

        // default properties and to apply registered transformers.
        RecordToken merged = super.transformProperties(properties, source,
                destination);

        // Get the transmit power.
        ScalarToken transmitPower = (ScalarToken) merged.get("power");

        // Evaluate the power loss factor, which will have been updated
        // with the new value of "distance."
        double powerPropagationFactorValue = ((DoubleToken) powerPropagationFactor
                .getToken()).doubleValue();

        // Calculate the receive power.
        double receivePower = transmitPower.doubleValue()
                * powerPropagationFactorValue;

        // Create a record token with the receive power.
        String[] names = { "power" };
        Token[] values = { new DoubleToken(receivePower) };
View Full Code Here

            throw new IllegalActionException("Inputs to DotProduct have "
                    + "no elements.");
        }

        Token dotProd = null;
        ScalarToken currentTerm;

        for (int i = 0; i < array1.length; i++) {
            currentTerm = (ScalarToken) array1[i].multiply(array2[i]);

            if (dotProd == null) {
View Full Code Here

            RecordToken defaultPropertiesValue = (RecordToken) defaultProperties
                    .getToken();

            // Type of the field must be convertible to double, but
            // need not actually be a double.
            ScalarToken field = (ScalarToken) defaultPropertiesValue
                    .get("range");
            range = field.doubleValue();
        }

        boolean result = (_distanceBetween(source, destination) <= range);

        // Whether a port is in range depends on the
View Full Code Here

     *  output.  If there is no input, then produce no output.
     *  @exception IllegalActionException If there is no director.
     */
    public void fire() throws IllegalActionException {
        super.fire();
        ScalarToken result = null;
        ScalarToken resultMagnitude = null;
        ScalarToken inMagnitude = null;
        int channelNum = -1;

        for (int i = 0; i < input.getWidth(); i++) {
            if (input.hasToken(i)) {
                ScalarToken in = (ScalarToken) input.get(i);

                if (in.getType().equals(BaseType.COMPLEX)) {
                    // If we have a complex, we use the absolute value
                    // for comparison, but save output the initial input
                    // for output at the end.
                    inMagnitude = in.absolute();
                } else {
                    inMagnitude = in;
                }

                if (result == null) {
View Full Code Here

TOP

Related Classes of ptolemy.data.ScalarToken

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.