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:42:19 +0200 (Thu, 11 Jun 2009) $:
26 * Revision: $LastChangedRevision: 223 $:
27 * URL: $HeadURL: https://db2sa.svn.sourceforge.net/svnroot/db2sa/branches/db2sa_beta/source-code/src/main/java/name/angoca/db2sa/core/lexical/Token.java $:
28 */
29 package name.angoca.db2sa.core.lexical;
30
31 import name.angoca.db2sa.core.lexical.exceptions.InvalidTokenException;
32
33 /**
34 * This is the representation of the decomposition of a phrase in several words
35 * or symbols. Each token is the product of dividing the given phrase and
36 * tokenize it in spaces, parenthesis and single and double quotation marks.
37 * TODO is reserved?<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>1.0.0 Moved to version 1.</li>
43 * </ul>
44 *
45 * @author Andres Gomez Casanova <a
46 * href="mailto:a n g o c a at y a h o o dot c o m">(AngocA)</a>
47 * @version 1.0.0 2009-07-19
48 */
49 public class Token {
50
51 /**
52 * Content that the token represents.
53 */
54 private final transient String m_token;
55
56 /**
57 * Constructor of a token, giving the value of it. A token cannot be a empty
58 * string.
59 *
60 * @param token
61 * Value to represent.
62 * @throws InvalidTokenException
63 * When trying to create an invalid token.
64 */
65 public Token(final String/* ! */token) throws InvalidTokenException {
66 if (token.compareTo("") == 0) { //$NON-NLS-1$
67 throw new InvalidTokenException();
68 }
69 this.m_token = token;
70 }
71
72 /*
73 * (non-Javadoc)
74 *
75 * @see java.lang.Object#equals(java.lang.Object)
76 */
77 @Override
78 public final boolean equals(final Object object/* ? */) {
79 boolean equals = false;
80 if (object instanceof Token) {
81 final Token token = (Token) object;
82 if (token.m_token.compareTo(this.m_token) == 0) {
83 equals = true;
84 }
85 }
86 return equals;
87 }
88
89 /**
90 * Returns the value that this token represents.
91 *
92 * @return the value that this token represents.
93 */
94 public final String/* ! */getToken() {
95 return this.m_token;
96 }
97
98 /*
99 * (non-Javadoc)
100 *
101 * @see java.lang.Object#hashCode()
102 */
103 @Override
104 public final int hashCode() {
105 final int value = this.getClass().getName().hashCode()
106 + this.m_token.hashCode();
107 return value;
108 }
109
110 /**
111 * Returns a string representation of a token. The representation is:
112 * T[token]
113 *
114 * @see java.lang.Object#toString()
115 * @return String representation of a token.
116 */
117 @Override
118 public final String/* ! */toString() {
119 return "T[" + this.m_token + ']'; //$NON-NLS-1$
120 }
121 }