View Javadoc

1   /*
2    * Zemucan: A Syntax Assistant for DB2
3    * Copyright (C) 2009, 2010 Andres Gomez Casanova
4    *
5    * This file is part of Zemucan.
6    *
7    * Zemucan is free software: you can redistribute it and/or modify
8    * it under the terms of the GNU Lesser General Public License as published by
9    * the Free Software Foundation; either version 3 of the License, or
10   * (at your option) any later version.
11   *
12   * Zemucan is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   * GNU Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public License
18   * along with this library; if not, see <http://www.gnu.org/licenses/>.
19   *
20   * Contact:
21   * a n g o c a  at  y a h o o  dot  c o m
22   * Cra. 45 No 61 - 31, Bogota, Colombia.
23   *
24   * Author:   $LastChangedBy: angoca $:
25   * Date:     $LastChangedDate: 2011-03-06 23:10:20 -0500 (dom, 06 mar 2011) $:
26   * Revision: $LastChangedRevision: 1917 $:
27   * URL:      $HeadURL: https://zemucan.svn.sourceforge.net/svnroot/zemucan/branches/zemucan_v1/source-code/graph/src/main/java/name/angoca/zemucan/core/graph/model/NonReservedGraphNode.java $:
28   */
29  package name.angoca.zemucan.core.graph.model;
30  
31  import name.angoca.zemucan.core.graph.api.InvalidGraphNodeException;
32  
33  /**
34   * Represents a word that should be defined by the user. It means, it could
35   * represents a name or a value, that the user introduce and its value is
36   * variable.
37   * <p>
38   * <b>Control Version</b>
39   * <p>
40   * <ul>
41   * <li>1.0.0 Class creation.</li>
42   * </ul>
43   *
44   * @author Andres Gomez Casanova <a
45   *         href="mailto:a n g o c a at y a h o o dot c o m">(AngocA)</a>
46   * @version 1.0.0 2010-08-28
47   */
48  public class NonReservedGraphNode extends TextualGraphNode {
49  
50  	/**
51  	 * Constructs a node with just only the id.
52  	 *
53  	 * @param name
54  	 *            Id of the node.
55  	 * @param graph
56  	 *            Graph.
57  	 * @throws InvalidGraphNodeException
58  	 *             The name is invalid.
59  	 */
60  	NonReservedGraphNode(final String/* ! */name, final Graph/* ! */graph)
61  			throws InvalidGraphNodeException {
62  		this(name, name, graph);
63  	}
64  
65  	/**
66  	 * Constructs a node with just only the id.
67  	 *
68  	 * @param tokenId
69  	 *            Id of the node.
70  	 * @param graphNodeName
71  	 *            Name of the token.
72  	 * @param graph
73  	 *            Graph.
74  	 * @throws InvalidGraphNodeException
75  	 *             The name is invalid.
76  	 */
77  	NonReservedGraphNode(final String/* ! */tokenId,
78  			final String /* ! */graphNodeName, final Graph/* ! */graph)
79  			throws InvalidGraphNodeException {
80  		super(tokenId, graphNodeName, graph);
81  	}
82  
83  	/*
84  	 * (non-Javadoc)
85  	 *
86  	 * @see java.lang.Object#hashCode()
87  	 */
88  	@Override
89  	public final int hashCode() {
90  		int superHash = super.hashCode();
91  		if (superHash == 0) {
92  			superHash = 1;
93  		}
94  		final int value = superHash + GraphNode.class.getName().hashCode();
95  		return value;
96  	}
97  
98  	/*
99  	 * (non-Javadoc)
100 	 *
101 	 * @see
102 	 * name.angoca.zemucan.core.graph.model.AbstractGraphNode#represent(java
103 	 * .lang.String)
104 	 */
105 	@Override
106 	public final boolean represent(final String/* ! */token) {
107 		return true;
108 	}
109 
110 	/**
111 	 * Returns a string representation of a graph token. The representation is:
112 	 * <ul>
113 	 * <li>For a non word reserved token: {name}</li>
114 	 * <li>For a word reserver token: {name|R}</li>
115 	 * </ul>
116 	 *
117 	 * @see java.lang.Object#toString()
118 	 * @return String representation of a graph token.
119 	 */
120 	@Override
121 	public final String/* ! */toString() {
122 		final String ret = super.getName() + "::" + super.toString();
123 		assert ret != null;
124 		return ret;
125 	}
126 }