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-09 19:09:09 +0200 (Tue, 09 Jun 2009) $:
26 * Revision: $LastChangedRevision: 211 $:
27 * URL: $HeadURL: https://db2sa.svn.sourceforge.net/svnroot/db2sa/branches/db2sa_beta/source-code/src/main/java/name/angoca/db2sa/core/syntax/graph/EndingToken.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 last token in the grammar (the ending node in the
37 * graph.) All the possible ways ends in 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>1.0.0 Moved to version 1.</li>
47 * </ul>
48 *
49 * @author Andres Gomez Casanova <a
50 * href="mailto:a n g o c a at y a h o o dot c o m">(AngocA)</a>
51 * @version 1.0.0 2009-07-19
52 */
53 public class EndingToken extends GraphToken {
54
55 /**
56 * Constructor that defines the ending node. Its name is ENDING_TOKEN and
57 * this works as a reserved name token..
58 */
59 public EndingToken() {
60 super(Constants.ENDING_TOKEN, true);
61 }
62
63 /*
64 * (non-Javadoc)
65 *
66 * @see
67 * name.angoca.db2sa.core.syntax.graph.GraphToken#equals(java.lang.Object)
68 */
69 @Override
70 public final boolean equals(final Object/* ? */object) {
71 // The equals was designed not to be symmetric with its parent.
72 // TODO test a.equals(b) y b.equals(a)
73 boolean equals = false;
74 if (object instanceof EndingToken) {
75 final GraphToken token = (GraphToken) object;
76 final List<GraphToken> ways = token.getWays();
77 if (token.getName().compareTo(this.getName()) == 0
78 && token.isReservedWord() == this.isReservedWord()
79 && ways.size() == this.getWays().size()
80 && this.getWays().size() == 0) {
81 equals = true;
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.ENDING_TOKEN.hashCode() * -1;
95 }
96
97 /**
98 * Returns a string representation of an ending token. The representation
99 * is: {END NODE}
100 *
101 * @see java.lang.Object#toString()
102 * @return String representation of an ending token.
103 */
104 @Override
105 public final String/* ! */toString() {
106 return "{END NODE}"; //$NON-NLS-1$
107 }
108 }