Skip to contentMethod: hashCode()
      1: package symbols;
2: 
3: import model.Position;
4: import scanner.ScannerConstants;
5: 
6: /**
7:  * This abstract class represents the symbols.
8:  * 
9:  * @author HFW410
10:  * 
11:  */
12: public class AbstractSymbol {
13: 
14:         /**
15:          * This attribute is the position of the symbol.
16:          */
17:         private final transient Position position;
18: 
19:         /**
20:          * This constructor instantiate the Symbol.
21:          * 
22:          * @param position
23:          *            (row and column) of the data in the datastream. The position of the first sign of
24:          *            the symbol inclusive of the \# or ' etc.
25:          */
26:         protected AbstractSymbol(final Position position) {
27:                 super();
28:                 this.position = position;
29:         }
30: 
31:         /**
32:          * 
33:          * @return the position
34:          */
35:         public Position getPosition() {
36:                 return this.position;
37:         }
38: 
39:         /**
40:          * 
41:          * @return true, if the Symbol is a value symbol.
42:          */
43:         public Boolean isValueSymbol() {
44:                 return Boolean.FALSE;
45:         }
46: 
47:         /**
48:          * 
49:          * @return true, if the Symbol is a path symbol.
50:          */
51:         public Boolean isPathSymbol() {
52:                 return Boolean.FALSE;
53:         }
54: 
55:         /**
56:          * 
57:          * @return true, if the Symbol is a row end symbol.
58:          */
59:         public Boolean isRowEndSymbol() {
60:                 return Boolean.FALSE;
61:         }
62: 
63:         /**
64:          * 
65:          * @return true, if the Symbol is a package description file symbol.
66:          */
67:         public Boolean isPackageDescriptionFileSymbol() {
68:                 return Boolean.FALSE;
69:         }
70: 
71:         /**
72:          * @return an error, if the symbol is not a variable symbol
73:          */
74:         public VariableSymbol toVariableSymbol() {
75:                 throw new WrongTypeError(ScannerConstants.WTE_VARIABLE);
76:         }
77: 
78:         /**
79:          * @return an error, if the symbol is not a value symbol
80:          */
81:         public ValueSymbol toValueSymbol() {
82:                 throw new WrongTypeError(ScannerConstants.WTE_VALUE);
83:         }
84: 
85:         /**
86:          * @return an error, if the symbol is not a path symbol
87:          */
88:         public PathSymbol toPathSymbol() {
89:                 throw new WrongTypeError(ScannerConstants.WTE_PATH);
90:         }
91: 
92:         /**
93:          * @return an error, if the symbol is not an option symbol
94:          */
95:         public OptionSymbol toOptionSymbol() {
96:                 throw new WrongTypeError(ScannerConstants.WTE_OPTION);
97:         }
98: 
99:         /**
100:          * @return an error, if the symbol is not a comment symbol
101:          */
102:         public CommentSymbol toCommentSymbol() {
103:                 throw new WrongTypeError(ScannerConstants.WTE_COMMENT);
104:         }
105: 
106:         /**
107:          * 
108:          * @return a PackageDescriptionFileSymbol or an error, if the symbol is not a package
109:          *         description file symbol.
110:          */
111:         public PackageDescriptionFileSymbol toPackageDescriptionFileSymbol() {
112:                 throw new WrongTypeError(ScannerConstants.WTE_PACKAGESYMBOL);
113:         }
114: 
115:         @Override
116:         public int hashCode() {
117:                 return this.position.hashCode();
118:         }
119: 
120:         @Override
121:         public boolean equals(final Object obj) {
122:                 return obj instanceof AbstractSymbol
123:                                 && ((AbstractSymbol) obj).getPosition().equals(this.getPosition());
124:         }
125: 
126: }