Skip to content

Method: hashCode()

1: package de.fhdw.wtf.common.ast;
2:
3: import de.fhdw.wtf.common.token.DummyToken;
4: import de.fhdw.wtf.common.token.Token;
5:
6: /**
7: * The reference for a {@link Constructor} that does not need to be existent when this reference is being parsed.
8: *
9: */
10: public final class ConstructorReference extends SyntaxObject {
11:         
12:         /**
13:          * The state, that characterizes this {@link ConstructorReference}.
14:          */
15:         private ConstructorReferenceState state;
16:         
17:         /**
18:          * Creates a new {@link ConstructorReference}.
19:          *
20:          * @param state
21:          * The state, that characterizes this {@link ConstructorReference}.
22:          * @return a new instance of {@link ConstructorReference}.
23:          */
24:         public static ConstructorReference create(final ConstructorReferenceState state) {
25:                 final Token dummy = DummyToken.getInstance();
26:                 return new ConstructorReference(state, dummy, dummy);
27:         }
28:         
29:         /**
30:          * Creates a new {@link ConstructorReference}.
31:          *
32:          * @param state
33:          * The state, that characterizes this {@link ConstructorReference}.
34:          * @param firstToken
35:          * firstToken.
36:          * @param lastToken
37:          * lastToken.
38:          */
39:         private ConstructorReference(final ConstructorReferenceState state, final Token firstToken, final Token lastToken) {
40:                 super(firstToken, lastToken);
41:                 this.state = state;
42:         }
43:         
44:         @Override
45:         public String toString() {
46:                 return this.getState().toString();
47:                 // final StringBuilder result = new StringBuilder();
48:                 // result.append(this.getParameters());
49:                 // result.append(AstDescriptionConstants.SEMICOLON_TOKEN);
50:                 // return result.toString();
51:         }
52:         
53:         @Override
54:         public boolean equals(final Object o) {
55:                 if (o instanceof ConstructorReference) {
56:                         final ConstructorReference other = (ConstructorReference) o;
57:                         return this.getState().equals(other.getState());
58:                 }
59:                 return false;
60:         }
61:         
62:         @Override
63:         public int hashCode() {
64:                 return this.getState().hashCode();
65:         }
66:         
67:         /**
68:          * The state, that characterizes this {@link ConstructorReference}.
69:          *
70:          * @return the state.
71:          */
72:         public ConstructorReferenceState getState() {
73:                 return this.state;
74:         }
75:         
76:         /**
77:          * Changes the state of this to <code>newState</code>.
78:          *
79:          * @param newState
80:          * - new State for {@link ConstructorReference}
81:          */
82:         public void setState(final ConstructorReferenceState newState) {
83:                 this.state = newState;
84:         }
85: }