Skip to content

Commit e453f45

Browse files
committed
Implement equals/hashCode for StructSequence.Descriptor
1 parent 8bc1323 commit e453f45

File tree

1 file changed

+40
-0
lines changed
  • graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/tuple

1 file changed

+40
-0
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/tuple/StructSequence.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import static com.oracle.graal.python.runtime.exception.PythonErrorType.TypeError;
4848

4949
import java.util.Arrays;
50+
import java.util.Objects;
5051

5152
import com.oracle.graal.python.PythonLanguage;
5253
import com.oracle.graal.python.builtins.Builtin;
@@ -162,6 +163,25 @@ String[] getFieldsForRepr() {
162163
assert k == inSequence;
163164
return fieldNamesForRepr;
164165
}
166+
167+
@Override
168+
public boolean equals(Object o) {
169+
if (this == o)
170+
return true;
171+
if (!(o instanceof Descriptor))
172+
return false;
173+
Descriptor that = (Descriptor) o;
174+
return inSequence == that.inSequence && allowInstances == that.allowInstances && Objects.equals(docString, that.docString) && Arrays.equals(fieldNames, that.fieldNames) &&
175+
Arrays.equals(fieldDocStrings, that.fieldDocStrings);
176+
}
177+
178+
@Override
179+
public int hashCode() {
180+
int result = Objects.hash(docString, inSequence, allowInstances);
181+
result = 31 * result + Arrays.hashCode(fieldNames);
182+
result = 31 * result + Arrays.hashCode(fieldDocStrings);
183+
return result;
184+
}
165185
}
166186

167187
/**
@@ -181,6 +201,26 @@ public BuiltinTypeDescriptor(PythonBuiltinClassType type, String docString, int
181201
public BuiltinTypeDescriptor(PythonBuiltinClassType type, String docString, int inSequence, String[] fieldNames, String[] fieldDocStrings) {
182202
this(type, docString, inSequence, fieldNames, fieldDocStrings, true);
183203
}
204+
205+
@Override
206+
public boolean equals(Object o) {
207+
if (this == o) {
208+
return true;
209+
}
210+
if (!(o instanceof BuiltinTypeDescriptor)) {
211+
return false;
212+
}
213+
if (!super.equals(o)) {
214+
return false;
215+
}
216+
BuiltinTypeDescriptor that = (BuiltinTypeDescriptor) o;
217+
return type == that.type;
218+
}
219+
220+
@Override
221+
public int hashCode() {
222+
return Objects.hash(super.hashCode(), type);
223+
}
184224
}
185225

186226
/**

0 commit comments

Comments
 (0)