Package ptolemy.data

Examples of ptolemy.data.RecordToken


            if (attribute instanceof Variable) {
                value[i] = ((Variable) attribute).getToken();
            }
        }

        return new RecordToken(resultLabels, value);
    }
View Full Code Here


     @see ptolemy.actor.Receiver#get()
     @exception NoTokenException If there are no more tokens. This is
     *   a runtime exception, so it need not be declared explicitly.
     */
    public synchronized Token get() throws NoTokenException {
        RecordToken bundled = (RecordToken) super.get();
        _properties = bundled.get("properties");
        return bundled.get("value");
    }
View Full Code Here

        Token[] values = { properties, token };
        Token result = null;

        try {
            result = new RecordToken(labels, values);
        } catch (IllegalActionException e) {
            // Should not occur since we've ensured above that
            // nothing is null and the arrays have the same size.
            throw new InternalErrorException(e);
        }
View Full Code Here

            Token token2, double epsilon) throws IllegalActionException {
        if (!(token1 instanceof RecordToken)
                || !(token2 instanceof RecordToken)) {
            return false;
        }
        RecordToken record1 = (RecordToken) token1;
        RecordToken record2 = (RecordToken) token2;

        Set myLabelSet = record1.labelSet();
        Set argLabelSet = record2.labelSet();

        if (!myLabelSet.equals(argLabelSet)) {
            return false;
        }

        // 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) {
View Full Code Here

        if (director == null) {
            throw new IllegalActionException(this, "No director!");
        }

        if (input.hasToken(0)) {
            RecordToken record = (RecordToken) input.get(0);
            Iterator labels = record.labelSet().iterator();

            while (labels.hasNext()) {
                String label = (String) labels.next();
                Token value = record.get(label);
                IOPort port = (IOPort) getPort(label);

                // since the record received may contain more fields than the
                // output ports, some fields may not have a corresponding
                // output port.
View Full Code Here

            }
        }

        if (!rangeIsSet) {
            // Type constraints in the constructor make the casts safe.
            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);
View Full Code Here

                double timeValue = getDirector().getModelTime()
                        .getDoubleValue();
                Token[] values = { new ArrayToken(locationArray),
                        new DoubleToken(timeValue), new IntToken(0) };
                Token result = new RecordToken(labels, values);

                output.send(0, result);
            } else {
                // It is the pursuer. Send its parent info to the pursuer.
                if (_timeValue > 0.0) {
                    String[] labels = { "location", "time", "depth" };

                    Token[] values = { new ArrayToken(_parentLocation),
                            new DoubleToken(_timeValue),
                            new IntToken(_parentDepth) };
                    Token result = new RecordToken(labels, values);

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

     *  change its icon back to white.
     */
    public void fire() throws IllegalActionException {
        super.fire();
        if (input.hasToken(0)) {
            RecordToken in = (RecordToken) input.get(0);
            double data = ((DoubleToken) in.get("data")).doubleValue();
            String destination = ((StringToken) in.get("destination"))
                    .stringValue();
            String routeTo = ((StringToken) in.get("routeTo")).stringValue();
            int hops = ((IntToken) in.get("hops")).intValue();

            /*System.out.println(getName() + " receive a event with : " + "\n"
             + "destination = " + destination + "\n"
             + "routeTo = " + routeTo + "\n"
             + "hops = " + hops);
             */
            if (getName().equals(destination)) {
                // Change the color of the icon to red.
                _circle2.fillColor.setToken("{1.0, 0.0, 0.1, 0.7}");

                //_isRed = true;
                test.send(0, new IntToken(hops + 1));

                //Call fireAt to set the color back to white after the delay time.
                Director director = getDirector();
                double delayTime = ((DoubleToken) delay.getToken())
                        .doubleValue();
                Time time = director.getModelTime().add(delayTime);
                director.fireAt(this, time);
            } else if (getName().equals(routeTo) || (hops == 0)) {
                // Change the color of the icon to green.
                _circle2.fillColor.setToken("{0.0, 1.0, 0.0, 1.0}");

                CompositeEntity container = (CompositeEntity) getContainer();
                Entity destNode = container.getEntity(destination);
                Locatable destLocation = (Locatable) destNode.getAttribute(
                        "_location", Locatable.class);
                Locatable myLocation = (Locatable) this.getAttribute(
                        "_location", Locatable.class);

                if ((destLocation == null) || (myLocation == null)) {
                    throw new IllegalActionException(
                            "Cannot determine location for node "
                                    + destNode.getName() + ".");
                }

                Iterator nodes = _connectedNodes.iterator();
                double minDistance = _distanceBetween(destLocation, myLocation);
                String to = " ";
                boolean multi = ((BooleanToken) doublePath.getToken())
                        .booleanValue();
                double nextMinDistance = _distanceBetween(destLocation,
                        myLocation);
                String to2 = " ";

                while (nodes.hasNext()) {
                    Entity node = (Entity) nodes.next();
                    Locatable location = (Locatable) node.getAttribute(
                            "_location", Locatable.class);

                    if (location == null) {
                        throw new IllegalActionException(
                                "Cannot determine location for node "
                                        + node.getName() + ".");
                    }

                    double d = _distanceBetween(destLocation, location);

                    if (multi) {
                        if (d < minDistance) {
                            nextMinDistance = minDistance;
                            to2 = to;
                            minDistance = d;
                            to = node.getName();
                        } else if (d < nextMinDistance) {
                            nextMinDistance = d;
                            to2 = node.getName();
                        }
                    } else {
                        if (d < minDistance) {
                            minDistance = d;
                            to = node.getName();
                        }
                    }
                }

                // Request refiring after a certain amount of time specified
                // by the <i>delay<i> parameter.
                Director director = getDirector();
                Token[] values = { new DoubleToken(data),
                        new StringToken(destination), new StringToken(to),
                        new IntToken(hops + 1) };
                double delayTime = ((DoubleToken) delay.getToken())
                        .doubleValue();
                Time time = director.getModelTime().add(delayTime);

                if (_receptions == null) {
                    _receptions = new HashMap();
                }

                Double timeDouble = Double.valueOf(time.getDoubleValue());
                String[] labels = { "data", "destination", "routeTo", "hops" };
                RecordToken result = new RecordToken(labels, values);
                _receptions.put(timeDouble, result);

                director.fireAt(this, time);

                if (multi) {
                    Token[] values2 = { new DoubleToken(data),
                            new StringToken(destination), new StringToken(to2),
                            new IntToken(hops + 1) };

                    if (_receptions == null) {
                        _receptions = new HashMap();
                    }

                    RecordToken result2 = new RecordToken(labels, values2);
                    _receptions.put(timeDouble, result2);

                    director.fireAt(this, time.add(delayTime));
                }

                //output.send(0, result);
            }
        } else {
            if (_receptions != null) {
                // We may be getting fired because of an impending event.
                double currentTimeValue = getDirector().getModelTime()
                        .getDoubleValue();
                Double timeDouble = Double.valueOf(currentTimeValue);
                RecordToken reception = (RecordToken) _receptions
                        .get(timeDouble);

                if (reception != null) {
                    // The time matches a pending reception.
                    _receptions.remove(reception);
View Full Code Here

     @see #registerPropertyTransformer(PropertyTransformer, WirelessIOPort)
     */
    public RecordToken transformProperties(RecordToken properties,
            WirelessIOPort source, WirelessIOPort destination)
            throws IllegalActionException {
        RecordToken result = properties;
        Token defaultPropertiesValue = defaultProperties.getToken();

        if (defaultPropertiesValue instanceof RecordToken) {
            if (properties != null) {
                result = RecordToken.merge(properties,
                        (RecordToken) defaultPropertiesValue);
            } else {
                result = (RecordToken) defaultPropertiesValue;
            }
        }

        if (_propertyTransformersByPort != null) {
            //Apply property transformer for the sender.
            Set transformers = (Set) _propertyTransformersByPort.get(source);

            if (transformers != null) {
                Iterator iterator = transformers.iterator();

                while (iterator.hasNext()) {
                    PropertyTransformer transformer = (PropertyTransformer) iterator
                            .next();
                    result = transformer.transformProperties(result, source,
                            destination);
                }
            }

            //Apply property transformers for the receiver.
            transformers = (Set) _propertyTransformersByPort.get(destination);

            if (transformers != null) {
                Iterator iterator = transformers.iterator();

                while (iterator.hasNext()) {
                    PropertyTransformer transformer = (PropertyTransformer) iterator
                            .next();
                    result = transformer.transformProperties(result, source,
                            destination);
                }
            }
        }

        if (_propertyTransformers != null) {
            Iterator iterator = _propertyTransformers.iterator();

            while (iterator.hasNext()) {
                PropertyTransformer transformer = (PropertyTransformer) iterator
                        .next();
                result = transformer.transformProperties(result, source,
                        destination);
            }
        }

        if (_debugging) {
            if (result != null) {
                _debug(" * transmission properties: \"" + result.toString()
                        + "\".");
            } else {
                _debug(" * no transmission properties.\"");
            }
        }
View Full Code Here

    public RecordToken transformProperties(RecordToken properties,
            WirelessIOPort source, WirelessIOPort destination)
            throws IllegalActionException {
        // Use the superclass to merge the record argument with the
        // 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) };
        RecordToken newPower = new RecordToken(names, values);

        // Merge the receive power into the merged token.
        RecordToken result = RecordToken.merge(newPower, merged);

        // Report the new received power.
        if (_debugging) {
            _debug(" * receive properties: \"" + result.toString() + "\".");
        }

        return result;
    }
View Full Code Here

TOP

Related Classes of ptolemy.data.RecordToken

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.