001/* A weighted node for an undirected or directed graph.
002
003 Copyright (c) 2001-2014 The University of Maryland
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 MARYLAND 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 MARYLAND HAS BEEN ADVISED OF THE POSSIBILITY OF
015 SUCH DAMAGE.
016
017 THE UNIVERSITY OF MARYLAND 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 MARYLAND HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
022 ENHANCEMENTS, OR MODIFICATIONS.
023
024 */
025package ptolemy.graph;
026
027////////////////////////////////////////////////////////////////////////// //
028//Node
029
030/**
031 An optionally-weighted node for an undirected or directed graph.  More
032 specifically, a node consists of an optional <i>weight</i> (an arbitrary
033 object that is associated with the node).  We say that a node is
034 <i>unweighted</i> if it does not have an assigned weight. It is an error to
035 attempt to access the weight of an unweighted node. Node weights must be
036 genuine (non-null) objects.
037
038 @author Shuvra S. Bhattacharyya
039 @version $Id$
040 @since Ptolemy II 2.0
041 @Pt.ProposedRating Red (cxh)
042 @Pt.AcceptedRating Red (cxh)
043 @see ptolemy.graph.Edge
044 */
045public final class Node extends Element {
046    /** Construct an unweighted node.
047     */
048    public Node() {
049        super();
050    }
051
052    /** Construct a node with a given node weight.
053     *  @param weight The given weight.
054     *  @exception IllegalArgumentException If the specified weight is
055     *  <code>null</code>.
056     */
057    public Node(Object weight) {
058        super(weight);
059    }
060
061    ///////////////////////////////////////////////////////////////////
062    ////                         public methods                    ////
063
064    /** A one-word description of the type of this graph element.
065     *  @return The description.
066     */
067    @Override
068    public String descriptor() {
069        return "node";
070    }
071
072    /** Return a string representation of the node.
073     *  The string representation is simply a representation of the node
074     *  weight (or the string <code>"&lt;unweighted node&gt;"</code> if
075     *  the node is unweighted.
076     */
077    @Override
078    public String toString() {
079        if (_weight == null) {
080            return "<unweighted node>";
081        } else {
082            return _weight.toString();
083        }
084    }
085}