Skip to content

Method: equals(Object)

1: package de.fhdw.wtf.common.ast;
2:
3: import de.fhdw.wtf.common.ast.type.ClassType;
4: import de.fhdw.wtf.common.ast.type.ProductType;
5:
6: /**
7: * Represents a signature for a {@link ConstructorOrOperation} and consolidates its attributes name, parameters,
8: * containingType.
9: */
10: public class ConstructorOrOperationSignature {
11:         private final String name;
12:         /**
13:          * The parameters of this {@link ConstructorOrOperation}.
14:          */
15:         private final ProductType parameters;
16:         /**
17:          * The containingType is the name of the Class, that contains this constructor or operation.
18:          */
19:         private final ClassType containingType;
20:         
21:         /**
22:          * @param name
23:          * of the assigned {@link ConstructorOrOperation}
24:          * @param parameters
25:          * of the assigned {@link ConstructorOrOperation}
26:          * @param containingType
27:          * of the assigned {@link ConstructorOrOperation}
28:          */
29:         private ConstructorOrOperationSignature(final String name,
30:                         final ProductType parameters,
31:                         final ClassType containingType) {
32:                 this.name = name;
33:                 this.parameters = parameters;
34:                 this.containingType = containingType;
35:         }
36:         
37:         /**
38:          * @param name
39:          * of the assigned {@link ConstructorOrOperation}
40:          * @param parameters
41:          * of the assigned {@link ConstructorOrOperation}
42:          * @param containingType
43:          * of the assigned {@link ConstructorOrOperation}
44:          * @return Returns a new instance of a signature with the given arguments
45:          */
46:         public static ConstructorOrOperationSignature create(final String name,
47:                         final ProductType parameters,
48:                         final ClassType containingType) {
49:                 return new ConstructorOrOperationSignature(name, parameters, containingType);
50:         }
51:         
52:         @Override
53:         public int hashCode() {
54:                 return this.getName().hashCode();
55:         }
56:         
57:         /**
58:          * @param object
59:          * is the object to compare with "this"
60:          * @return if and only if all properties given in the signature are equals this function returns true
61:          */
62:         @Override
63:         public boolean equals(final Object object) {
64:•                if (!(object instanceof ConstructorOrOperationSignature)) {
65:                         return false;
66:                 }
67:                 final ConstructorOrOperationSignature signature = (ConstructorOrOperationSignature) object;
68:•                if (!(this.name.equals(signature.name))) {
69:                         return false;
70:                 }
71:•                if (!(this.containingType.equals(signature.containingType))) {
72:                         return false;
73:                 }
74:•                if (!(this.parameters.equals(signature.parameters))) {
75:                         return false;
76:                 }
77:                 return true;
78:         }
79:         
80:         /**
81:          * @return the name of the assigned {@link ConstructorOrOperation}
82:          */
83:         public String getName() {
84:                 return this.name;
85:         }
86:         
87:         /**
88:          * @return the parameter of assigned {@link ConstructorOrOperation}
89:          */
90:         public ProductType getParameters() {
91:                 return this.parameters;
92:         }
93:         
94:         /**
95:          * @return the containingType of the assigned {@link ConstructorOrOperation}
96:          */
97:         public ClassType getContainingType() {
98:                 return this.containingType;
99:         }
100: }