Skip to content

Method: equals(Object)

1: package de.fhdw.wtf.generator.java.generatorModel;
2:
3: import java.util.ArrayList;
4: import java.util.Collection;
5: import java.util.Vector;
6:
7: import de.fhdw.wtf.generator.java.visitor.GenerationModelItemVisitor;
8:
9: /**
10: * A GenParameter represents a java-like parameter. For example for operations.
11: */
12: public final class GenParameter extends GenerationModelItem {
13:         
14:         /**
15:          * The referenced type of the parameter.
16:          */
17:         private final GenTypeReference typ;
18:         
19:         /**
20:          * The modifiers of the parameter.
21:          */
22:         private final Collection<GenParameterModifier> modifiers;
23:         
24:         /**
25:          * Generics in addition to the type of the parameter.
26:          */
27:         private final ArrayList<Generic> generics;
28:         
29:         /**
30:          * Instantiates a new {@link GenParameter}.
31:          *
32:          * @param name
33:          * The name to identify the parameter.
34:          * @param typ
35:          * The referenced type of the parameter.
36:          */
37:         private GenParameter(final String name, final GenTypeReference typ) {
38:                 super(name);
39:                 this.typ = typ;
40:                 this.modifiers = new Vector<>();
41:                 this.generics = new ArrayList<>();
42:         }
43:         
44:         /**
45:          * Creates a new {@link GenParameter}.
46:          *
47:          * @param name
48:          * The name to identify the parameter.
49:          * @param typ
50:          * The referenced type of the parameter.
51:          * @return {@link GenParameter}
52:          */
53:         public static GenParameter create(final String name, final GenTypeReference typ) {
54:                 return new GenParameter(name, typ);
55:         }
56:         
57:         /**
58:          * Creates a new {@link GenParameter}.
59:          *
60:          * @param name
61:          * The name to identify the parameter.
62:          * @param typ
63:          * The referenced type of the parameter.
64:          * @return {@link GenParameter}
65:          */
66:         public static GenParameter create(final String name, final GenImportType typ) {
67:                 return GenParameter.create(name, GenTypeReferenceByReference.create(typ));
68:         }
69:         
70:         /**
71:          * Creates a new {@link GenParameter}.
72:          *
73:          * @param name
74:          * The name to identify the parameter.
75:          * @param typ
76:          * The referenced type of the parameter.
77:          * @return {@link GenParameter}
78:          */
79:         public static GenParameter create(final String name, final GenType typ) {
80:                 return GenParameter.create(name, GenTypeReferenceByReference.create(typ));
81:         }
82:         
83:         @Override
84:         public int hashCode() {
85:                 return this.getGenerics().hashCode() ^ this.getModifiers().hashCode() ^ this.getName().hashCode()
86:                                 ^ this.getTyp().hashCode();
87:         }
88:         
89:         @Override
90:         public boolean equals(final Object obj) {
91:•                if (obj instanceof GenParameter) {
92:•                        return ((GenParameter) obj).getName().equals(this.getName())
93:                                         && ((GenParameter) obj).getTyp().equals(this.getTyp());
94:                 }
95:                 return false;
96:         }
97:         
98:         @Override
99:         public String toString() {
100:                 final StringBuffer result = new StringBuffer();
101:                 if (!this.modifiers.isEmpty()) {
102:                         for (final GenParameterModifier modifier : this.modifiers) {
103:                                 result.append(modifier);
104:                                 result.append(' ');
105:                         }
106:                 }
107:                 result.append(this.typ.getFullyQualifiedName());
108:                 if (!this.generics.isEmpty()) {
109:                         result.append('<');
110:                         for (final GenType type : this.generics) {
111:                                 result.append(type.getName());
112:                                 result.append(',');
113:                         }
114:                         result.deleteCharAt(result.length() - 1);
115:                         result.append('>');
116:                 }
117:                 result.append(' ');
118:                 result.append(this.getName());
119:                 return result.toString();
120:         }
121:         
122:         @Override
123:         public void accept(final GenerationModelItemVisitor visitor) {
124:                 visitor.handle(this);
125:         }
126:         
127:         /**
128:          * Returns the referenced type of the parameter.
129:          *
130:          * @return {@link GenTypeReference}
131:          */
132:         public GenTypeReference getTyp() {
133:                 return this.typ;
134:         }
135:         
136:         /**
137:          * Returns the modifiers of the parameter.
138:          *
139:          * @return Collection<GenParameterModifier>
140:          */
141:         public Collection<GenParameterModifier> getModifiers() {
142:                 return this.modifiers;
143:         }
144:         
145:         /**
146:          * Returns the generics that are an addition to the type of the parameter.
147:          *
148:          * @return ArrayList<Generic>
149:          */
150:         public ArrayList<Generic> getGenerics() {
151:                 return this.generics;
152:         }
153:         
154: }