1 /*
2 * Copyright (c) 2009 QOS.ch All rights reserved.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 * SOFTWARE.
21 */
22 package ch.qos.cal10n.util;
23
24 /**
25 *
26 * @author Ceki Gülcü
27 *
28 */
29 public class Token {
30
31 final static Token EOL = new Token(TokenType.EOL);
32 final static Token TRAILING_BACKSLASH = new Token(TokenType.TRAILING_BACKSLASH);
33
34 enum TokenType {
35 KEY,
36 SEPARATOR,
37 VALUE,
38 TRAILING_BACKSLASH,
39 EOL;
40 }
41
42 final TokenType tokenType;
43 final String value;
44
45
46 Token(TokenType tokenType) {
47 this(tokenType, null);
48 }
49
50 Token(TokenType tokenType, String value) {
51 this.tokenType = tokenType;
52 this.value = value;
53 }
54
55
56 public TokenType getTokenType() {
57 return tokenType;
58 }
59
60 public String getValue() {
61 return value;
62 }
63
64 public String toString() {
65 if (value == null) {
66 return "Token(" + tokenType + ")";
67 } else {
68 return "Token(" + tokenType + ", \"" + value + "\")";
69 }
70 }
71
72 @Override
73 public int hashCode() {
74 return tokenType.hashCode();
75 }
76
77 @Override
78 public boolean equals(Object obj) {
79 if (this == obj)
80 return true;
81 if (obj == null)
82 return false;
83 if (getClass() != obj.getClass())
84 return false;
85 Token other = (Token) obj;
86
87 if (!tokenType.equals(other.tokenType))
88 return false;
89
90 if (value == null) {
91 if (other.value != null)
92 return false;
93 } else if (!value.equals(other.value))
94 return false;
95 return true;
96 }
97
98
99 }