1 /*
2 * db2sa: DB2 Syntax Assistant
3 * Copyright (C) Andres Gomez Casanova
4 *
5 * This file is part of db2sa.
6 *
7 * db2sa 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 * db2sa 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: 2009-06-11 23:52:28 +0200 (Thu, 11 Jun 2009) $:
26 * Revision: $LastChangedRevision: 225 $:
27 * URL: $HeadURL: https://db2sa.svn.sourceforge.net/svnroot/db2sa/branches/db2sa_beta/source-code/src/main/java/name/angoca/db2sa/core/syntax/graph/StartingToken.java $:
28 */
29 package name.angoca.db2sa.core.syntax.graph;
30
31 import java.util.List;
32
33 import name.angoca.db2sa.Constants;
34
35 /**
36 * This token represents the first token in the grammar (the starting node in
37 * the graph.) All the possible ways starts from this token.<br/>
38 * <b>Control Version</b><br />
39 * <ul>
40 * <li>0.0.1 Class creation.</li>
41 * <li>0.0.2 Recommendations from PMD.</li>
42 * <li>0.0.3 Change constant value.</li>
43 * <li>0.0.4 Starting and ending token as constants.</li>
44 * <li>0.0.5 equals from super.</li>
45 * <li>0.0.6 equals different super.</li>
46 * <li>0.0.7 part equals super.</li>
47 * <li>1.0.0 Moved to version 1.</li>
48 * </ul>
49 *
50 * @author Andres Gomez Casanova <a
51 * href="mailto:a n g o c a at y a h o o dot c o m">(AngocA)</a>
52 * @version 1.0.0 2009-07-19
53 */
54 public class StartingToken extends GraphToken {
55
56 /**
57 * Constructor that defines the starting node. Its name is STARTING_TOKEN
58 * and this works as a reserved name token.
59 */
60 public StartingToken() {
61 super(Constants.STARTING_TOKEN, true);
62 }
63
64 /*
65 * (non-Javadoc)
66 *
67 * @see
68 * name.angoca.db2sa.core.syntax.graph.GraphToken#equals(java.lang.Object)
69 */
70 @Override
71 public final boolean equals(final Object/* ? */object) {
72 // The equals was designed not to be symmetric with its parent.
73 // TODO test a.equals(b) y b.equals(a)
74 boolean equals = false;
75 if (object instanceof StartingToken) {
76 final GraphToken token = (GraphToken) object;
77 final List<GraphToken> ways = token.getWays();
78 if (token.getName().compareTo(this.getName()) == 0
79 && token.isReservedWord() == this.isReservedWord()
80 && ways.size() == this.getWays().size()) {
81 equals = super.equals(token);
82 }
83 }
84 return equals;
85 }
86
87 /*
88 * (non-Javadoc)
89 *
90 * @see java.lang.Object#hashCode()
91 */
92 @Override
93 public final int hashCode() {
94 return Constants.STARTING_TOKEN.hashCode() * -1;
95 }
96
97 /**
98 * Returns a string representation of an starting token. The representation
99 * is: {START NODE}
100 *
101 * @see java.lang.Object#toString()
102 * @return String representation of an starting token.
103 */
104 @Override
105 public final String/* ! */toString() {
106 return "{START NODE}"; //$NON-NLS-1$
107 }
108 }