Package ptolemy.data

Examples of ptolemy.data.Token


        // Loop through all of the fields, checking each one for closeness.
        Iterator iterator = myLabelSet.iterator();

        while (iterator.hasNext()) {
            String label = (String) iterator.next();
            Token innerToken1 = record1.get(label);
            Token innerToken2 = record2.get(label);
            boolean result = false;
            if (innerToken1 instanceof ArrayToken) {
                result = _isCloseToIfNilArrayElement(innerToken1, innerToken2,
                        epsilon);
            } else if (innerToken1 instanceof RecordToken) {
                result = _isCloseToIfNilRecordElement(innerToken1, innerToken2,
                        epsilon);
            } else {
                result = innerToken1.isCloseTo(innerToken2, epsilon)
                        .booleanValue();
            }

            if (!result) {
                if (innerToken1.isNil() && innerToken2.isNil()) {
                    // They are not close, but both are nil, so for
                    // our purposes, the are close.
                } else {
                    return false;
                }
View Full Code Here


                _trainingTokens = new ArrayList();
            }

            if (width == 1) {
                if (input.hasToken(0)) {
                    Token token = input.get(0);
                    if (token instanceof ArrayToken) {
                        Token[] innerArrayToken = new Token[1];
                        innerArrayToken[0] = token;
                        _trainingTokens.add(innerArrayToken);
                    } else {
                        _trainingTokens.add(token);
                    }
                }
            } else {
                ArrayList arrayList = new ArrayList();

                for (int i = 0; i < width; i++) {
                    arrayList.add(input.get(i));
                }

                _trainingTokens.add(arrayList);
            }

            return;
        }

        if (_numberOfInputTokensSeen >= ((ArrayToken) (correctValues.getToken()))
                .length()) {
            // Consume and discard input values.  We are beyond the end
            // of the correctValues array.
            for (int i = 0; i < width; i++) {
                if (input.hasToken(i)) {
                    input.get(i);
                }
            }

            // Indicate that the test has passed.
            output.send(0, new BooleanToken(true));
            return;
        }

        output.send(0, new BooleanToken(false));

        Token referenceToken = ((ArrayToken) (correctValues.getToken()))
                .getElement(_numberOfInputTokensSeen);
        Token[] reference;

        if ((width == 1) && !(referenceToken instanceof ArrayToken)) {
            reference = new Token[1];
            reference[0] = referenceToken;
        } else {
            try {
                reference = ((ArrayToken) referenceToken).arrayValue();
            } catch (ClassCastException ex) {
                throw new IllegalActionException(this,
                        "Test fails in iteration " + _numberOfInputTokensSeen
                                + ".\n" + "Width of input is " + width
                                + ", but correctValues parameter "
                                + "is not an array " + "of arrays.");
            }

            if (width != reference.length) {
                throw new IllegalActionException(this,
                        "Test fails in iteration " + _numberOfInputTokensSeen
                                + ".\n" + "Width of input is " + width
                                + ", which does not match "
                                + "the  width of the "
                                + _numberOfInputTokensSeen + "-th element of"
                                + " correctValues, " + reference.length);
            }
        }

        for (int i = 0; i < width; i++) {
            if (!input.hasToken(i)) {
                throw new IllegalActionException(this,
                        "Test fails in iteration " + _numberOfInputTokensSeen
                                + ".\n" + "Empty input on channel " + i);
            }

            Token token = input.get(i);
            boolean isClose;

            try {
                isClose = token.isCloseTo(reference[i], _tolerance)
                        .booleanValue()
                        || token.isNil() && reference[i].isNil();
                // Additional guards makes things slightly easier for
                // Copernicus.
                if (token instanceof ArrayToken
                        && reference[i] instanceof ArrayToken) {
                    isClose |= _isCloseToIfNilArrayElement(token, reference[i],
View Full Code Here

        boolean currentInputIsBlankLine = true;

        for (int i = 0; i < width; i++) {
            if (input.hasToken(i)) {
                Token token = input.get(i);

                if (!_initialized) {
                    _initialized = true;
                    _openWindow();
                }

                // If the window has been deleted, read the rest of the inputs.
                if (textArea == null) {
                    continue;
                }

                // FIXME: There is a race condition here.
                // textArea can be set to null during execution of this method
                // if another thread closes the display window.

                // The toString() method yields a string that can be parsed back
                // in the expression language to get the original token.
                // However, if the token is a StringToken, that probably is
                // not what we want. So we treat StringToken separately.
                String value = token.toString();
                if (token instanceof StringToken) {
                    value = ((StringToken) token).stringValue();
                }

                // If the value is not an empty string, set the
View Full Code Here

            if (token.length() == 0) {
                return;
            }

            Token sum = token.getElement(0);

            for (int i = 1; i < token.length(); i++) {
                sum = sum.add(token.getElement(i));
            }

            output.send(0, sum);
        }
    }
View Full Code Here

            if (SootUtilities.derivesFrom(type.getSootClass(),
                    PtolemyUtilities.tokenClass)) {
                // if we are invoking a method on a token class, then
                // attempt to get the constant value of the token.
                Token token = getTokenValue((Local) r.getBase(), unit,
                        _localDefs, _tokenAnalysis);

                if (_debug) {
                    System.out.println("reference to Token with value = "
                            + token);
View Full Code Here

     *   to the queue.
     *  @return true
     */
    public boolean postfire() throws IllegalActionException {
        if (input.hasToken(0)) {
            Token token = input.get(0);

            try {
                _jmfImageToken = (JMFImageToken) token;
            } catch (ClassCastException ex) {
                throw new IllegalActionException(this, ex, "Failed to cast "
                        + token.getClass()
                        + " to a JMFImageToken.\nToken was: " + token);
            }

            if (_debugging) {
                _debug("MoveWriter.postfire(): read in " + _jmfImageToken);
View Full Code Here

     throws an exception.
     *  @return super.postfire()
     */
    public boolean postfire() throws IllegalActionException {
        ObjectToken objectToken;
        Token token = input.get(0);

        try {
            objectToken = (ObjectToken) token;
        } catch (ClassCastException ex) {
            throw new IllegalActionException(this, ex, "Failed to cast "
                    + token.getClass() + " to an ObjectToken.\n"
                    + "The VideoPlayer actor expects to be connected to "
                    + "actors like the StreamLoader.\n"
                    + "Try connecting other actors to "
                    + "actor.lib.image.ImageDisplay.");
        }
View Full Code Here

     @exception IllegalActionException If the input operation code
     *  is not supported.
     */
    public void fire() throws IllegalActionException {
        super.fire();
        Token result = null;

        if (A.hasToken(0) && B.hasToken(0)) {
            int opcode = Integer.parseInt(operation.getExpression().substring(
                    0, 1));
            IntToken tokenA = (IntToken) A.get(0);
View Full Code Here

            if (token.length() == 0) {
                return;
            }

            Token sum = token.getElement(0);

            for (int i = 1; i < token.length(); i++) {
                sum = sum.add(token.getElement(i));
            }

            output.send(0, sum.divide(new IntToken(token.length())));
        }
    }
View Full Code Here

     @throw IllegalActionException If the input operation code
     *  is not supported.
     */
    public void fire() throws IllegalActionException {
        super.fire();
        Token result = null;

        if (A.hasToken(0) && B.hasToken(0) && operation.hasToken(0)) {
            int opcode = ((IntToken) operation.get(0)).intValue();
            IntToken tokenA = (IntToken) A.get(0);
            IntToken tokenB = (IntToken) B.get(0);
View Full Code Here

TOP

Related Classes of ptolemy.data.Token

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.