001/* Test file for attributeChanged() notification.
002
003 Copyright (c) 1998-2014 The Regents of the University of California.
004 All rights reserved.
005 Permission is hereby granted, without written agreement and without
006 license or royalty fees, to use, copy, modify, and distribute this
007 software and its documentation for any purpose, provided that the above
008 copyright notice and the following two paragraphs appear in all copies
009 of this software.
010
011 IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY
012 FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
013 ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
014 THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
015 SUCH DAMAGE.
016
017 THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
018 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
019 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
020 PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
021 CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
022 ENHANCEMENTS, OR MODIFICATIONS.
023
024 PT_COPYRIGHT_VERSION_2
025 COPYRIGHTENDKEY
026
027 */
028package ptolemy.data.expr.test;
029
030import ptolemy.data.DoubleToken;
031import ptolemy.data.expr.Parameter;
032import ptolemy.kernel.Entity;
033import ptolemy.kernel.util.Attribute;
034import ptolemy.kernel.util.IllegalActionException;
035import ptolemy.kernel.util.NameDuplicationException;
036
037//////////////////////////////////////////////////////////////////////////
038//// AttributeChanged
039
040/**
041 Test class that checks to see whether it is ok to cache parameter values.
042 @author  Edward A. Lee
043 @version $Id$
044 @since Ptolemy II 0.3
045 @Pt.ProposedRating Red (eal)
046 @Pt.AcceptedRating Red (reviewmoderator)
047 */
048public class AttributeChanged extends Entity {
049
050    /** Construct a test class for the attributeChanged() method.
051     *  @param name The name of this object.
052     *  @exception IllegalActionException If the entity cannot be contained
053     *   by the proposed container (see the setContainer() method).
054     *  @exception NameDuplicationException If the name coincides with
055     *   an entity already in the container.
056     */
057    public AttributeChanged(String name)
058            throws NameDuplicationException, IllegalActionException {
059        super(name);
060        param = new Parameter(this, "param", new DoubleToken(1.0));
061    }
062
063    /** The parameter to test. */
064    public Parameter param;
065
066    /** Update the cached value of the parameter.
067     *  @param attribute The attribute that might be param.
068     *  @exception IllegalActionException If thrown while getting the
069     *  parameter as a double.
070     */
071    @Override
072    public void attributeChanged(Attribute attribute)
073            throws IllegalActionException {
074        if (attribute == param) {
075            _param = ((DoubleToken) param.getToken()).doubleValue();
076        }
077    }
078
079    /** Return the cached value of the parameter.
080     *  @return the cached value of the parameter.
081     */
082    public double getParamValue() {
083        return _param;
084    }
085
086    private double _param;
087}