Skip to content

Method: hashCode()

1: package de.fhdw.wtf.common.token;
2:
3: /**
4: * This token contains one identifier - e.g. a class identifier.
5: *
6: */
7: public final class IdentifierToken extends MultiCharToken {
8:         
9:         /**
10:          * generated.
11:          */
12:         private static final long serialVersionUID = -2521207444154441984L;
13:         
14:         /**
15:          * Private Constructor for IdentifierToken. Use create(...)-Factory instead!
16:          *
17:          * @param identifier
18:          * initial identifier string
19:          * @param position
20:          * start position of this token in the original input.
21:          */
22:         private IdentifierToken(final String identifier, final Position position) {
23:                 super(identifier, position);
24:         }
25:         
26:         /**
27:          * Factory for a {@link IdentifierToken}.
28:          *
29:          * @param identifier
30:          * initial identifier string
31:          * @param position
32:          * start position of this token in the original input.
33:          * @return a new instance of this token
34:          */
35:         public static IdentifierToken create(final String identifier, final Position position) {
36:                 return new IdentifierToken(identifier, position);
37:         }
38:         
39:         @Override
40:         public boolean isIdentifierToken() {
41:                 return true;
42:         }
43:         
44:         /**
45:          * Identifier as string representation.
46:          *
47:          * @return identifier represented by this token
48:          */
49:         public String getIdentifier() {
50:                 return this.getTokenString();
51:         }
52:         
53:         @Override
54:         protected boolean equalsTemplate(final Token t) {
55:                 if (t.isIdentifierToken()) {
56:                         final IdentifierToken ct = (IdentifierToken) t;
57:                         return this.getIdentifier().equals(ct.getIdentifier());
58:                 }
59:                 return false;
60:         }
61:         
62:         @Override
63:         protected int hashCodeTemplate() {
64:                 return this.getIdentifier().hashCode();
65:         }
66:         
67:         @Override
68:         public boolean equals(final Object o) {
69:                 if (o instanceof IdentifierToken) {
70:                         return super.equals(o);
71:                 }
72:                 return false;
73:         }
74:         
75:         @Override
76:         public int hashCode() {
77:                 return super.hashCode();
78:         }
79:         
80: }