001/** A constant InequalityTerm.
002
003 Copyright (c) 1997-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.graph.test;
029
030import ptolemy.graph.GraphActionException;
031import ptolemy.graph.InequalityTerm;
032
033///////////////////////////////////////////////////////////////////
034//// TestConstant
035
036/**
037 A constant InequalityTerm.
038 This class is for testing inequality related classes.
039 The value of this InequalityTerm is a String set in the constructor.
040 This term has name, which is used for printing test result.
041
042 @author Yuhong Xiong
043 @version $Id$
044 @since Ptolemy II 0.2
045 @Pt.ProposedRating Red (cxh)
046 @Pt.AcceptedRating Red (cxh)
047 */
048public class TestConstant implements InequalityTerm {
049    /** Construct a constant InequalityTerm with a String value.
050     *  @param value A String
051     */
052    public TestConstant(String value) {
053        _value = value;
054    }
055
056    ///////////////////////////////////////////////////////////////////
057    ////                         public methods                    ////
058
059    /** Do nothing.
060     */
061    public void fixValue() {
062    }
063
064    /** Return the string value.
065     *  @return A String
066     */
067    @Override
068    public Object getAssociatedObject() {
069        return _value;
070    }
071
072    /** Return the information of this term. The information is a
073     *  String of the form: <i>name</i>(constant)_<i>value</i>.
074     *  @return A String
075     */
076    public String getInfo() {
077        return _name + "(constant)_" + getValue();
078    }
079
080    /** Return the constant String value of this term.
081     *  @return a String
082     *  @see #setValue(Object)
083     */
084    @Override
085    public Object getValue() {
086        return _value;
087    }
088
089    /** Return an array of size zero.
090     *  @return an array of InequalityTerms
091     */
092    @Override
093    public InequalityTerm[] getVariables() {
094        return new InequalityTerm[0];
095    }
096
097    /** Return false.
098     *  @return false
099     */
100    @Override
101    public boolean isSettable() {
102        return false;
103    }
104
105    /** Throw an Exception.
106     *  @exception GraphActionException Always thrown since this term is a
107     *   constant.
108     */
109    @Override
110    public void initialize(Object e) throws GraphActionException {
111        throw new GraphActionException(
112                "TestConstant.initialize: This term " + "is a constant.");
113    }
114
115    /** Check whether the current value of this term is acceptable,
116     *  and return true if it is.  In this class, a value is always
117     *  acceptable.
118     *  @return True.
119     */
120    @Override
121    public boolean isValueAcceptable() {
122        return true;
123    }
124
125    /** Set the name of this constant. If the specified String is null,
126     *  Set the name to an empty String.
127     *  @param name The name of this constant.
128     */
129    public void setName(String name) {
130        if (name != null) {
131            _name = name;
132        } else {
133            _name = "";
134        }
135    }
136
137    /** Throw an Exception.
138     *  @param e an Object. Ignored by this method.
139     *  @exception GraphActionException always thrown.
140     *  @see #getValue()
141     */
142    @Override
143    public void setValue(Object e) throws GraphActionException {
144        throw new GraphActionException(
145                "TestConstant.setValue: This term " + "is a constant.");
146    }
147
148    /** Override the base class to describe the constant.
149     *  @return A string describing the constant
150     */
151    @Override
152    public String toString() {
153        return getClass().getName() + getInfo();
154    }
155
156    /** Do nothing.
157     */
158    public void unfixValue() {
159    }
160
161    ///////////////////////////////////////////////////////////////////
162    ////                         private methods                   ////
163    private String _name = "";
164
165    private String _value = null;
166}